Skip to content

Commit 8694d88

Browse files
authored
"Manual or Auto" OrderPlacement declaration (#41)
* variable manual_or_auto OrderPlacement - Option to set-and-forget at client init - Option to override on each request in cases of part-auto part-manual applications * Update client.py * Update order.py
1 parent da137e6 commit 8694d88

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

async_rithmic/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .plants.order import OrderPlant
1010
from .plants.pnl import PnlPlant
1111
from .logger import logger
12-
from .enums import SysInfraType
12+
from .enums import OrderPlacement, SysInfraType
1313
from .objects import ReconnectionSettings, RetrySettings
1414

1515
def _setup_ssl_context():
@@ -31,6 +31,7 @@ def __init__(
3131
app_name: str,
3232
app_version: str,
3333
url: str,
34+
manual_or_auto: OrderPlacement = OrderPlacement.MANUAL,
3435
**kwargs
3536
):
3637
# Connection events
@@ -60,6 +61,9 @@ def __init__(
6061
if "://" not in url:
6162
url = f"wss://{url}"
6263

64+
assert manual_or_auto in [OrderPlacement.MANUAL, OrderPlacement.AUTO], "manual_or_auto must be an instance of .enums.OrderPlacement"
65+
self.manual_or_auto = manual_or_auto
66+
6367
self.credentials = dict(
6468
user=user,
6569
password=password,

async_rithmic/plants/order.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ async def submit_order(
254254
msg_kwargs["cancel_at_ssboe"] = ssboe
255255
msg_kwargs["cancel_at_usecs"] = usecs
256256

257+
manual_or_auto = kwargs.get("manual_or_auto", self.client.manual_or_auto)
258+
257259
return await self._send_and_collect(
258260
template_id=template_id,
259261
expected_response=dict(template_id=template_id + 1),
@@ -262,7 +264,7 @@ async def submit_order(
262264
exchange=exchange,
263265
price_type=order_type,
264266
quantity=qty,
265-
manual_or_auto=OrderPlacement.MANUAL,
267+
manual_or_auto=manual_or_auto,
266268
transaction_type=transaction_type,
267269
duration=kwargs["duration"],
268270
**msg_kwargs
@@ -284,10 +286,12 @@ async def cancel_order(self, **kwargs):
284286
basket_id = order.basket_id
285287
account_id = order.account_id
286288

289+
manual_or_auto = kwargs.get("manual_or_auto", self.client.manual_or_auto)
290+
287291
return await self._send_and_collect(
288292
template_id=316,
289293
expected_response=dict(template_id=317),
290-
manual_or_auto=OrderPlacement.MANUAL,
294+
manual_or_auto=manual_or_auto,
291295
basket_id=basket_id,
292296
account_id=account_id,
293297
)
@@ -296,10 +300,12 @@ async def cancel_all_orders(self, **kwargs):
296300
"""
297301
Cancel all orders
298302
"""
303+
manual_or_auto = kwargs.get("manual_or_auto", self.client.manual_or_auto)
304+
299305
return await self._send_and_collect(
300306
template_id=346,
301307
expected_response=dict(template_id=347),
302-
manual_or_auto=OrderPlacement.MANUAL,
308+
manual_or_auto=manual_or_auto,
303309
account_id=self._get_account_id(**kwargs)
304310
)
305311

@@ -360,10 +366,13 @@ async def modify_order(self, **kwargs):
360366

361367
# Update the actual order
362368
msg_kwargs = self._validate_price_fields(order_type, raise_exception=False, **kwargs)
369+
370+
manual_or_auto = kwargs.get("manual_or_auto", self.client.manual_or_auto)
371+
363372
return await self._send_and_collect(
364373
template_id=314,
365374
expected_response=dict(template_id=315),
366-
manual_or_auto=OrderPlacement.MANUAL,
375+
manual_or_auto=manual_or_auto,
367376
account_id=order.account_id,
368377
basket_id=order.basket_id,
369378
symbol=order.symbol,
@@ -404,10 +413,12 @@ async def exit_position(self, **kwargs):
404413
You can pass `symbol` and `exchange` to target a specific position, otherwise all the account positions will
405414
be exited.
406415
"""
416+
manual_or_auto = kwargs.get("manual_or_auto", self.client.manual_or_auto)
417+
407418
return await self._send_and_collect(
408419
template_id=3504,
409420
expected_response=dict(template_id=3505),
410-
manual_or_auto=OrderPlacement.MANUAL,
421+
manual_or_auto=manual_or_auto,
411422
**kwargs
412423
)
413424

0 commit comments

Comments
 (0)