feat: Add options contract holdings parsing & mark pricing support for Derive exchange - #219
Open
halfdoctor wants to merge 3 commits into
Open
feat: Add options contract holdings parsing & mark pricing support for Derive exchange#219halfdoctor wants to merge 3 commits into
halfdoctor wants to merge 3 commits into
Conversation
…support for Derive exchange
Greptile SummaryThe PR adds Derive option-position balances, mark-price valuation, and generic parsing for ticker payloads containing nested instrument metadata.
Confidence Score: 5/5The PR appears safe to merge because the previously reported startup and test-integration failures have been addressed and no blocking failure remains. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| main.py | Applies the Derive options patch before application services and connector instances are initialized. |
| services/accounts_service.py | Adds Derive options quote configuration and connector-specific mark-price resolution while retaining existing market-data fallbacks. |
| services/ticker_sources.py | Extends generic ticker field recognition and flattens nested symbol objects in list payloads. |
| utils/patch_derive_connector.py | Adds the runtime Derive connector patch for position balances, option metadata, and mark-price lookup. |
| test/test_derive_options_integration.py | Tests patched Derive position parsing and account valuation with the required async markers and patch setup. |
Sequence Diagram
sequenceDiagram
participant Startup as Application startup
participant Patch as Derive patch
participant Derive as DeriveExchange
participant Accounts as AccountsService
Startup->>Patch: apply_derive_options_patch()
Patch->>Derive: install patched initialization and balance methods
Accounts->>Derive: _update_balances()
Derive-->>Accounts: collateral and option balances
Accounts->>Derive: get_token_price(option symbol)
Derive-->>Accounts: cached mark price
Accounts-->>Accounts: calculate option holding value
Reviews (3): Last reviewed commit: "fix(test): apply derive options patch be..." | Re-trigger Greptile
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR introduces support for parsing, valuation, and mark pricing of options contract holdings (specifically targeting options on the Derive exchange connector and generalizing generic ticker row handling).
Motivation
Options instruments (e.g.
ETH-20260925-3000-C) require custom handling compared to standard spot assets:ETH-20260925-3000-C-USDC."USD"(such as option contracts quoted in USD) were previously at risk of being treated as $1.00 USD stablecoins by default.Key Changes
1.
services/accounts_service.pyderive_optionsQuote Mapping: Mapped"derive_options": "USDC"in defaultQUOTE_ASSETS."USD" in token and "-" not in token): Prevents option symbols containing "USD" (e.g., options contracts) from being hardcoded to a $1.00 valuation.connector.get_token_price(token)): Allows connectors (like options exchanges) to return mark prices directly for non-standard assets, safely casting toDecimal.2.
services/ticker_sources.py"instrument_name"to_SYMBOL_KEYS, and"best_bid","best_bid_price","best_ask","best_ask_price"to bid/ask keys._heuristic_rows: Flattens nested"symbol"dictionaries (e.g.,{"symbol": {"instrument_name": "ETH-PERP"}, ...}) so generic ticker adapters can process options and perps feeds without error.3.
utils/patch_derive_connector.pyDeriveExchange._update_balances()to pullpositions(active options and perps) alongsidecollateralsfrom/api/v1/private/get_subaccount. Exposesget_token_price()andget_option_positions()for Greeks and mark price metadata.4.
test/test_derive_options_integration.pyAccountsServicetoken info integration (using scrubbed test credentials).Verification & Testing
AccountsServiceoption mark price resolution using custom connector hook._heuristic_rowsparsing with nested symbol dictionary structures.test/test_derive_options_integration.pypassing with mock responses.pytest.importorskip("hummingbot").