1111Tif  =  Union [Literal ["Alo" ], Literal ["Ioc" ], Literal ["Gtc" ]]
1212Tpsl  =  Union [Literal ["tp" ], Literal ["sl" ]]
1313LimitOrderType  =  TypedDict ("LimitOrderType" , {"tif" : Tif })
14- TriggerOrderType  =  TypedDict ("TriggerOrderType" , {"triggerPx" : int , "isMarket" : bool , "tpsl" : Tpsl })
14+ TriggerOrderType  =  TypedDict ("TriggerOrderType" , {"triggerPx" : float , "isMarket" : bool , "tpsl" : Tpsl })
15+ TriggerOrderTypeWire  =  TypedDict ("TriggerOrderTypeWire" , {"triggerPx" : str , "isMarket" : bool , "tpsl" : Tpsl })
1516OrderType  =  TypedDict ("OrderType" , {"limit" : LimitOrderType , "trigger" : TriggerOrderType }, total = False )
17+ OrderTypeWire  =  TypedDict ("OrderTypeWire" , {"limit" : LimitOrderType , "trigger" : TriggerOrderTypeWire }, total = False )
1618
1719
18- def  order_type_to_tuple (order_type : OrderType ) ->  Tuple [int , int ]:
20+ def  order_type_to_tuple (order_type : OrderType ) ->  Tuple [int , float ]:
1921    if  "limit"  in  order_type :
2022        tif  =  order_type ["limit" ]["tif" ]
2123        if  tif  ==  "Gtc" :
@@ -69,10 +71,25 @@ def order_spec_preprocessing(order_spec: OrderSpec) -> Any:
6971
7072
7173OrderWire  =  TypedDict (
72-     "OrderWire" , {"asset" : int , "isBuy" : bool , "limitPx" : str , "sz" : str , "reduceOnly" : bool , "orderType" : OrderType }
74+     "OrderWire" ,
75+     {"asset" : int , "isBuy" : bool , "limitPx" : str , "sz" : str , "reduceOnly" : bool , "orderType" : OrderTypeWire },
7376)
7477
7578
79+ def  order_type_to_wire (order_type : OrderType ) ->  OrderTypeWire :
80+     if  "limit"  in  order_type :
81+         return  {"limit" : order_type ["limit" ]}
82+     elif  "trigger"  in  order_type :
83+         return  {
84+             "trigger" : {
85+                 "triggerPx" : float_to_wire (order_type ["trigger" ]["triggerPx" ]),
86+                 "tpsl" : order_type ["trigger" ]["tpsl" ],
87+                 "isMarket" : order_type ["trigger" ]["isMarket" ],
88+             }
89+         }
90+     raise  ValueError ("Invalid order type" , order_type )
91+ 
92+ 
7693def  order_spec_to_order_wire (order_spec : OrderSpec ) ->  OrderWire :
7794    order  =  order_spec ["order" ]
7895    return  {
@@ -81,7 +98,7 @@ def order_spec_to_order_wire(order_spec: OrderSpec) -> OrderWire:
8198        "limitPx" : float_to_wire (order ["limitPx" ]),
8299        "sz" : float_to_wire (order ["sz" ]),
83100        "reduceOnly" : order ["reduceOnly" ],
84-         "orderType" : order_spec ["orderType" ],
101+         "orderType" : order_type_to_wire ( order_spec ["orderType" ]) ,
85102    }
86103
87104
0 commit comments