Skip to content

Commit 6f96865

Browse files
committed
Implement custom client IDs
1 parent 9410846 commit 6f96865

File tree

19 files changed

+99
-54
lines changed

19 files changed

+99
-54
lines changed

nautilus_trader/adapters/betfair/factories.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def create( # type: ignore
140140
loop : asyncio.AbstractEventLoop
141141
The event loop for the client.
142142
name : str
143-
The client name.
143+
The custom client ID.
144144
config : dict[str, Any]
145145
The configuration dictionary.
146146
msgbus : MessageBus
@@ -201,7 +201,7 @@ def create( # type: ignore
201201
loop : asyncio.AbstractEventLoop
202202
The event loop for the client.
203203
name : str
204-
The client name.
204+
The custom client ID.
205205
config : dict[str, Any]
206206
The configuration for the client.
207207
msgbus : MessageBus

nautilus_trader/adapters/binance/common/data.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class BinanceCommonDataClient(LiveMarketDataClient):
101101
The account type for the client.
102102
base_url_ws : str
103103
The base url for the WebSocket client.
104+
name : str, optional
105+
The custom client ID.
104106
config : BinanceDataClientConfig
105107
The configuration for the client.
106108
@@ -122,11 +124,12 @@ def __init__(
122124
instrument_provider: InstrumentProvider,
123125
account_type: BinanceAccountType,
124126
base_url_ws: str,
127+
name: str | None,
125128
config: BinanceDataClientConfig,
126129
) -> None:
127130
super().__init__(
128131
loop=loop,
129-
client_id=ClientId(BINANCE_VENUE.value),
132+
client_id=ClientId(name or BINANCE_VENUE.value),
130133
venue=BINANCE_VENUE,
131134
msgbus=msgbus,
132135
cache=cache,

nautilus_trader/adapters/binance/common/execution.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class BinanceCommonExecutionClient(LiveExecutionClient):
108108
The account type for the client.
109109
base_url_ws : str
110110
The base URL for the WebSocket client.
111+
name : str, optional
112+
The custom client ID.
111113
config : BinanceExecClientConfig
112114
The configuration for the client.
113115
@@ -131,11 +133,12 @@ def __init__(
131133
instrument_provider: InstrumentProvider,
132134
account_type: BinanceAccountType,
133135
base_url_ws: str,
136+
name: str | None,
134137
config: BinanceExecClientConfig,
135138
) -> None:
136139
super().__init__(
137140
loop=loop,
138-
client_id=ClientId(BINANCE_VENUE.value),
141+
client_id=ClientId(name or BINANCE_VENUE.value),
139142
venue=BINANCE_VENUE,
140143
oms_type=OmsType.HEDGING if account_type.is_futures else OmsType.NETTING,
141144
instrument_provider=instrument_provider,
@@ -162,7 +165,7 @@ def __init__(
162165
self._log.info(f"{config.max_retries=}", LogColor.BLUE)
163166
self._log.info(f"{config.retry_delay=}", LogColor.BLUE)
164167

165-
self._set_account_id(AccountId(f"{BINANCE_VENUE.value}-spot-master"))
168+
self._set_account_id(AccountId(f"{name or BINANCE_VENUE.value}-spot-master"))
166169

167170
# Enum parser
168171
self._enum_parser = enum_parser

nautilus_trader/adapters/binance/factories.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def get_cached_binance_http_client(
102102
("allOrders", Quota.rate_per_minute(int(1200 / 20))),
103103
]
104104

105-
client_key: str = "|".join((key, secret))
105+
client_key: str = "|".join((account_type.value, key, secret))
106106
if client_key not in BINANCE_HTTP_CLIENTS:
107107
client = BinanceHttpClient(
108108
clock=clock,
@@ -214,7 +214,7 @@ def create( # type: ignore
214214
loop : asyncio.AbstractEventLoop
215215
The event loop for the client.
216216
name : str
217-
The client name.
217+
The custom client ID.
218218
config : BinanceDataClientConfig
219219
The client configuration.
220220
msgbus : MessageBus
@@ -271,6 +271,7 @@ def create( # type: ignore
271271
instrument_provider=provider,
272272
account_type=config.account_type,
273273
base_url_ws=config.base_url_ws or default_base_url_ws,
274+
name=name,
274275
config=config,
275276
)
276277
else:
@@ -291,6 +292,7 @@ def create( # type: ignore
291292
instrument_provider=provider,
292293
account_type=config.account_type,
293294
base_url_ws=config.base_url_ws or default_base_url_ws,
295+
name=name,
294296
config=config,
295297
)
296298

@@ -317,7 +319,7 @@ def create( # type: ignore
317319
loop : asyncio.AbstractEventLoop
318320
The event loop for the client.
319321
name : str
320-
The client name.
322+
The custom client ID.
321323
config : BinanceExecClientConfig
322324
The configuration for the client.
323325
msgbus : MessageBus
@@ -374,6 +376,7 @@ def create( # type: ignore
374376
instrument_provider=provider,
375377
base_url_ws=config.base_url_ws or default_base_url_ws,
376378
account_type=config.account_type,
379+
name=name,
377380
config=config,
378381
)
379382
else:
@@ -394,5 +397,6 @@ def create( # type: ignore
394397
instrument_provider=provider,
395398
base_url_ws=config.base_url_ws or default_base_url_ws,
396399
account_type=config.account_type,
400+
name=name,
397401
config=config,
398402
)

nautilus_trader/adapters/binance/futures/data.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ class BinanceFuturesDataClient(BinanceCommonDataClient):
5959
The instrument provider.
6060
base_url_ws : str
6161
The base URL for the WebSocket client.
62-
account_type : BinanceAccountType
63-
The account type for the client.
6462
config : BinanceDataClientConfig
6563
The configuration for the client.
64+
account_type : BinanceAccountType, default 'USDT_FUTURE'
65+
The account type for the client.
66+
name : str, optional
67+
The custom client ID.
6668
6769
"""
6870

@@ -77,6 +79,7 @@ def __init__(
7779
base_url_ws: str,
7880
config: BinanceDataClientConfig,
7981
account_type: BinanceAccountType = BinanceAccountType.USDT_FUTURE,
82+
name: str | None = None,
8083
):
8184
PyCondition.true(
8285
account_type.is_futures,
@@ -101,6 +104,7 @@ def __init__(
101104
instrument_provider=instrument_provider,
102105
account_type=account_type,
103106
base_url_ws=base_url_ws,
107+
name=name,
104108
config=config,
105109
)
106110

nautilus_trader/adapters/binance/futures/execution.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ class BinanceFuturesExecutionClient(BinanceCommonExecutionClient):
7272
The instrument provider.
7373
base_url_ws : str
7474
The base URL for the WebSocket client.
75-
account_type : BinanceAccountType
76-
The account type for the client.
7775
config : BinanceExecClientConfig
7876
The configuration for the client.
77+
account_type : BinanceAccountType, default 'USDT_FUTURE'
78+
The account type for the client.
79+
name : str, optional
80+
The custom client ID.
7981
8082
"""
8183

@@ -90,6 +92,7 @@ def __init__(
9092
base_url_ws: str,
9193
config: BinanceExecClientConfig,
9294
account_type: BinanceAccountType = BinanceAccountType.USDT_FUTURE,
95+
name: str | None = None,
9396
):
9497
PyCondition.true(
9598
account_type.is_futures,
@@ -118,6 +121,7 @@ def __init__(
118121
instrument_provider=instrument_provider,
119122
account_type=account_type,
120123
base_url_ws=base_url_ws,
124+
name=name,
121125
config=config,
122126
)
123127

nautilus_trader/adapters/binance/futures/providers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ def _parse_instrument(
334334
underlying=base_currency,
335335
quote_currency=quote_currency,
336336
settlement_currency=settlement_currency,
337+
is_inverse=False, # No inverse instruments trade on Binance
337338
activation_ns=activation.value,
338339
expiration_ns=expiration.value,
339340
price_precision=price_precision,

nautilus_trader/adapters/binance/spot/data.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ class BinanceSpotDataClient(BinanceCommonDataClient):
5656
The instrument provider.
5757
base_url_ws : str
5858
The base URL for the WebSocket client.
59-
account_type : BinanceAccountType
60-
The account type for the client.
6159
config : BinanceDataClientConfig
6260
The configuration for the client.
61+
account_type : BinanceAccountType, default 'SPOT'
62+
The account type for the client.
63+
name : str, optional
64+
The custom client ID.
6365
6466
"""
6567

@@ -74,6 +76,7 @@ def __init__(
7476
base_url_ws: str,
7577
config: BinanceDataClientConfig,
7678
account_type: BinanceAccountType = BinanceAccountType.SPOT,
79+
name: str | None = None,
7780
):
7881
PyCondition.true(
7982
account_type.is_spot_or_margin,
@@ -97,6 +100,7 @@ def __init__(
97100
instrument_provider=instrument_provider,
98101
account_type=account_type,
99102
base_url_ws=base_url_ws,
103+
name=name,
100104
config=config,
101105
)
102106

nautilus_trader/adapters/binance/spot/execution.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ class BinanceSpotExecutionClient(BinanceCommonExecutionClient):
6565
The instrument provider.
6666
base_url_ws : str
6767
The base URL for the WebSocket client.
68-
account_type : BinanceAccountType
69-
The account type for the client.
7068
config : BinanceExecClientConfig
7169
The configuration for the client.
70+
account_type : BinanceAccountType, default 'SPOT'
71+
The account type for the client.
72+
name : str, optional
73+
The custom client ID.
7274
7375
"""
7476

@@ -83,6 +85,7 @@ def __init__(
8385
base_url_ws: str,
8486
config: BinanceExecClientConfig,
8587
account_type: BinanceAccountType = BinanceAccountType.SPOT,
88+
name: str | None = None,
8689
):
8790
PyCondition.true(
8891
account_type.is_spot_or_margin,
@@ -111,6 +114,7 @@ def __init__(
111114
instrument_provider=instrument_provider,
112115
account_type=account_type,
113116
base_url_ws=base_url_ws,
117+
name=name,
114118
config=config,
115119
)
116120

nautilus_trader/adapters/bybit/data.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class BybitDataClient(LiveMarketDataClient):
9494
The product base urls for the WebSocket clients.
9595
config : BybitDataClientConfig
9696
The configuration for the client.
97+
name : str, optional
98+
The custom client ID.
9799
98100
"""
99101

@@ -108,11 +110,12 @@ def __init__(
108110
product_types: list[BybitProductType],
109111
ws_base_urls: dict[BybitProductType, str],
110112
config: BybitDataClientConfig,
113+
name: str | None,
111114
) -> None:
112115
self._enum_parser = BybitEnumParser()
113116
super().__init__(
114117
loop=loop,
115-
client_id=ClientId(BYBIT_VENUE.value),
118+
client_id=ClientId(name or BYBIT_VENUE.value),
116119
venue=BYBIT_VENUE,
117120
msgbus=msgbus,
118121
cache=cache,

nautilus_trader/adapters/bybit/execution.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class BybitExecutionClient(LiveExecutionClient):
101101
The base URL for the WebSocket client.
102102
config : BybitExecClientConfig
103103
The configuration for the client.
104+
name : str, optional
105+
The custom client ID.
104106
105107
"""
106108

@@ -115,6 +117,7 @@ def __init__(
115117
product_types: list[BybitProductType],
116118
base_url_ws: str,
117119
config: BybitExecClientConfig,
120+
name: str | None,
118121
) -> None:
119122
if BybitProductType.SPOT in product_types:
120123
if len(set(product_types)) > 1:
@@ -125,7 +128,7 @@ def __init__(
125128

126129
super().__init__(
127130
loop=loop,
128-
client_id=ClientId(BYBIT_VENUE.value),
131+
client_id=ClientId(name or BYBIT_VENUE.value),
129132
venue=BYBIT_VENUE,
130133
oms_type=OmsType.NETTING,
131134
instrument_provider=instrument_provider,
@@ -153,7 +156,7 @@ def __init__(
153156

154157
self._enum_parser = BybitEnumParser()
155158

156-
account_id = AccountId(f"{BYBIT_VENUE.value}-UNIFIED")
159+
account_id = AccountId(f"{name or BYBIT_VENUE.value}-UNIFIED")
157160
self._set_account_id(account_id)
158161

159162
# WebSocket API

nautilus_trader/adapters/bybit/factories.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def create( # type: ignore
157157
loop : asyncio.AbstractEventLoop
158158
The event loop for the client.
159159
name : str
160-
The client name.
160+
The custom client ID.
161161
config : BybitDataClientConfig
162162
The client configuration.
163163
msgbus : MessageBus
@@ -202,6 +202,7 @@ def create( # type: ignore
202202
product_types=product_types,
203203
ws_base_urls=ws_base_urls,
204204
config=config,
205+
name=name,
205206
)
206207

207208

@@ -227,7 +228,7 @@ def create( # type: ignore
227228
loop : asyncio.AbstractEventLoop
228229
The event loop for the client.
229230
name : str
230-
The client name.
231+
The custom client ID.
231232
config : BybitExecClientConfig
232233
The client configuration.
233234
msgbus : MessageBus
@@ -266,4 +267,5 @@ def create( # type: ignore
266267
product_types=config.product_types or [BybitProductType.SPOT],
267268
base_url_ws=config.base_url_ws or base_url_ws,
268269
config=config,
270+
name=name,
269271
)

nautilus_trader/adapters/databento/data.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from nautilus_trader.adapters.databento.common import databento_schema_from_nautilus_bar_type
2525
from nautilus_trader.adapters.databento.config import DatabentoDataClientConfig
2626
from nautilus_trader.adapters.databento.constants import ALL_SYMBOLS
27-
from nautilus_trader.adapters.databento.constants import DATABENTO_CLIENT_ID
27+
from nautilus_trader.adapters.databento.constants import DATABENTO
2828
from nautilus_trader.adapters.databento.constants import PUBLISHERS_PATH
2929
from nautilus_trader.adapters.databento.enums import DatabentoSchema
3030
from nautilus_trader.adapters.databento.loaders import DatabentoDataLoader
@@ -48,6 +48,7 @@
4848
from nautilus_trader.model.data import capsule_to_data
4949
from nautilus_trader.model.enums import BookType
5050
from nautilus_trader.model.enums import bar_aggregation_to_str
51+
from nautilus_trader.model.identifiers import ClientId
5152
from nautilus_trader.model.identifiers import InstrumentId
5253
from nautilus_trader.model.identifiers import Venue
5354
from nautilus_trader.model.instruments import instruments_from_pyo3
@@ -78,6 +79,8 @@ class DatabentoDataClient(LiveMarketDataClient):
7879
The loader for the client.
7980
config : DatabentoDataClientConfig, optional
8081
The configuration for the client.
82+
name : str, optional
83+
The custom client ID.
8184
8285
"""
8386

@@ -91,14 +94,15 @@ def __init__(
9194
instrument_provider: DatabentoInstrumentProvider,
9295
loader: DatabentoDataLoader | None = None,
9396
config: DatabentoDataClientConfig | None = None,
97+
name: str | None = None,
9498
) -> None:
9599
if config is None:
96100
config = DatabentoDataClientConfig()
97101
PyCondition.type(config, DatabentoDataClientConfig, "config")
98102

99103
super().__init__(
100104
loop=loop,
101-
client_id=DATABENTO_CLIENT_ID,
105+
client_id=ClientId(name or DATABENTO),
102106
venue=None, # Not applicable
103107
msgbus=msgbus,
104108
cache=cache,

0 commit comments

Comments
 (0)