-
Notifications
You must be signed in to change notification settings - Fork 10
PerpOB #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arturbeg
wants to merge
63
commits into
main
Choose a base branch
from
feat/perpOB
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+7,408
−4,160
Open
PerpOB #51
Changes from all commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
e2d33e4
feat(perpOB): migrate Python SDK to v2.3.0 unified spot+perp API
arturbeg e755105
feat(perpOB): point SDK at devnet1 + resolve all perpOB TODOs
arturbeg 81db30d
test(perpOB): port test_market_data + expand test_orderbook + recover…
arturbeg f27e9e4
chore(perpOB): lint pass — black/isort/flake8/mypy/pylint clean
arturbeg 233daff
chore(perpOB): pre-commit run --all-files clean
arturbeg 5e31cd6
fix(perpOB): review fixes — spot summary WS routing + trigger qty foo…
arturbeg eeacff9
test(perpOB): TS↔Py EIP-712 signature parity harness
arturbeg fb312b9
fix(perpOB): align examples + helpers with v2.3.0 PerpExecution + Mar…
arturbeg b5c392d
chore(perpOB): drop redundant casts, fix Returning-Any, run black
arturbeg bcc8bd7
chore(lint): future-import annotations on PEP-604 union sites
arturbeg 9c73bc6
fix(perpOB): CodeRabbit follow-ups — qty guard, conftest wiring, docs…
arturbeg 1100638
chore(lint): pyupgrade rewrites + drop now-unused typing imports
arturbeg e5b182d
feat: devnet progressing
arturbeg c284afe
fix: tests
arturbeg be8e0d2
fix: drop legacy test
arturbeg 7dcc760
chore(specs): bump api-specs submodule to 2.3.0 + regenerate open_api
arturbeg c0a2788
test(perps): relax test_candles to assert >0 candles, not == 200
arturbeg 9e2561c
fix: depth market maker
arturbeg 5fcfd0b
test(perps): bump test_perp_gtc_rests_on_book retry budget to 6s (PRO…
arturbeg a519e36
test(perps): skip maker/taker tests when external liquidity is on the…
arturbeg 02b9537
ci(lint): unbreak feat/perpOB lint + version-check
arturbeg 126a5b0
chore(generated): regenerate openapi + asyncapi after version bump
arturbeg 769b0d2
Add fixes for depth scripts
tomdevman c58ce2e
fix(sdk): drop client.cancel_order XOR check on order_id / client_ord…
arturbeg e3b9563
test(spot): add `expiresAfter` to 5 validation tests so they reach th…
arturbeg 6a5729e
test(perps): harden perp test suite for devnet1 conditions
arturbeg bfb19de
test(perp): rework reduce_only test to source signal from WS bust feed
arturbeg 8bb67a7
test(perp): tolerate either WS-bust or REST-4xx for reduce_only invar…
arturbeg 8200ef1
chore(specs): bump api-specs to 2.3.3 + regenerate open_api/async_api
arturbeg ea2c6ea
fix(sdk): gate reduceOnly wire field by market type + order type
arturbeg 12518fd
test(helpers): retry current_price through transient price-feed gaps
arturbeg 285ebf2
Merge origin/main into feat/perpOB — absorb ws-exec client (PRO-140)
arturbeg 167c57d
fix(ws-exec): update mvp.py trigger enums to unified 2.3.x names
arturbeg 53324b4
test(ws-exec): wire mvp.py as collectible pytest module (PRO-140)
arturbeg f451fe5
fix(ci): unbreak Lint + Version Check on feat/perpOB
arturbeg 109640c
chore(generated): regenerate open_api at packageVersion 2.3.3.0
arturbeg 87d4bab
refactor(sdk): remove dead code left by the perpOB migration
arturbeg 3d1122d
fix(sdk): restore TIF/market-aware order lifetimes + tighten reduceOn…
arturbeg 9ebb15f
docs(sdk): correct deadline-vs-expiresAfter framing in order builders
arturbeg f5c0b44
test: fix qty false-green, lazy market fixtures, add sell parity vector
arturbeg 583ab6d
fix(trigger): serialize sell-sentinel limitPx as fixed-point, not 1E-9
arturbeg 951058a
fix(trigger): use one market tick as the sell-sentinel limit price
arturbeg 2a8092d
test(trigger): drop synthetic tiny-tick symbol; guard sci-notation vi…
arturbeg ab621eb
docs(trigger): point sentinel comment at PRO-155 (revisit limit-price…
arturbeg 7928f48
test(ws-exec): re-mark perp flows — IOC passes, skip SLTP facade, GTC…
arturbeg 9090e5f
test(ws-exec): un-xfail perp LIMIT GTC — cancel fix deployed, now passes
arturbeg c02ffc6
docs: warn to kill leftover example processes before running the live…
arturbeg 5a0f4ad
Fix devnet1 OrdersGateway: stale default broke EIP-712 signing (PRO-164)
arturbeg 91908b0
docs(test): explain extreme-price → "Insufficient balance" reason in …
arturbeg 9e1f519
Review: keep all 3 OrdersGateway envs; document devnet1/cronos chain-…
arturbeg 0eb745c
Review: give cronos its own .env.example section; drop "legacy" wording
arturbeg 628e5e7
Review: apply Option A — gateway is per-env config, clean override/fa…
arturbeg 3fdb287
Apply black formatting to config.py (fix pre-commit CI)
arturbeg 2b5df1e
Merge pull request #56 from Reya-Labs/artur/fix-devnet1-orders-gateway
arturbeg 08a9acb
test(ws-exec): un-xfail cancel-by-clientOrderId — PRO-143 fixed + ver…
arturbeg e5f7446
test(parity): regenerate TS↔Py signature vectors for new OrdersGatewa…
arturbeg 1bc2250
test(perps): skip reduce-only-without-position test on external liqui…
arturbeg 6cdba3f
feat(rest): sign 14-field OrderDetails (postOnly); decouple deadline …
arturbeg b39f674
feat(sdk): carry postOnly/GTT on the wire (spec sync); keep entry gat…
arturbeg 8d3fbd7
chore: bump SDK version to 3.0.1.0 (consumes api-specs 3.0.1)
arturbeg b5d5df3
chore: regenerate ws-exec async models for postOnly/GTT (specs 3.0.1)
arturbeg febce55
test(sdk): add offline entry-rule negative tests (PRO-198 P1)
arturbeg 19b6858
test(spot): align API-validation tests with the decoupled expiresAfte…
arturbeg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,48 @@ | ||
| ### Cronos (testnet) | ||
| ### Devnet1 (perpOB testnet) | ||
| CHAIN_ID=89346162 | ||
| REYA_WS_URL="wss://websocket-testnet.reya.xyz/" | ||
| REYA_WS_EXEC_URL="wss://ws-exec-testnet.reya.xyz" | ||
| REYA_API_URL="https://api-cronos.reya.xyz/v2" | ||
| REYA_WS_URL="wss://websocket-devnet.reya-cronos.network/" | ||
| REYA_WS_EXEC_URL="wss://ws-exec-devnet.reya-cronos.network" | ||
| REYA_API_URL="https://api-devnet.reya-cronos.network/v2" | ||
| # OrdersGateway proxy = the EIP-712 verifyingContract. | ||
| REYA_ORDERS_GATEWAY="0x7Ec89E555c771D2B5939aBE5C4E4291852633D4D" | ||
|
|
||
| ### Cronos testnet (same chain id as devnet1, different deployment) | ||
| #CHAIN_ID=89346162 | ||
| #REYA_WS_URL="wss://websocket-testnet.reya.xyz/" | ||
| #REYA_WS_EXEC_URL="wss://ws-exec-testnet.reya.xyz" | ||
| #REYA_API_URL="https://api-cronos.reya.xyz/v2" | ||
| # Cronos shares devnet1's chain id, so set the gateway explicitly to target it: | ||
| #REYA_ORDERS_GATEWAY="0x5a0ac2f89e0bdeafc5c549e354842210a3e87ca5" | ||
|
|
||
| ### Reya Network (mainnet) | ||
| #CHAIN_ID=1729 | ||
| #REYA_WS_URL="wss://ws.reya.xyz/" | ||
| #REYA_WS_EXEC_URL="wss://ws-exec.reya.xyz" | ||
| #REYA_API_URL="https://api.reya.xyz/v2" | ||
| #REYA_ORDERS_GATEWAY="0xfc8c96be87da63cecddbf54abfa7b13ee8044739" | ||
|
|
||
| ### Staging (uses mainnet chain ID 1729) | ||
| #CHAIN_ID=1729 | ||
| #REYA_WS_URL="wss://websocket-staging.reya.xyz" | ||
| #REYA_WS_EXEC_URL="wss://ws-exec-staging.reya.xyz" | ||
| #REYA_API_URL="https://api-staging.reya.xyz/v2" | ||
|
|
||
| # PERP_ACCOUNT_ID_1 | ||
| # PERP_ACCOUNT_ID_1 (default single-account perp tester) | ||
| PERP_ACCOUNT_ID_1= | ||
| PERP_PRIVATE_KEY_1= | ||
| PERP_WALLET_ADDRESS_1= | ||
|
|
||
| # SPOT_ACCOUNT_ID_1 | ||
| # PERP_ACCOUNT_ID_2 (used as the perp taker in maker/taker tests; perp orderbook needs both sides) | ||
| PERP_ACCOUNT_ID_2= | ||
| PERP_PRIVATE_KEY_2= | ||
| PERP_WALLET_ADDRESS_2= | ||
|
|
||
| # SPOT_ACCOUNT_ID_1 (spot maker) | ||
| SPOT_ACCOUNT_ID_1= | ||
| SPOT_PRIVATE_KEY_1= | ||
| SPOT_WALLET_ADDRESS_1= | ||
|
|
||
| # SPOT_ACCOUNT_ID_2 | ||
| # SPOT_ACCOUNT_ID_2 (spot taker) | ||
| SPOT_ACCOUNT_ID_2= | ||
| SPOT_PRIVATE_KEY_2= | ||
| SPOT_WALLET_ADDRESS_2= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| # AGENTS.md | ||
|
|
||
| This file provides guidance to Codex (Codex.ai/code) when working with code in this repository. | ||
|
|
||
| ## Important Notes | ||
| * Always read entire files. Otherwise, you don’t know what you don’t know, and will end up making mistakes, duplicating code that already exists, or misunderstanding the architecture. | ||
| * Commit early and often. When working on large tasks, your task could be broken down into multiple logical milestones. After a certain milestone is completed and confirmed to be ok by the user, you should commit it. If you do not, if something goes wrong in further steps, we would need to end up throwing away all the code, which is expensive and time consuming. | ||
| * Your internal knowledgebase of libraries might not be up to date. When working with any external library, unless you are 100% sure that the library has a super stable interface, you will look up the latest syntax and usage via either Perplexity (first preference) or web search (less preferred, only use if Perplexity is not available) | ||
| * Do not say things like: “x library isn’t working so I will skip it”. Generally, it isn’t working because you are using the incorrect syntax or patterns. This applies doubly when the user has explicitly asked you to use a specific library, if the user wanted to use another library they wouldn’t have asked you to use a specific one in the first place. | ||
| * Always run linting after making major changes. Otherwise, you won’t know if you’ve corrupted a file or made syntax errors, or are using the wrong methods, or using methods in the wrong way. | ||
| * Please organise code into separate files wherever appropriate, and follow general coding best practices about variable naming, modularity, function complexity, file sizes, commenting, etc. | ||
| * Code is read more often than it is written, make sure your code is always optimised for readability | ||
| * Unless explicitly asked otherwise, the user never wants you to do a “dummy” implementation of any given task. Never do an implementation where you tell the user: “This is how it *would* look like”. Just implement the thing. | ||
| * Whenever you are starting a new task, it is of utmost importance that you have clarity about the task. You should ask the user follow up questions if you do not, rather than making incorrect assumptions. | ||
| * Do not carry out large refactors unless explicitly instructed to do so. | ||
| * When starting on a new task, you should first understand the current architecture, identify the files you will need to modify, and come up with a Plan. In the Plan, you will think through architectural aspects related to the changes you will be making, consider edge cases, and identify the best approach for the given task. Get your Plan approved by the user before writing a single line of code. | ||
| * If you are running into repeated issues with a given task, figure out the root cause instead of throwing random things at the wall and seeing what sticks, or throwing in the towel by saying “I’ll just use another library / do a dummy implementation”. | ||
| * You are an incredibly talented and experienced polyglot with decades of experience in diverse areas such as software architecture, system design, development, UI & UX, copywriting, and more. | ||
| * When doing UI & UX work, make sure your designs are both aesthetically pleasing, easy to use, and follow UI / UX best practices. You pay attention to interaction patterns, micro-interactions, and are proactive about creating smooth, engaging user interfaces that delight users. | ||
| * When you receive a task that is very large in scope or too vague, you will first try to break it down into smaller subtasks. If that feels difficult or still leaves you with too many open questions, push back to the user and ask them to consider breaking down the task for you, or guide them through that process. This is important because the larger the task, the more likely it is that things go wrong, wasting time and energy for everyone involved. | ||
|
|
||
|
|
||
| ## Project Overview | ||
|
|
||
| This is the Reya Python SDK, providing Python interfaces for interacting with the Reya ecosystem. The SDK consists of three main components: | ||
|
|
||
| - **REST API Client** (`sdk/reya_rest_api/`) - HTTP client for Reya's Trading API | ||
| - **RPC Client** (`sdk/reya_rpc/`) - Web3-based client for on-chain actions | ||
| - **WebSocket Client** (`sdk/reya_websocket/`) - Real-time data streaming client | ||
|
|
||
| ## Development Commands | ||
|
|
||
| ### Setup and Installation | ||
| ```bash | ||
| # Install dependencies | ||
| poetry install | ||
|
|
||
| # Activate virtual environment | ||
| poetry shell | ||
| # Or use: source $(poetry env info --path)/bin/activate | ||
| ``` | ||
|
|
||
| ### Code Quality and Testing | ||
| ```bash | ||
| # Run all linting and formatting (via pre-commit) | ||
| make lint | ||
| # Or: make pre-commit | ||
|
|
||
| # Run specific linter only | ||
| make pre-commit hook=black | ||
| make pre-commit hook=isort | ||
| make pre-commit hook=flake8 | ||
| make pre-commit hook=mypy | ||
|
|
||
| # Install additional type stubs for mypy | ||
| make install-types | ||
|
|
||
| # Run security checks | ||
| make check-safety | ||
|
|
||
| # Clean build artifacts | ||
| make cleanup | ||
| ``` | ||
|
|
||
| ### Dependency Management | ||
| ```bash | ||
| # Update poetry.lock | ||
| make lockfile-update | ||
|
|
||
| # Fully regenerate poetry.lock | ||
| make lockfile-update-full | ||
|
|
||
| # Update dev dependencies to latest | ||
| make update-dev-deps | ||
| ``` | ||
|
|
||
| ### Running Examples | ||
| ```bash | ||
| # Activate environment first | ||
| poetry shell | ||
|
|
||
| # Run examples using module notation | ||
| python -m examples.rest_api.wallet_example | ||
| python -m examples.websocket.market_monitoring | ||
| python -m examples.rpc.trade_execution | ||
| ``` | ||
|
|
||
| ## Architecture Overview | ||
|
|
||
| ### REST API Client Architecture | ||
| The REST API client (`sdk/reya_rest_api/`) follows a resource-based pattern: | ||
|
|
||
| - **Client** (`client.py`) - Main entry point with signature authentication | ||
| - **Resources** (`resources/`) - Organized by API endpoints (wallet, markets, orders, assets, prices) | ||
| - **Auth** (`auth/signatures.py`) - EIP-712 signature generation for authenticated requests | ||
| - **Models** (`models/`) - Pydantic models for request/response data | ||
| - **Config** (`config.py`) - Configuration management with environment variable support | ||
|
|
||
| ### RPC Client Architecture | ||
| The RPC client (`sdk/reya_rpc/`) provides Web3-based blockchain interactions: | ||
|
|
||
| - **Actions** (`actions/`) - High-level transaction builders for common operations | ||
| - **ABIs** (`abis/`) - Smart contract ABIs for all supported contracts | ||
| - **Config** (`config.py`) - Network-specific contract addresses and configuration | ||
| - **Utils** (`utils/`) - Core transaction execution utilities | ||
|
|
||
| ### WebSocket Client Architecture | ||
| The WebSocket client (`sdk/reya_websocket/`) offers resource-oriented real-time data access: | ||
|
|
||
| - **Socket** (`socket.py`) - Main WebSocket connection manager with auto-reconnection | ||
| - **Resources** (`resources/`) - Market, wallet, and price subscription managers | ||
| - **Config** (`config.py`) - WebSocket connection configuration | ||
|
|
||
| ### Key Configuration Patterns | ||
|
|
||
| The codebase uses environment variables extensively for configuration: | ||
|
|
||
| - **Trading API**: Uses `TradingConfig.from_env()` to load API URLs, authentication, etc. | ||
| - **RPC**: Uses `get_config()` to load chain IDs, contract addresses, private keys | ||
| - **WebSocket**: Uses `WebSocketConfig.from_env()` for connection parameters | ||
|
|
||
| ### Smart Contract Integration | ||
|
|
||
| The RPC client supports two main networks: | ||
| - **Mainnet** (chain_id=1729): Production Reya network | ||
| - **Testnet** (chain_id=89346162): Testing environment | ||
|
|
||
| Contract addresses are network-specific and configured in `sdk/reya_rpc/config.py`. | ||
|
|
||
| ### Code Quality Configuration | ||
|
|
||
| - **Line length**: 120 characters (Black, isort, Pylint) | ||
| - **Python version**: 3.12+ required, 3.10 for type checking | ||
| - **Type checking**: Strict mypy configuration with comprehensive checks | ||
| - **Pre-commit hooks**: Automated formatting and linting on commit | ||
|
|
||
| ## Environment Setup Requirements | ||
|
|
||
| Create `.env` file with: | ||
| ``` | ||
| ACCOUNT_ID=your_account_id | ||
| PRIVATE_KEY=your_private_key | ||
| CHAIN_ID=1729 # or 89346162 for testnet | ||
| REYA_WS_URL=wss://ws.reya.xyz/ | ||
| ``` | ||
|
|
||
| ## Testing Approach | ||
|
|
||
| The project uses pytest with additional packages: | ||
| - `pytest-recording` and `vcrpy` for HTTP request/response recording | ||
| - `pytest-cov` for coverage reporting | ||
| - Test files should be placed alongside source code or in dedicated test directories | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,8 @@ | |
| --qty 5 | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import asyncio | ||
| import logging | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 Important — this setup block won't start the SDK.
TradingConfig.from_env()readsPERP_ACCOUNT_ID_1/PERP_PRIVATE_KEY_1/PERP_WALLET_ADDRESS_1, notACCOUNT_ID/PRIVATE_KEY— following this verbatim raises"PERP_WALLET_ADDRESS_1 ... is required". The example module paths above (examples.rest_api.wallet_example,examples.websocket.market_monitoring) are also missing theperps/segment →ModuleNotFoundError. Please align with.env.exampleand the actual example layout.