@@ -137,6 +137,68 @@ def DerivativeOrder(
137137 trigger_price = str (trigger_price ),
138138 )
139139
140+ def BinaryOptionsOrder (
141+ self ,
142+ market_id : str ,
143+ subaccount_id : str ,
144+ fee_recipient : str ,
145+ price : float ,
146+ quantity : float ,
147+ ** kwargs
148+ ):
149+ # load denom metadata
150+ denom = Denom .load_market (self .network , market_id )
151+ print ("Loaded market metadata for" , denom .description )
152+
153+ if kwargs .get ("is_reduce_only" ) is None and kwargs .get ("is_buy" ):
154+ margin = binary_options_buy_margin_to_backend (
155+ price , quantity , denom
156+ )
157+ elif kwargs .get ("is_reduce_only" ) is None and not kwargs .get ("is_buy" ):
158+ margin = binary_options_sell_margin_to_backend (
159+ price , quantity , denom
160+ )
161+ elif kwargs .get ("is_reduce_only" ) is False and kwargs .get ("is_buy" ):
162+ margin = binary_options_buy_margin_to_backend (
163+ price , quantity , denom
164+ )
165+ elif kwargs .get ("is_reduce_only" ) is False and not kwargs .get ("is_buy" ):
166+ margin = binary_options_sell_margin_to_backend (
167+ price , quantity , denom
168+ )
169+ elif kwargs .get ("is_reduce_only" , True ):
170+ margin = 0
171+
172+ # prepare values
173+ price = binary_options_price_to_backend (price , denom )
174+ trigger_price = binary_options_price_to_backend (0 , denom )
175+ quantity = binary_options_quantity_to_backend (quantity , denom )
176+
177+ if kwargs .get ("is_buy" ) and not kwargs .get ("is_po" ):
178+ order_type = injective_exchange_pb .OrderType .BUY
179+
180+ elif not kwargs .get ("is_buy" ) and not kwargs .get ("is_po" ):
181+ order_type = injective_exchange_pb .OrderType .SELL
182+
183+ elif kwargs .get ("is_buy" ) and kwargs .get ("is_po" ):
184+ order_type = injective_exchange_pb .OrderType .BUY_PO
185+
186+ elif not kwargs .get ("is_buy" ) and kwargs .get ("is_po" ):
187+ order_type = injective_exchange_pb .OrderType .SELL_PO
188+
189+ return injective_exchange_pb .DerivativeOrder (
190+ market_id = market_id ,
191+ order_info = injective_exchange_pb .OrderInfo (
192+ subaccount_id = subaccount_id ,
193+ fee_recipient = fee_recipient ,
194+ price = str (price ),
195+ quantity = str (quantity ),
196+ ),
197+ margin = str (margin ),
198+ order_type = order_type ,
199+ trigger_price = str (trigger_price ),
200+ )
201+
140202 def MsgSend (self , from_address : str , to_address : str , amount : float , denom : str ):
141203 peggy_denom , decimals = Denom .load_peggy_denom (self .network , denom )
142204 be_amount = amount_to_backend (amount , decimals )
@@ -287,6 +349,137 @@ def MsgCreateDerivativeMarketOrder(
287349 ),
288350 )
289351
352+ def MsgCreateBinaryOptionsLimitOrder (
353+ self ,
354+ market_id : str ,
355+ sender : str ,
356+ subaccount_id : str ,
357+ fee_recipient : str ,
358+ price : float ,
359+ quantity : float ,
360+ ** kwargs
361+ ):
362+ return injective_exchange_tx_pb .MsgCreateBinaryOptionsLimitOrder (
363+ sender = sender ,
364+ order = self .BinaryOptionsOrder (
365+ market_id = market_id ,
366+ subaccount_id = subaccount_id ,
367+ fee_recipient = fee_recipient ,
368+ price = price ,
369+ quantity = quantity ,
370+ is_buy = kwargs .get ("is_buy" ),
371+ is_po = kwargs .get ("is_po" ),
372+ is_reduce_only = kwargs .get ("is_reduce_only" ),
373+ ),
374+ )
375+
376+ def MsgCreateBinaryOptionsMarketOrder (
377+ self ,
378+ market_id : str ,
379+ sender : str ,
380+ subaccount_id : str ,
381+ fee_recipient : str ,
382+ price : float ,
383+ quantity : float ,
384+ ** kwargs
385+ ):
386+ return injective_exchange_tx_pb .MsgCreateBinaryOptionsMarketOrder (
387+ sender = sender ,
388+ order = self .BinaryOptionsOrder (
389+ market_id = market_id ,
390+ subaccount_id = subaccount_id ,
391+ fee_recipient = fee_recipient ,
392+ price = price ,
393+ quantity = quantity ,
394+ is_buy = kwargs .get ("is_buy" ),
395+ is_reduce_only = kwargs .get ("is_reduce_only" ),
396+ ),
397+ )
398+
399+ def MsgCancelBinaryOptionsOrder (
400+ self ,
401+ sender : str ,
402+ market_id : str ,
403+ subaccount_id : str ,
404+ order_hash : str ):
405+
406+ return injective_exchange_tx_pb .MsgCancelBinaryOptionsOrder (
407+ sender = sender ,
408+ market_id = market_id ,
409+ subaccount_id = subaccount_id ,
410+ order_hash = order_hash
411+ )
412+
413+ def MsgAdminUpdateBinaryOptionsMarket (
414+ self ,
415+ sender : str ,
416+ market_id : str ,
417+ settlement_price : float ,
418+ expiration_timestamp : int ,
419+ settlement_timestamp : int ,
420+ status : str
421+ ):
422+
423+ scale_price = Decimal ((settlement_price * pow (10 , 18 )))
424+ price_to_bytes = bytes (str (scale_price ), "utf-8" )
425+ print (scale_price )
426+
427+ return injective_exchange_tx_pb .MsgAdminUpdateBinaryOptionsMarket (
428+ sender = sender ,
429+ market_id = market_id ,
430+ settlement_price = price_to_bytes ,
431+ expiration_timestamp = expiration_timestamp ,
432+ settlement_timestamp = settlement_timestamp ,
433+ status = status
434+ )
435+
436+ def MsgInstantBinaryOptionsMarketLaunch (
437+ self ,
438+ sender : str ,
439+ ticker : str ,
440+ oracle_symbol : str ,
441+ oracle_provider : str ,
442+ oracle_type : str ,
443+ oracle_scale_factor : int ,
444+ maker_fee_rate : float ,
445+ taker_fee_rate : float ,
446+ expiration_timestamp : int ,
447+ settlement_timestamp : int ,
448+ quote_denom : str ,
449+ min_price_tick_size : float ,
450+ min_quantity_tick_size : float ,
451+ ** kwargs
452+ ):
453+
454+ scaled_maker_fee_rate = Decimal ((maker_fee_rate * pow (10 , 18 )))
455+ maker_fee_to_bytes = bytes (str (scaled_maker_fee_rate ), "utf-8" )
456+
457+ scaled_taker_fee_rate = Decimal ((taker_fee_rate * pow (10 , 18 )))
458+ taker_fee_to_bytes = bytes (str (scaled_taker_fee_rate ), "utf-8" )
459+
460+ scaled_min_price_tick_size = Decimal ((min_price_tick_size * pow (10 , 18 )))
461+ min_price_to_bytes = bytes (str (scaled_min_price_tick_size ), "utf-8" )
462+
463+ scaled_min_quantity_tick_size = Decimal ((min_quantity_tick_size * pow (10 , 18 )))
464+ min_quantity_to_bytes = bytes (str (scaled_min_quantity_tick_size ), "utf-8" )
465+
466+ return injective_exchange_tx_pb .MsgInstantBinaryOptionsMarketLaunch (
467+ sender = sender ,
468+ ticker = ticker ,
469+ oracle_symbol = oracle_symbol ,
470+ oracle_provider = oracle_provider ,
471+ oracle_type = oracle_type ,
472+ oracle_scale_factor = oracle_scale_factor ,
473+ maker_fee_rate = maker_fee_to_bytes ,
474+ taker_fee_rate = taker_fee_to_bytes ,
475+ expiration_timestamp = expiration_timestamp ,
476+ settlement_timestamp = settlement_timestamp ,
477+ quote_denom = quote_denom ,
478+ min_price_tick_size = min_price_to_bytes ,
479+ min_quantity_tick_size = min_quantity_to_bytes ,
480+ admin = kwargs .get ("admin" )
481+ )
482+
290483 def MsgCancelDerivativeOrder (
291484 self , market_id : str , sender : str , subaccount_id : str , order_hash : str
292485 ):
@@ -312,13 +505,14 @@ def MsgBatchUpdateOrders(self, sender: str, **kwargs):
312505 sender = sender ,
313506 subaccount_id = kwargs .get ("subaccount_id" ),
314507 spot_market_ids_to_cancel_all = kwargs .get ("spot_market_ids_to_cancel_all" ),
315- derivative_market_ids_to_cancel_all = kwargs .get (
316- "derivative_market_ids_to_cancel_all"
317- ),
508+ derivative_market_ids_to_cancel_all = kwargs .get ("derivative_market_ids_to_cancel_all" ),
318509 spot_orders_to_cancel = kwargs .get ("spot_orders_to_cancel" ),
319510 derivative_orders_to_cancel = kwargs .get ("derivative_orders_to_cancel" ),
320511 spot_orders_to_create = kwargs .get ("spot_orders_to_create" ),
321512 derivative_orders_to_create = kwargs .get ("derivative_orders_to_create" ),
513+ binary_options_orders_to_cancel = kwargs .get ("binary_options_orders_to_cancel" ),
514+ binary_options_market_ids_to_cancel_all = kwargs .get ("binary_options_market_ids_to_cancel_all" ),
515+ binary_options_orders_to_create = kwargs .get ("binary_options_orders_to_create" )
322516 )
323517
324518 def MsgLiquidatePosition (self , sender : str , subaccount_id : str , market_id : str ):
@@ -575,6 +769,11 @@ def MsgResponses(data, simulation=False):
575769 "/injective.exchange.v1beta1.MsgLiquidatePosition" : injective_exchange_tx_pb .MsgLiquidatePositionResponse ,
576770 "/injective.exchange.v1beta1.MsgIncreasePositionMargin" : injective_exchange_tx_pb .MsgIncreasePositionMarginResponse ,
577771 "/injective.auction.v1beta1.MsgBid" : injective_auction_tx_pb .MsgBidResponse ,
772+ "/injective.exchange.v1beta1.MsgCreateBinaryOptionsLimitOrder" : injective_exchange_tx_pb .MsgCreateBinaryOptionsLimitOrderResponse ,
773+ "/injective.exchange.v1beta1.MsgCreateBinaryOptionsMarketOrder" : injective_exchange_tx_pb .MsgCreateBinaryOptionsMarketOrderResponse ,
774+ "/injective.exchange.v1beta1.MsgCancelBinaryOptionsOrder" : injective_exchange_tx_pb .MsgCancelBinaryOptionsOrderResponse ,
775+ "/injective.exchange.v1beta1.MsgAdminUpdateBinaryOptionsMarket" : injective_exchange_tx_pb .MsgAdminUpdateBinaryOptionsMarketResponse ,
776+ "/injective.exchange.v1beta1.MsgInstantBinaryOptionsMarketLaunch" : injective_exchange_tx_pb .MsgInstantBinaryOptionsMarketLaunchResponse ,
578777 "/cosmos.bank.v1beta1.MsgSend" : cosmos_bank_tx_pb .MsgSendResponse ,
579778 "/cosmos.authz.v1beta1.MsgGrant" : cosmos_authz_tx_pb .MsgGrantResponse ,
580779 "/cosmos.authz.v1beta1.MsgExec" : cosmos_authz_tx_pb .MsgExecResponse ,
@@ -608,6 +807,11 @@ def UnpackMsgExecResponse(msg_type, data):
608807 "MsgSubaccountTransfer" : injective_exchange_tx_pb .MsgSubaccountTransferResponse ,
609808 "MsgLiquidatePosition" : injective_exchange_tx_pb .MsgLiquidatePositionResponse ,
610809 "MsgIncreasePositionMargin" : injective_exchange_tx_pb .MsgIncreasePositionMarginResponse ,
810+ "MsgCreateBinaryOptionsLimitOrder" : injective_exchange_tx_pb .MsgCreateBinaryOptionsLimitOrderResponse ,
811+ "MsgCreateBinaryOptionsMarketOrder" : injective_exchange_tx_pb .MsgCreateBinaryOptionsMarketOrderResponse ,
812+ "MsgCancelBinaryOptionsOrder" : injective_exchange_tx_pb .MsgCancelBinaryOptionsOrderResponse ,
813+ "MsgAdminUpdateBinaryOptionsMarket" : injective_exchange_tx_pb .MsgAdminUpdateBinaryOptionsMarketResponse ,
814+ "MsgInstantBinaryOptionsMarketLaunch" : injective_exchange_tx_pb .MsgInstantBinaryOptionsMarketLaunchResponse
611815 }
612816
613817 return header_map [msg_type ].FromString (bytes (data , "utf-8" ))
0 commit comments