async def broadcast_cancel_order( background_tasks: BackgroundTasks, cancel_order: SignCancelOrderSchema = Body( ..., example={ "msg": { "order_id": "<order_id>", "symbol": "ANN-457_BNB" }, "wallet_name": "wallet_1" }), req_wallet: WalletConfig = Depends(get_wallet), current_user: UserSettings = Depends(get_current_user), sync=True): """Sign and broadcast a cancel order message to the exchange """ assert_wallet_has_permission(req_wallet, WalletPermission.TRADE) assert_user_has_wallet_permission(current_user, cancel_order.wallet_name, WalletPermission.TRADE) # create the message msg = CancelOrderMsg(wallet=req_wallet.wallet, **cancel_order.msg.dict()) log_broadcast_transaction(current_user, req_wallet, msg) background_tasks.add_task(increment_wallet_sequence) return await req_wallet.broadcast_msg(msg.to_hex_data(), sync=sync)
async def sign_cancel_order( cancel_order: SignCancelOrderSchema = Body( ..., example={ "msg": { "order_id": "<order_id>", "symbol": "ANN-457_BNB" }, "wallet_name": "wallet_1" }), req_wallet: WalletConfig = Depends(get_wallet), current_user: UserSettings = Depends(get_current_user)): """Sign a cancel order message, returning the hex data """ assert_wallet_has_permission(req_wallet, WalletPermission.TRADE) assert_user_has_wallet_permission(current_user, cancel_order.wallet_name, WalletPermission.TRADE) # create the message msg = CancelOrderMsg(wallet=req_wallet.wallet, **cancel_order.msg.dict()) log_sign_transaction(current_user, req_wallet, msg) return {'signed_msg': msg.to_hex_data()}
async def broadcast_cancel_order( cancel_order: SignCancelOrderSchema, background_tasks: BackgroundTasks, req_wallet: WalletConfig = Depends(get_wallet), current_user: UserSettings = Depends(get_current_user), sync=True): """Sign and broadcast a cancel order message to the exchange """ if not req_wallet.has_permission(WalletPermission.TRADE): raise HTTPException(status_code=403, detail=f"No permission {WalletPermission.TRADE}") # check user has permission for this wallet if not user_has_wallet_permission(current_user, cancel_order.wallet_name, WalletPermission.TRADE): raise HTTPException( status_code=403, detail= f"User has no permission {WalletPermission.TRADE} on wallet {cancel_order.wallet_name}" ) # create the message msg = CancelOrderMsg(wallet=req_wallet.wallet, **cancel_order.msg.dict()) background_tasks.add_task(increment_wallet_sequence) return await req_wallet.broadcast_msg(msg.to_hex_data(), sync=sync)
def test_cancel_order_message_dict(self, wallet): wallet._account_number = 23452 wallet._sequence = 2 symbol = 'ANN-457_BNB' order_id = '7F756B1BE93AA2E2FDC3D7CB713ABC206F877802-3' msg = CancelOrderMsg(wallet=wallet, symbol=symbol, order_id=order_id) expected = OrderedDict([ ('refid', order_id), ('sender', wallet.address), ('symbol', symbol), ]) assert msg.to_dict() == expected
def test_cancel_order_message_hex(self, wallet): wallet._account_number = 23452 wallet._sequence = 2 symbol = 'ANN-457_BNB' order_id = '7F756B1BE93AA2E2FDC3D7CB713ABC206F877802-3' msg = CancelOrderMsg(wallet=wallet, symbol=symbol, order_id=order_id) expected = ( b'cd01f0625dee0a53166e681b0a147f756b1be93aa2e2fdc3d7cb713abc206f877802120b414e4e2d3435375f424e4' b'21a2a374637353642314245393341413245324644433344374342373133414243323036463837373830322d331270' b'0a26eb5ae9872102cce2ee4e37dc8c65d6445c966faf31ebfe578a90695138947ee7cab8ae9a2c08124085c6fb270' b'de3e614b025a68c0ff0f3af0fb6667e4ddf7a52b2e182bbf049bcb16151b4766b77ad1d00beb597dde432321f320a' b'e3b7446e4e8abce07257c83049189cb70120022001') assert msg.to_hex_data() == expected
def cancel_order(self, order_id): cancel_order_msg = CancelOrderMsg( wallet=self.wallet, order_id=order_id, symbol=self.symbol, ) res = self.broadcast_transaction(cancel_order_msg, sync=True) print(res) return res
def test_cancel_order_message_hex(self, wallet): wallet._account_number = 23452 wallet._sequence = 2 symbol = 'ANN-457_BNB' order_id = '7F756B1BE93AA2E2FDC3D7CB713ABC206F877802-3' msg = CancelOrderMsg(wallet=wallet, symbol=symbol, order_id=order_id) print(msg.to_hex_data()) expected = ( b'cb01f0625dee0a53166e681b0a147f756b1be93aa2e2fdc3d7cb713abc206f877802120b414e4e2d3435375f424e' b'421a2a374637353642314245393341413245324644433344374342373133414243323036463837373830322d3312' b'700a26eb5ae9872102cce2ee4e37dc8c65d6445c966faf31ebfe578a90695138947ee7cab8ae9a2c08124031640a' b'1f18daef6a36aeef358ebe559ae34b97c73947915abad91b5c244426ce1130b0425c73d6ebdc7720e2c48613d8e8' b'26a7434e3899e317543f25bf6f63c1189cb7012002') assert msg.to_hex_data() == expected
async def sign_cancel_order( cancel_order: SignCancelOrderSchema, req_wallet: WalletConfig = Depends(get_wallet), current_user: UserSettings = Depends(get_current_user)): """Sign a cancel order message, returning the hex data """ if not req_wallet.has_permission(WalletPermission.TRADE): raise HTTPException(status_code=403, detail=f"No permission {WalletPermission.TRADE}") # check user has permission for this wallet if not user_has_wallet_permission(current_user, cancel_order.wallet_name, WalletPermission.TRADE): raise HTTPException( status_code=403, detail= f"User has no permission {WalletPermission.TRADE} on wallet {cancel_order.wallet_name}" ) # create the message msg = CancelOrderMsg(wallet=req_wallet.wallet, **cancel_order.msg.dict()) return {'signed_msg': msg.to_hex_data()}