Ejemplo n.º 1
0
    def broadcast_msg(self,
                      msg: binance_chain.messages.Msg,
                      sync: bool = False):
        """Broadcast a message

        https://binance-chain.github.io/api-reference/dex-api/paths.html#apiv1broadcast

        :param msg: Type of NewOrderMsg, CancelOrderMsg, FreezeMsg, UnfreezeMsg
        :param sync: Synchronous broadcast (wait for DeliverTx)?

        .. code:: python

            # new order example
            # construct the message
            new_order_msg = NewOrderMsg(
                wallet=wallet,
                symbol="ANN-457_BNB",
                time_in_force=TimeInForce.GTE,
                order_type=OrderType.LIMIT,
                side=OrderSide.BUY,
                price=Decimal(0.000396000),
                quantity=Decimal(12)
            )
            # then broadcast it
            res = client.broadcast_msg(new_order_msg, sync=True)

            # cancel order example
            cancel_order_msg = CancelOrderMsg(
                wallet=wallet,
                order_id="09F8B32D33CBE2B546088620CBEBC1FF80F9BE001ACF42762B0BBFF0A729CE3",
                symbol='ANN-457_BNB',
            )
            res = client.broadcast_msg(cancel_order_msg, sync=True)

        :return: API Response

        """

        # fetch account detail
        # account = self.get_account(self.msg.wallet.address)

        if self._env != msg.wallet.env:
            raise BinanceChainBroadcastException(
                "Wallet environment doesn't match HttpApiClient environment")

        msg.wallet.initialise_wallet()
        data = msg.to_hex_data()

        logging.debug(f'data:{data}')

        req_path = 'broadcast'
        if sync:
            req_path += f'?sync=1'

        res = self._post(req_path, data=data)
        msg.wallet.increment_account_sequence()
        return res
Ejemplo n.º 2
0
    async def broadcast_msg(self, msg: binance_chain.messages.Msg, sync: bool = False):
        # fetch account detail
        # account = self.get_account(self.msg.wallet.address)

        if self._env != msg.wallet.env:
            raise BinanceChainBroadcastException("Wallet environment doesn't match HttpApiClient environment")

        msg.wallet.initialise_wallet()
        data = msg.to_hex_data()

        logging.debug(f'data:{data}')

        req_path = 'broadcast'
        if sync:
            req_path += f'?sync=1'

        res = await self._post(req_path, data=data)
        msg.wallet.increment_account_sequence()
        return res