dYdX2 - Loren1166/NautilusTrader- GitHub Wiki
dYdX
The dYdX adapter.
dYdX 适配器。
Config 配置
Define the dYdX configuration classes.
定义 dYdX 配置类。
class DYDXDataClientConfig dYdX 数据客户端配置
class DYDXDataClientConfig(LiveDataClientConfig)
Configuration for
DYDXDataClient
instances.
DYDXDataClient
实例的配置。
testnet
: If the client is connecting to the dYdX testnet API.
testnet
:如果客户端连接到 dYdX 测试网 API。
wallet_address: str | None
is_testnet: bool
def __dict__(self) -> dict[str, Any]:
"""
Return a dictionary representation of the configuration.
Returns
-------
dict[str, Any]
"""
...
@classmethod
def fully_qualified_name() -> str:
"""
Return the fully qualified name for the NautilusConfig class.
Returns
-------
str
"""
...
@property
def handle_revised_bars(self) -> bool:
...
@property
def id(self) -> str:
"""
Return the hashed identifier for the configuration.
Returns
-------
str
"""
...
@property
def instrument_provider(self) -> InstrumentProviderConfig:
...
def json(self) -> bytes:
"""
Return serialized JSON encoded bytes.
Returns
-------
bytes
"""
...
def json_primitives(self) -> dict[str, Any]:
"""
Return a dictionary representation of the configuration with JSON primitive types as values.
Returns
-------
dict[str, Any]
"""
...
@classmethod
def parse(raw: bytes | str) -> Any:
"""
Return a decoded object of the given cls.
Parameters
----------
cls : type
The type to decode to.
raw : bytes or str
The raw bytes or JSON string to decode.
Returns
-------
Any
"""
...
@property
def routing(self) -> RoutingConfig:
...
def validate(self) -> bool:
"""
Return whether the configuration can be represented as valid JSON.
Returns
-------
bool
"""
...
class DYDXExecClientConfig dYdX 执行客户端配置
class DYDXExecClientConfig(LiveExecClientConfig)
Configuration for
DYDXExecutionClient
instances.
DYDXExecutionClient
实例的配置。
wallet_address
: The dYdX wallet address. IfNone
then will sourceDYDX_WALLET_ADDRESS
orDYDX_TESTNET_WALLET_ADDRESS
environment variables.
wallet_address
:dYdX 钱包地址。如果为None
,则将获取DYDX_WALLET_ADDRESS
或DYDX_TESTNET_WALLET_ADDRESS
环境变量。
subaccount
: The subaccount number. The venue creates subaccount 0 by default.
subaccount
:子账户编号。默认情况下,交易平台会创建子账户 0。
mnemonic
: The mnemonic string which is used to generate the private key. The private key is used to sign transactions like submitting orders. IfNone
then will sourceDYDX_MNEMONIC
orDYDX_TESTNET_MNEMONIC
environment variables.
mnemonic
:用于生成私钥的助记词字符串。私钥用于签署交易,例如提交订单。如果为None
,则将获取DYDX_MNEMONIC
或DYDX_TESTNET_MNEMONIC
环境变量。
base_url_http
: The HTTP client custom endpoint override.
base_url_http
:HTTP 客户端自定义端点覆盖。
base_url_ws
: The WebSocket client custom endpoint override.
base_url_ws
:WebSocket 客户端自定义端点覆盖。
is_testnet
: If the client is connecting to the dYdX testnet API.
is_testnet
:如果客户端连接到 dYdX 测试网 API。
max_retries
: The maximum number of times a submit, cancel or modify order request will be retried.
max_retries
:提交、取消或修改订单请求将重试的最大次数。
retry_delay
: The delay (seconds) between retries. Short delays with frequent retries may result in account bans.
retry_delay
:重试之间的延迟(以秒为单位)。频繁重试的短延迟可能会导致账户被封禁。
wallet_address: str | None
subaccount: int
mnemonic: str | None
base_url_http: str | None
base_url_ws: str | None
is_testnet: bool
max_retries: Annotated[int, msgspec.Meta(gt=0)] | None
retry_delay: Annotated[float, msgspec.Meta(gt=0.0)] | None
def __dict__(self) -> dict[str, Any]:
"""
Return a dictionary representation of the configuration.
Returns
-------
dict[str, Any]
"""
...
@classmethod
def fully_qualified_name() -> str:
"""
Return the fully qualified name for the NautilusConfig class.
Returns
-------
str
"""
...
@property
def id(self) -> str:
"""
Return the hashed identifier for the configuration.
Returns
-------
str
"""
...
@property
def instrument_provider(self) -> InstrumentProviderConfig:
...
def json(self) -> bytes:
"""
Return serialized JSON encoded bytes.
Returns
-------
bytes
"""
...
def json_primitives(self) -> dict[str, Any]:
"""
Return a dictionary representation of the configuration with JSON primitive types as values.
Returns
-------
dict[str, Any]
"""
...
@classmethod
def parse(raw: bytes | str) -> Any:
"""
Return a decoded object of the given cls.
Parameters
----------
cls : type
The type to decode to.
raw : bytes or str
The raw bytes or JSON string to decode.
Returns
-------
Any
"""
...
@property
def routing(self) -> RoutingConfig:
...
def validate(self) -> bool:
"""
Return whether the configuration can be represented as valid JSON.
Returns
-------
bool
"""
...
Factories 工厂
Enums 枚举
Define common enumerations for the dYdX adapter.
定义 dYdX 适配器的通用枚举。
class DYDXLiquidity(Enum):
"""
Represents a dYdX liquidity type.
# 表示 dYdX 流动性类型。
"""
TAKER = "TAKER"
MAKER = "MAKER"
class DYDXFillType(Enum):
"""
Represents a dYdX fill type.
# 表示 dYdX 成交类型。
"""
LIMIT = "LIMIT"
LIQUIDATED = "LIQUIDATED"
LIQUIDATION = "LIQUIDATION"
DELEVERAGED = "DELEVERAGED"
OFFSETTING = "OFFSETTING"
class DYDXMarketType(Enum):
"""
Represents a dYdX market type.
# 表示 dYdX 市场类型。
"""
PERPETUAL = "PERPETUAL"
SPOT = "SPOT"
class DYDXPerpetualPositionStatus(Enum):
"""
Represents a dYdX position status.
# 表示 dYdX 头寸状态。
"""
OPEN = "OPEN"
CLOSED = "CLOSED"
LIQUIDATED = "LIQUIDATED"
class DYDXOrderStatus(Enum):
"""
Represents a dYdX order status.
# 表示 dYdX 订单状态。
"""
OPEN = "OPEN"
FILLED = "FILLED"
CANCELED = "CANCELED"
BEST_EFFORT_CANCELED = "BEST_EFFORT_CANCELED"
UNTRIGGERED = "UNTRIGGERED"
BEST_EFFORT_OPENED = "BEST_EFFORT_OPENED"
class DYDXTimeInForce(Enum):
"""
Represents a dYdX time in force setting.
# 表示 dYdX 有效期设置。
"""
GTT = "GTT"
FOK = "FOK"
IOC = "IOC"
class DYDXPositionSide(Enum):
"""
Represents a dYdX position side.
# 表示 dYdX 头寸方向。
"""
LONG = "LONG"
SHORT = "SHORT"
class DYDXEndpointType(Enum):
"""
Represents a dYdX endpoint perpetual market status.
# 表示 dYdX 端点永续市场状态。
"""
NONE = "NONE"
ASSET = "ASSET"
MARKET = "MARKET"
ACCOUNT = "ACCOUNT"
TRADE = "TRADE"
POSITION = "POSITION"
class DYDXPerpetualMarketStatus(Enum):
"""
Represents a dYdX endpoint perpetual market status.
# 表示 dYdX 端点永续市场状态。
"""
ACTIVE = "ACTIVE"
PAUSED = "PAUSED"
CANCEL_ONLY = "CANCEL_ONLY"
POST_ONLY = "POST_ONLY"
INITIALIZING = "INITIALIZING"
FINAL_SETTLEMENT = "FINAL_SETTLEMENT"
class DYDXPerpetualMarketType(Enum):
"""
Represents a dYdX endpoint perpetual market type.
# 表示 dYdX 端点永续市场类型。
"""
CROSS = "CROSS"
ISOLATED = "ISOLATED"
class DYDXOrderSide(Enum):
"""
Represents a dYdX order side type.
# 表示 dYdX 订单方向类型。
"""
BUY = "BUY"
SELL = "SELL"
class DYDXOrderType(Enum):
"""
Represents a dYdX order type.
# 表示 dYdX 订单类型。
"""
LIMIT = "LIMIT"
MARKET = "MARKET"
STOP_LIMIT = "STOP_LIMIT"
STOP_MARKET = "STOP_MARKET"
TRAILING_STOP = "TRAILING_STOP"
TAKE_PROFIT = "TAKE_PROFIT"
TAKE_PROFIT_MARKET = "TAKE_PROFIT_MARKET"
LIQUIDATED = "LIQUIDATED"
DELEVERAGED = "DELEVERAGED"
class DYDXCandlesResolution(Enum):
"""
Represent the kline resolution for dYdX.
# 表示 dYdX 的 K 线分辨率。
"""
ONE_MINUTE = "1MIN"
FIVE_MINUTES = "5MINS"
FIFTEEN_MINUTES = "15MINS"
THIRTY_MINUTES = "30MINS"
ONE_HOUR = "1HOUR"
FOUR_HOURS = "4HOURS"
ONE_DAY = "1DAY"
class DYDXTransferType(Enum):
"""
Represent the different transfer types.
# 表示不同的转账类型。
"""
TRANSFER_IN = "TRANSFER_IN"
TRANSFER_OUT = "TRANSFER_OUT"
DEPOSIT = "DEPOSIT"
WITHDRAWAL = "WITHDRAWAL"
class DYDXEnumParser:
"""
Convert dYdX enums to Nautilus enums.
# 将 dYdX 枚举转换为 Nautilus 枚举。
"""
def parse_dydx_order_type(self, order_type: DYDXOrderType) -> OrderType:
"""
Convert a DYDX order type to a Nautilus order type.
# 将 DYDX 订单类型转换为 Nautilus 订单类型。
"""
...
def parse_nautilus_order_type(self, order_type: OrderType) -> DYDXOrderType:
"""
Convert a Nautilus order type to a DYDX order type.
# 将 Nautilus 订单类型转换为 DYDX 订单类型。
"""
...
def parse_dydx_order_side(self, order_side: DYDXOrderSide | None) -> OrderSide:
"""
Convert a DYDX order side to a Nautilus order side.
# 将 DYDX 订单方向转换为 Nautilus 订单方向。
"""
...
def parse_nautilus_order_side(self, order_side: OrderSide) -> DYDXOrderSide | None:
"""
Convert a Nautilus order side to a DYDX order side.
# 将 Nautilus 订单方向转换为 DYDX 订单方向。
"""
...
def parse_dydx_order_status(self, order_status: DYDXOrderStatus) -> OrderStatus:
"""
Convert a DYDX order status to a Nautilus order status.
# 将 DYDX 订单状态转换为 Nautilus 订单状态。
"""
...
def parse_dydx_time_in_force(self, time_in_force: DYDXTimeInForce) -> TimeInForce:
"""
Convert a DYDX time in force to a Nautilus time in force.
# 将 DYDX 有效期转换为 Nautilus 有效期。
"""
...
def parse_dydx_liquidity_side(self, liquidity_side: DYDXLiquidity) -> LiquiditySide:
"""
Convert a DYDX liquidity side to a Nautilus liquidity side.
# 将 DYDX 流动性方向转换为 Nautilus 流动性方向。
"""
...
def parse_dydx_position_side(self, position_side: DYDXPositionSide) -> PositionSide:
"""
Convert a DYDX position side to a Nautilus position side.
# 将 DYDX 头寸方向转换为 Nautilus 头寸方向。
"""
...
def parse_dydx_kline(self, bar_type: BarType) -> DYDXCandlesResolution:
"""
Convert a Nautilus bar type to a dYdX candles resolution.
# 将 Nautilus K线类型转换为 dYdX K 线分辨率。
"""
...