Пример #1
0
def is_order_present_in_order_history(pg_conn, trade, table_name="arbitrage_orders"):
    """
                We can execute history retrieval several times.
                Some exchanges do not have precise mechanism to exclude particular time range.
                It is possible to have multiple trades per order = order_id.
                As this is arbitrage it mean that all other fields may be the same.
                exchange_id | trade_type | pair_id |   price   |  volume    |   order_id | timest

                executed_volume

    :param pg_conn:
    :param trade:
    :param table_name:
    :return:
    """

    select_query = """select arbitrage_id, exchange_id, trade_type, pair_id, price, volume, executed_volume, order_id,
        trade_id, order_book_time, create_time, execute_time from {table_name} where order_id = '{order_id}'""".format(
        table_name=table_name, order_id=trade.order_id)

    cursor = pg_conn.cursor

    cursor.execute(select_query)

    for row in cursor:
        cur_trade = Trade.from_row(row)
        if abs(cur_trade.executed_volume - trade.executed_volume) < 0.0000001 and \
                cur_trade.create_time == trade.create_time:
            return True

    return False
Пример #2
0
def get_last_binance_trade(pg_conn, start_date, end_time, pair_id, table_name="arbitrage_trades"):

    select_query = """select arbitrage_id, exchange_id, trade_type, pair_id, price, volume, executed_volume, order_id,
    trade_id, order_book_time, create_time, execute_time from {table_name} where exchange_id = {exchange_id} and
    pair_id = {pair_id} and create_time >= {start_time} and create_time <= {end_time}
    ORDER BY create_time DESC limit 1""".format(
        table_name=table_name, exchange_id=EXCHANGE.BINANCE, pair_id=pair_id, start_time=start_date, end_time=end_time)

    cursor = pg_conn.cursor

    cursor.execute(select_query)

    for row in cursor:
        return Trade.from_row(row)

    return None
Пример #3
0
def get_all_orders(pg_conn, table_name="arbitrage_orders", time_start=START_OF_TIME, time_end=START_OF_TIME):
    orders = []

    if time_start == START_OF_TIME and time_end == START_OF_TIME:
        select_query = """select arbitrage_id, exchange_id, trade_type, pair_id, price, volume, executed_volume,
        order_id, trade_id, order_book_time, create_time, execute_time from {table_name}""".format(table_name=table_name)
    else:
        select_query = """select arbitrage_id, exchange_id, trade_type, pair_id, price, volume, executed_volume,
        order_id, trade_id, order_book_time, create_time, execute_time from {table_name} where create_time >= {start_time}
        and create_time <= {end_time}
        """.format(table_name=table_name, start_time=time_start, end_time=time_end)

    cursor = pg_conn.cursor

    cursor.execute(select_query)

    for row in cursor:
        orders.append(Trade.from_row(row))

    return orders