Skip to content

Commit d56e5d4

Browse files
authored
Add optional params to order strategy functions (#2251)
1 parent 822c683 commit d56e5d4

File tree

4 files changed

+86
-23
lines changed

4 files changed

+86
-23
lines changed

nautilus_trader/execution/messages.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ cdef class TradingCommand(Command):
3838
"""The strategy ID associated with the command.\n\n:returns: `StrategyId`"""
3939
cdef readonly InstrumentId instrument_id
4040
"""The instrument ID associated with the command.\n\n:returns: `InstrumentId`"""
41+
cdef readonly dict[str, object] params
42+
"""Additional specific parameters for the command.\n\n:returns: `dict[str, object]` or ``None``"""
4143

4244

4345
cdef class SubmitOrder(TradingCommand):

nautilus_trader/execution/messages.pyx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ cdef class TradingCommand(Command):
5252
The commands ID.
5353
ts_init : uint64_t
5454
UNIX timestamp (nanoseconds) when the object was initialized.
55+
params : dict[str, object], optional
56+
Additional parameters for the command.
5557
5658
Warnings
5759
--------
@@ -66,13 +68,15 @@ cdef class TradingCommand(Command):
6668
InstrumentId instrument_id not None,
6769
UUID4 command_id not None,
6870
uint64_t ts_init,
71+
dict[str, object] params: dict | None = None,
6972
):
7073
super().__init__(command_id, ts_init)
7174

7275
self.client_id = client_id
7376
self.trader_id = trader_id
7477
self.strategy_id = strategy_id
7578
self.instrument_id = instrument_id
79+
self.params = params
7680

7781

7882
cdef class SubmitOrder(TradingCommand):
@@ -95,6 +99,8 @@ cdef class SubmitOrder(TradingCommand):
9599
The position ID for the command.
96100
client_id : ClientId, optional
97101
The execution client ID for the command.
102+
params : dict[str, object], optional
103+
Additional parameters for the command.
98104
99105
References
100106
----------
@@ -110,6 +116,7 @@ cdef class SubmitOrder(TradingCommand):
110116
uint64_t ts_init,
111117
PositionId position_id: PositionId | None = None,
112118
ClientId client_id = None,
119+
dict[str, object] params: dict | None = None,
113120
):
114121
super().__init__(
115122
client_id=client_id,
@@ -118,6 +125,7 @@ cdef class SubmitOrder(TradingCommand):
118125
instrument_id=order.instrument_id,
119126
command_id=command_id,
120127
ts_init=ts_init,
128+
params=params,
121129
)
122130

123131
self.order = order
@@ -229,6 +237,8 @@ cdef class SubmitOrderList(TradingCommand):
229237
The position ID for the command.
230238
client_id : ClientId, optional
231239
The execution client ID for the command.
240+
params : dict[str, object], optional
241+
Additional parameters for the command.
232242
233243
References
234244
----------
@@ -244,6 +254,7 @@ cdef class SubmitOrderList(TradingCommand):
244254
uint64_t ts_init,
245255
PositionId position_id: PositionId | None = None,
246256
ClientId client_id = None,
257+
dict[str, object] params: dict | None = None,
247258
):
248259
super().__init__(
249260
client_id=client_id,
@@ -252,6 +263,7 @@ cdef class SubmitOrderList(TradingCommand):
252263
instrument_id=order_list.instrument_id,
253264
command_id=command_id,
254265
ts_init=ts_init,
266+
params=params,
255267
)
256268

257269
self.order_list = order_list
@@ -372,6 +384,8 @@ cdef class ModifyOrder(TradingCommand):
372384
UNIX timestamp (nanoseconds) when the object was initialized.
373385
client_id : ClientId, optional
374386
The execution client ID for the command.
387+
params : dict[str, object], optional
388+
Additional parameters for the command.
375389
376390
References
377391
----------
@@ -391,6 +405,7 @@ cdef class ModifyOrder(TradingCommand):
391405
UUID4 command_id not None,
392406
uint64_t ts_init,
393407
ClientId client_id = None,
408+
dict[str, object] params: dict | None = None,
394409
):
395410
super().__init__(
396411
client_id=client_id,
@@ -399,6 +414,7 @@ cdef class ModifyOrder(TradingCommand):
399414
instrument_id=instrument_id,
400415
command_id=command_id,
401416
ts_init=ts_init,
417+
params=params,
402418
)
403419

404420
self.client_order_id = client_order_id
@@ -526,6 +542,8 @@ cdef class CancelOrder(TradingCommand):
526542
UNIX timestamp (nanoseconds) when the object was initialized.
527543
client_id : ClientId, optional
528544
The execution client ID for the command.
545+
params : dict[str, object], optional
546+
Additional parameters for the command.
529547
530548
References
531549
----------
@@ -542,6 +560,7 @@ cdef class CancelOrder(TradingCommand):
542560
UUID4 command_id not None,
543561
uint64_t ts_init,
544562
ClientId client_id = None,
563+
dict[str, object] params: dict | None = None,
545564
):
546565
if client_id is None:
547566
client_id = ClientId(instrument_id.venue.value)
@@ -552,6 +571,7 @@ cdef class CancelOrder(TradingCommand):
552571
instrument_id=instrument_id,
553572
command_id=command_id,
554573
ts_init=ts_init,
574+
params=params,
555575
)
556576

557577
self.client_order_id = client_order_id
@@ -659,6 +679,8 @@ cdef class CancelAllOrders(TradingCommand):
659679
UNIX timestamp (nanoseconds) when the object was initialized.
660680
client_id : ClientId, optional
661681
The execution client ID for the command.
682+
params : dict[str, object], optional
683+
Additional parameters for the command.
662684
"""
663685

664686
def __init__(
@@ -670,6 +692,7 @@ cdef class CancelAllOrders(TradingCommand):
670692
UUID4 command_id not None,
671693
uint64_t ts_init,
672694
ClientId client_id = None,
695+
dict[str, object] params: dict | None = None,
673696
):
674697
super().__init__(
675698
client_id=client_id,
@@ -678,6 +701,7 @@ cdef class CancelAllOrders(TradingCommand):
678701
instrument_id=instrument_id,
679702
command_id=command_id,
680703
ts_init=ts_init,
704+
params=params,
681705
)
682706

683707
self.order_side = order_side
@@ -779,6 +803,8 @@ cdef class BatchCancelOrders(TradingCommand):
779803
UNIX timestamp (nanoseconds) when the object was initialized.
780804
client_id : ClientId, optional
781805
The execution client ID for the command.
806+
params : dict[str, object], optional
807+
Additional parameters for the command.
782808
783809
Raises
784810
------
@@ -797,6 +823,7 @@ cdef class BatchCancelOrders(TradingCommand):
797823
UUID4 command_id not None,
798824
uint64_t ts_init,
799825
ClientId client_id = None,
826+
dict[str, object] params: dict | None = None,
800827
):
801828
Condition.not_empty(cancels, "cancels")
802829
Condition.list_type(cancels, CancelOrder, "cancels")
@@ -807,6 +834,7 @@ cdef class BatchCancelOrders(TradingCommand):
807834
instrument_id=instrument_id,
808835
command_id=command_id,
809836
ts_init=ts_init,
837+
params=params,
810838
)
811839

812840
self.cancels = cancels
@@ -910,6 +938,8 @@ cdef class QueryOrder(TradingCommand):
910938
UNIX timestamp (nanoseconds) when the object was initialized.
911939
client_id : ClientId, optional
912940
The execution client ID for the command.
941+
params : dict[str, object], optional
942+
Additional parameters for the command.
913943
"""
914944

915945
def __init__(
@@ -922,6 +952,7 @@ cdef class QueryOrder(TradingCommand):
922952
UUID4 command_id not None,
923953
uint64_t ts_init,
924954
ClientId client_id = None,
955+
dict[str, object] params: dict | None = None,
925956
):
926957
if client_id is None:
927958
client_id = ClientId(instrument_id.venue.value)
@@ -932,6 +963,7 @@ cdef class QueryOrder(TradingCommand):
932963
instrument_id=instrument_id,
933964
command_id=command_id,
934965
ts_init=ts_init,
966+
params=params,
935967
)
936968

937969
self.client_order_id = client_order_id

nautilus_trader/trading/strategy.pxd

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ from nautilus_trader.core.rust.model cimport PositionSide
2525
from nautilus_trader.execution.manager cimport OrderManager
2626
from nautilus_trader.execution.messages cimport CancelOrder
2727
from nautilus_trader.execution.messages cimport ModifyOrder
28-
from nautilus_trader.execution.messages cimport TradingCommand
29-
from nautilus_trader.model.data cimport Bar
30-
from nautilus_trader.model.data cimport BarType
31-
from nautilus_trader.model.data cimport QuoteTick
32-
from nautilus_trader.model.data cimport TradeTick
3328
from nautilus_trader.model.events.order cimport OrderAccepted
3429
from nautilus_trader.model.events.order cimport OrderCanceled
3530
from nautilus_trader.model.events.order cimport OrderCancelRejected
@@ -53,7 +48,6 @@ from nautilus_trader.model.events.position cimport PositionEvent
5348
from nautilus_trader.model.events.position cimport PositionOpened
5449
from nautilus_trader.model.identifiers cimport ClientId
5550
from nautilus_trader.model.identifiers cimport ClientOrderId
56-
from nautilus_trader.model.identifiers cimport ExecAlgorithmId
5751
from nautilus_trader.model.identifiers cimport InstrumentId
5852
from nautilus_trader.model.identifiers cimport PositionId
5953
from nautilus_trader.model.identifiers cimport StrategyId
@@ -125,37 +119,38 @@ cdef class Strategy(Actor):
125119
self,
126120
Order order,
127121
PositionId position_id=*,
128-
ClientId client_id=*,
122+
ClientId client_id=*, dict[str, object] params=*,
129123
)
130124
cpdef void submit_order_list(
131125
self,
132126
OrderList order_list,
133127
PositionId position_id=*,
134-
ClientId client_id=*,
128+
ClientId client_id=*, dict[str, object] params=*,
135129
)
136130
cpdef void modify_order(
137131
self,
138132
Order order,
139133
Quantity quantity=*,
140134
Price price=*,
141135
Price trigger_price=*,
142-
ClientId client_id=*,
136+
ClientId client_id=*, dict[str, object] params=*,
143137
)
144-
cpdef void cancel_order(self, Order order, ClientId client_id=*)
145-
cpdef void cancel_orders(self, list orders, ClientId client_id=*)
146-
cpdef void cancel_all_orders(self, InstrumentId instrument_id, OrderSide order_side=*, ClientId client_id=*)
147-
cpdef void close_position(self, Position position, ClientId client_id=*, list[str] tags=*, bint reduce_only=*)
148-
cpdef void close_all_positions(self, InstrumentId instrument_id, PositionSide position_side=*, ClientId client_id=*, list[str] tags=*, bint reduce_only=*)
149-
cpdef void query_order(self, Order order, ClientId client_id=*)
138+
cpdef void cancel_order(self, Order order, ClientId client_id=*,dict[str, object] params=*)
139+
cpdef void cancel_orders(self, list orders, ClientId client_id=*,dict[str, object] params=*)
140+
cpdef void cancel_all_orders(self, InstrumentId instrument_id, OrderSide order_side=*, ClientId client_id=*, dict[str, object] params=*)
141+
cpdef void close_position(self, Position position, ClientId client_id=*, list[str] tags=*, bint reduce_only=*, dict[str, object] params=*)
142+
cpdef void close_all_positions(self, InstrumentId instrument_id, PositionSide position_side=*, ClientId client_id=*, list[str] tags=*, bint reduce_only=*, dict[str, object] params=*)
143+
cpdef void query_order(self, Order order, ClientId client_id=*, dict[str, object] params=*)
150144
cdef ModifyOrder _create_modify_order(
151145
self,
152146
Order order,
153147
Quantity quantity=*,
154148
Price price=*,
155149
Price trigger_price=*,
156150
ClientId client_id=*,
151+
dict[str, object] params=*,
157152
)
158-
cdef CancelOrder _create_cancel_order(self, Order order, ClientId client_id=*)
153+
cdef CancelOrder _create_cancel_order(self, Order order, ClientId client_id=*, dict[str, object] params=*)
159154

160155
cpdef void cancel_gtd_expiry(self, Order order)
161156
cdef bint _has_gtd_expiry_timer(self, ClientOrderId client_order_id)

0 commit comments

Comments
 (0)