Skip to content

Commit

Permalink
(feat) Added cid to all messages used to cancel orders in spot, deriv…
Browse files Browse the repository at this point in the history
…ative and binary versions
  • Loading branch information
abel committed Oct 25, 2023
1 parent 9407224 commit 2a53d22
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/chain_client/17_MsgBatchUpdateOrders.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def main() -> None:
composer.OrderData(
market_id=spot_market_id_cancel,
subaccount_id=subaccount_id,
order_hash="0x3870fbdd91f07d54425147b1bb96404f4f043ba6335b422a6d494d285b387f2d",
cid="0e5c3ad5-2cc4-4a2a-bbe5-b12697739163",
),
composer.OrderData(
market_id=spot_market_id_cancel_2,
Expand Down
4 changes: 3 additions & 1 deletion examples/chain_client/3_MsgCreateSpotLimitOrder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async def main() -> None:
# prepare trade info
market_id = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
cid = str(uuid.uuid4())

# prepare tx msg
msg = composer.MsgCreateSpotLimitOrder(
Expand All @@ -37,7 +38,7 @@ async def main() -> None:
quantity=0.01,
is_buy=True,
is_po=False,
cid=str(uuid.uuid4()),
cid=cid,
)

# build sim tx
Expand Down Expand Up @@ -83,6 +84,7 @@ async def main() -> None:
print(res)
print("gas wanted: {}".format(gas_limit))
print("gas fee: {} INJ".format(gas_fee))
print(f"\n\ncid: {cid}")


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/exchange_client/meta_rpc/4_StreamKeepAlive.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ async def main() -> None:
network = Network.testnet()
client = AsyncClient(network)

task1 = asyncio.create_task(get_markets(client))
task2 = asyncio.create_task(keepalive(client, [task1]))
task1 = asyncio.get_event_loop().create_task(get_markets(client))
task2 = asyncio.get_event_loop().create_task(keepalive(client, [task1]))

try:
await asyncio.gather(
Expand Down
2 changes: 1 addition & 1 deletion pyinjective/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ def _exchange_cookie_metadata_requestor(self) -> Coroutine:

def _initialize_timeout_height_sync_task(self):
self._cancel_timeout_height_sync_task()
self._timeout_height_sync_task = asyncio.create_task(self._timeout_height_sync_process())
self._timeout_height_sync_task = asyncio.get_event_loop().create_task(self._timeout_height_sync_process())

async def _timeout_height_sync_process(self):
while True:
Expand Down
36 changes: 32 additions & 4 deletions pyinjective/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,17 @@ def get_order_mask(self, **kwargs):

return order_mask

def OrderData(self, market_id: str, subaccount_id: str, order_hash: str, **kwargs):
def OrderData(
self, market_id: str, subaccount_id: str, order_hash: Optional[str] = None, cid: Optional[str] = None, **kwargs
):
order_mask = self.get_order_mask(**kwargs)

return injective_exchange_tx_pb.OrderData(
market_id=market_id,
subaccount_id=subaccount_id,
order_hash=order_hash,
order_mask=order_mask,
cid=cid,
)

def SpotOrder(
Expand Down Expand Up @@ -348,12 +351,20 @@ def MsgCreateSpotMarketOrder(
),
)

def MsgCancelSpotOrder(self, market_id: str, sender: str, subaccount_id: str, order_hash: str):
def MsgCancelSpotOrder(
self,
market_id: str,
sender: str,
subaccount_id: str,
order_hash: Optional[str] = None,
cid: Optional[str] = None,
):
return injective_exchange_tx_pb.MsgCancelSpotOrder(
sender=sender,
market_id=market_id,
subaccount_id=subaccount_id,
order_hash=order_hash,
cid=cid,
)

def MsgBatchCreateSpotLimitOrders(self, sender: str, orders: List):
Expand Down Expand Up @@ -463,12 +474,20 @@ def MsgCreateBinaryOptionsMarketOrder(
),
)

def MsgCancelBinaryOptionsOrder(self, sender: str, market_id: str, subaccount_id: str, order_hash: str):
def MsgCancelBinaryOptionsOrder(
self,
sender: str,
market_id: str,
subaccount_id: str,
order_hash: Optional[str] = None,
cid: Optional[str] = None,
):
return injective_exchange_tx_pb.MsgCancelBinaryOptionsOrder(
sender=sender,
market_id=market_id,
subaccount_id=subaccount_id,
order_hash=order_hash,
cid=cid,
)

def MsgAdminUpdateBinaryOptionsMarket(
Expand Down Expand Up @@ -555,7 +574,15 @@ def MsgInstantBinaryOptionsMarketLaunch(
admin=kwargs.get("admin"),
)

def MsgCancelDerivativeOrder(self, market_id: str, sender: str, subaccount_id: str, order_hash: str, **kwargs):
def MsgCancelDerivativeOrder(
self,
market_id: str,
sender: str,
subaccount_id: str,
order_hash: Optional[str] = None,
cid: Optional[str] = None,
**kwargs,
):
order_mask = self.get_order_mask(**kwargs)

return injective_exchange_tx_pb.MsgCancelDerivativeOrder(
Expand All @@ -564,6 +591,7 @@ def MsgCancelDerivativeOrder(self, market_id: str, sender: str, subaccount_id: s
subaccount_id=subaccount_id,
order_hash=order_hash,
order_mask=order_mask,
cid=cid,
)

def MsgBatchCreateDerivativeLimitOrders(self, sender: str, orders: List):
Expand Down

0 comments on commit 2a53d22

Please sign in to comment.