Skip to content

Commit

Permalink
Fix markets schema for dYdX (#2190)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsblom authored Jan 7, 2025
1 parent b810e77 commit 03d8086
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
9 changes: 6 additions & 3 deletions nautilus_trader/adapters/dydx/schemas/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,9 +845,7 @@ class DYDXTradingPerpetualMarketMessage(msgspec.Struct, forbid_unknown_fields=Tr
clobPairId: str | None = None
ticker: str | None = None
marketId: int | None = None
status: DYDXPerpetualMarketStatus | None = (
None # 'ACTIVE', 'PAUSED', 'CANCEL_ONLY', 'POST_ONLY', or 'INITIALIZING'
)
status: DYDXPerpetualMarketStatus | None = None
baseAsset: str | None = None
quoteAsset: str | None = None
initialMarginFraction: str | None = None
Expand All @@ -865,6 +863,11 @@ class DYDXTradingPerpetualMarketMessage(msgspec.Struct, forbid_unknown_fields=Tr
trades24H: int | None = None
nextFundingRate: str | None = None
baseOpenInterest: str | None = None
marketType: str | None = None
openInterestLowerCap: str | None = None
openInterestUpperCap: str | None = None
tickSize: str | None = None
stepSize: str | None = None


class DYDXMarketMessageContents(msgspec.Struct, forbid_unknown_fields=True):
Expand Down
19 changes: 19 additions & 0 deletions tests/integration_tests/adapters/dydx/test_websocket_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"tests/test_data/dydx/websocket/v4_accounts_rewards.json",
"tests/test_data/dydx/websocket/v4_accounts_fills.json",
"tests/test_data/dydx/websocket/v4_markets_subscribed.json",
"tests/test_data/dydx/websocket/v4_markets_cross.json",
"tests/test_data/dydx/websocket/v4_markets_channel_data.json",
"tests/test_data/dydx/websocket/v4_block_height_subscribed.json",
"tests/test_data/dydx/websocket/v4_block_height_channel_data.json",
Expand Down Expand Up @@ -198,6 +199,24 @@ def test_markets_channel_message() -> None:
assert msg.contents.oraclePrices is not None


def test_markets_channel_market_type() -> None:
"""
Test parsing the account subscribed message with a CROSS market type.
"""
# Prepare
decoder = msgspec.json.Decoder(DYDXWsMarketChannelData)

# Act
with Path("tests/test_data/dydx/websocket/v4_markets_cross.json").open() as file_reader:
msg = decoder.decode(file_reader.read())

# Assert
assert msg.channel == "v4_markets"
assert msg.type == "channel_data"
assert msg.contents.trading is not None
assert msg.contents.trading["FTM-USD"].marketType == "CROSS"


def test_markets_channel_trade_message() -> None:
"""
Test parsing the account subscribed message.
Expand Down
35 changes: 35 additions & 0 deletions tests/test_data/dydx/websocket/v4_markets_cross.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"type": "channel_data",
"connection_id": "3f42a31a-07a0-4c4b-b74e-bfa3dbf03012",
"message_id": 768900,
"channel": "v4_markets",
"version": "1.0.0",
"contents": {
"trading": {
"FTM-USD": {
"id": "86",
"clobPairId": "86",
"ticker": "FTM-USD",
"marketId": 86,
"status": "FINAL_SETTLEMENT",
"quantumConversionExponent": -9,
"atomicResolution": -5,
"subticksPerTick": 1000000,
"stepBaseQuantums": 1000000,
"marketType": "CROSS",
"initialMarginFraction": "0.2",
"maintenanceMarginFraction": "0.1",
"openInterestLowerCap": "5000000",
"openInterestUpperCap": "10000000",
"tickSize": "0.0001",
"stepSize": "10",
"priceChange24H": "-0.0036333222",
"volume24H": "292953.744",
"trades24H": 2656,
"nextFundingRate": "0",
"openInterest": "564710",
"baseOpenInterest": "263330"
}
}
}
}

0 comments on commit 03d8086

Please sign in to comment.