Example #1
0
def _hide_order(order: QuerySet):
    """
    Changes order visiblity to False.
    """
    order.is_displayed = False
    order.save()

    return 1
Example #2
0
def swap_token_on_uniswap(
    order: QuerySet,
    input_token: AddressLike,
    output_token: AddressLike,
    qty: Union[int, Wei],
    recipient: AddressLike = None,
) -> HexBytes:
    """
    Make a trade by defining the qty of the output token.
    Input is address of swapped tokens and exact amount of output token.
    """
    # TODO: now it works only for ETH->TOKEN and TOKEN->ETH swaps
    #  needed to add TOKEN->TOKEN swap ability
    if not is_approved(RUBIC_ADDRESS):
        approve(RUBIC_ADDRESS)
    # ---

    if input_token == w3.toChecksumAddress(ETH_ADDRESS):
        logging.info('if input token is native ETH')
        balance = get_eth_balance(WALLET_ADDRESS)
        logging.info('balance')
        need = get_eth_token_output_price(token_address=output_token,
                                          quantity_in_wei=qty)
        logging.info("balance: {}\nneed: {}".format(balance, need))

        if balance < need:
            logging.info('balance < need is TRUE')
            # TODO: add logging "not enough eth token"
            pass
        else:
            logging.info('balance < need is FALSE')

            eth_to_token_swap_output(output_token, qty, recipient)

            order.swaped_on_uniswap = True
            order.save()

            return 1

    elif output_token == w3.toChecksumAddress(ETH_ADDRESS):
        logging.info('if output token is ETH token')
        # balance = get_rbc_balance(WALLET_ADDRESS)
        # need = get_token_eth_output_price(output_token, qty)
        # if balance < need:
        #     # TODO: add logging "not enough eth token"
        #     pass
        # else:
        qty = Wei(qty)

        token_to_eth_swap_output(input_token, qty)

        order.swaped_on_uniswap = True
        order.save()

        return 1

    return 0
Example #3
0
def _set_done_status_order(order: QuerySet):
    """
    Changes order visibility to True and state to 'done'.
    # TODO: done by order limiter
    """
    order.state = OrderBookSwaps.STATE_DONE
    order.is_closed_by_limiter = True
    order.is_displayed = True
    order.save()

    return 1