Пример #1
0
    def __init__(self,
                 symbol: str,
                 time_in_force: TimeInForce,
                 order_type: OrderType,
                 side: OrderSide,
                 price: Union[int, float, Decimal],
                 quantity: Union[int, float, Decimal],
                 wallet: Optional[BaseWallet] = None):
        """NewOrder transaction creates a new order to buy and sell tokens on Binance DEX.

        :param symbol: symbol for trading pair in full name of the tokens e.g. 'ANN-457_BNB'
        :param time_in_force: TimeInForce type (GOOD_TILL_EXPIRE, IMMEDIATE_OR_CANCEL)
        :param order_type: OrderType (LIMIT, MARKET)
        :param side: OrderSide (BUY, SELL)
        :param price: price of the order e.g. Decimal(0.000396000) or 0.002384
        :param quantity: quantity of the order Decimal(12) or 12

        """
        super().__init__(wallet)
        self._symbol = symbol
        self._time_in_force = time_in_force.value
        self._order_type = order_type.value
        self._side = side.value
        self._price = price
        self._price_encoded = encode_number(price)
        self._quantity = quantity
        self._quantity_encoded = encode_number(quantity)
Пример #2
0
 def to_dict(self):
     return OrderedDict([
         ('inputs', [
             OrderedDict([
                 ('address', self._from_address),
                 ('coins', [
                     OrderedDict([
                         ('amount', encode_number(transfer.amount)),
                         ('denom', transfer.symbol)
                     ]) for transfer in self._transfers
                 ])
             ])
         ]),
         ('outputs', [
             OrderedDict([
                 ('address', self._to_address),
                 ('coins', [
                     OrderedDict([
                         ('amount', encode_number(transfer.amount)),
                         ('denom', transfer.symbol)
                     ]) for transfer in self._transfers
                 ])
             ])
         ])
     ])
Пример #3
0
    def __init__(self, wallet: Wallet, symbol: str, amount: Union[int, float, Decimal]):
        """Turn the amount of frozen tokens back to free state.

        :param symbol: token symbol, in full name with "-" suffix
        :param amount: amount of token to unfreeze
        """
        super().__init__(wallet)
        self._symbol = symbol
        self._amount = encode_number(amount)
Пример #4
0
    def __init__(self, wallet: Wallet, symbol: str, amount: Union[int, float, Decimal]):
        """Freeze transaction moves the amount of the tokens into a frozen state,
        in which it cannot be used to transfer or send new orders.

        :param symbol: token symbol, in full name with "-" suffix
        :param amount: amount of token to freeze
        """
        super().__init__(wallet)
        self._symbol = symbol
        self._amount = encode_number(amount)
Пример #5
0
    def __init__(self, wallet: Wallet, symbol: str, time_in_force: TimeInForce, order_type: OrderType, side: OrderSide,
                 price: Union[int, float, Decimal], quantity: Union[int, float, Decimal]):
        """NewOrder transaction creates a new order to buy and sell tokens on Binance DEX.

        :param symbol: symbol for trading pair in full name of the tokens e.g. 'ANN-457_BNB'
        :param time_in_force: TimeInForce type (GOOD_TILL_EXPIRE, IMMEDIATE_OR_CANCEL)
        :param order_type: OrderType (LIMIT, MARKET)
        :param side: OrderSide (BUY, SELL)
        :param price: price of the order e.g. Decimal(0.000396000) or 0.002384
        :param quantity: quantity of the order Decimal(12) or 12

        """
        super().__init__(wallet)
        self._symbol = symbol
        self._time_in_force = NewOrderMsg.TIME_IN_FORCE_INT[time_in_force]
        self._order_type = NewOrderMsg.ORDER_TYPE_INT[order_type]
        self._side = NewOrderMsg.ORDER_SIDE_INT[side]
        self._price = encode_number(price)
        self._quantity = encode_number(quantity)
Пример #6
0
    def __init__(self, proposal_id: int, vote_option: VoteOption,
                 wallet: Optional[BaseWallet] = None):
        """Place a vote for a proposal from the given wallet address.

        :param proposal_id: ID of the proposal
        :param vote_option: option chosen by the voter
        """
        super().__init__(wallet)
        self._proposal_id = proposal_id
        self._proposal_id_amino = encode_number(proposal_id)
        self._voter = wallet.address if wallet else None
        self._vote_option = vote_option
Пример #7
0
    def __init__(self, wallet: Wallet, symbol: str, amount: Union[int, float, Decimal],
                 from_address: str, to_address: str):
        """Transferring funds between different addresses.

        :param symbol: token symbol, in full name with "-" suffix
        :param amount: amount of token to freeze
        :param from_address: amount of token to freeze
        :param to_address: amount of token to freeze
        """
        super().__init__(wallet)
        self._symbol = symbol
        self._amount = encode_number(amount)
        self._from_address = from_address
        self._to_address = to_address
Пример #8
0
    def to_protobuf(self) -> Send:
        input_addr = Input()
        output_addr = Output()
        for transfer in self._transfers:
            token = Token()
            token.denom = transfer.symbol
            token.amount = encode_number(transfer.amount)
            input_addr.coins.extend([token])
            output_addr.coins.extend([token])
        input_addr.address = decode_address(self._from_address)
        output_addr.address = decode_address(self._to_address)

        msg = Send()
        msg.inputs.extend([input_addr])
        msg.outputs.extend([output_addr])
        return msg
Пример #9
0
    def __init__(self,
                 symbol: str,
                 amount: Union[int, float, Decimal],
                 to_address: str,
                 wallet: Optional[Wallet] = None):
        """Transferring funds between different addresses.

        :param symbol: token symbol, in full name with "-" suffix
        :param amount: amount of token to freeze
        :param to_address: amount of token to freeze
        """
        super().__init__(wallet)
        self._symbol = symbol
        self._amount = amount
        self._amount_amino = encode_number(amount)
        self._from_address = wallet.address if wallet else None
        self._to_address = to_address
Пример #10
0
def test_encode_correct(num, expected):
    assert encode_number(num) == expected