@@ -10,16 +10,21 @@ def main():
1010 parser .add_argument ("--is_buy" , action = "store_true" )
1111 args = parser .parse_args ()
1212
13- address , info , exchange = example_utils .setup (constants .TESTNET_API_URL , skip_ws = True )
13+ _ , _ , exchange = example_utils .setup (constants .TESTNET_API_URL , skip_ws = True )
1414
1515 is_buy = args .is_buy
16- # Place an order that should execute by setting the price very aggressively
17- order_result = exchange .order ("ETH" , is_buy , 0.02 , 2500 if is_buy else 1500 , {"limit" : {"tif" : "Gtc" }})
16+ coin = "ETH"
17+ sz = 0.02
18+ px = 3500 if is_buy else 2500
19+ trigger_px = 2600 if is_buy else 3400
20+ sl_px = 2500 if is_buy else 3500
21+ # Place an order that should execute by setting the price very aggressively, the above prices were set when ETH was at 3000
22+ order_result = exchange .order (coin , is_buy , sz , px , {"limit" : {"tif" : "Gtc" }})
1823 print (order_result )
1924
2025 # Place a stop order
21- stop_order_type = {"trigger" : {"triggerPx" : 1600 if is_buy else 2400 , "isMarket" : True , "tpsl" : "sl" }}
22- stop_result = exchange .order ("ETH" , not is_buy , 0.02 , 1500 if is_buy else 2500 , stop_order_type , reduce_only = True )
26+ stop_order_type = {"trigger" : {"triggerPx" : trigger_px , "isMarket" : True , "tpsl" : "sl" }}
27+ stop_result = exchange .order ("ETH" , not is_buy , sz , sl_px , stop_order_type , reduce_only = True )
2328 print (stop_result )
2429
2530 # Cancel the order
@@ -30,8 +35,8 @@ def main():
3035 print (cancel_result )
3136
3237 # Place a tp order
33- tp_order_type = {"trigger" : {"triggerPx" : 1600 if is_buy else 2400 , "isMarket" : True , "tpsl" : "tp" }}
34- tp_result = exchange .order ("ETH" , not is_buy , 0.02 , 2500 if is_buy else 1500 , tp_order_type , reduce_only = True )
38+ tp_order_type = {"trigger" : {"triggerPx" : px , "isMarket" : True , "tpsl" : "tp" }}
39+ tp_result = exchange .order ("ETH" , not is_buy , sz , px , tp_order_type , reduce_only = True )
3540 print (tp_result )
3641
3742 # Cancel the order
@@ -41,6 +46,49 @@ def main():
4146 cancel_result = exchange .cancel ("ETH" , status ["resting" ]["oid" ])
4247 print (cancel_result )
4348
49+ # Alternatively use grouping to place the parent order and child TP/SL in a single action
50+ orders = [
51+ {
52+ "coin" : "ETH" ,
53+ "is_buy" : is_buy ,
54+ "sz" : sz ,
55+ "limit_px" : px ,
56+ "order_type" : {"limit" : {"tif" : "Gtc" }},
57+ "reduce_only" : False ,
58+ },
59+ {
60+ "coin" : "ETH" ,
61+ "is_buy" : not is_buy ,
62+ "sz" : sz ,
63+ "limit_px" : px ,
64+ "order_type" : {
65+ "trigger" : {
66+ "isMarket" : True ,
67+ "triggerPx" : px ,
68+ "tpsl" : "tp" ,
69+ }
70+ },
71+ "reduce_only" : True ,
72+ },
73+ {
74+ "coin" : coin ,
75+ "is_buy" : not is_buy ,
76+ "sz" : sz ,
77+ "limit_px" : sl_px ,
78+ "order_type" : {
79+ "trigger" : {
80+ "isMarket" : True ,
81+ "triggerPx" : trigger_px ,
82+ "tpsl" : "sl" ,
83+ }
84+ },
85+ "reduce_only" : True ,
86+ },
87+ ]
88+
89+ resp = exchange .bulk_orders (orders , grouping = "normalTpsl" )
90+ print (resp )
91+
4492
4593if __name__ == "__main__" :
4694 main ()
0 commit comments