def get_orders(symbol):
    trade_client = TradeClient(api_key=g_api_key, secret_key=g_secret_key)
    list_obj = trade_client.get_orders(symbol=symbol, order_state=OrderState.SUBMITTED,
                                    order_type=None, start_date=None, end_date=None,
                                   start_id=None, size=None, direct=QueryDirection.PREV)
                                    #order_type=OrderType.BUY_LIMIT, start_date=None, end_date=None,

    LogInfo.output("===== {symbol} {count} orders found".format(symbol=symbol, count=len(list_obj)))
    if len(list_obj):
        LogInfo.output_list(list_obj)
def get_orders_id_list(symbol):
    try:
        trade_client = TradeClient(api_key=g_api_key, secret_key=g_secret_key)
        list_obj = trade_client.get_orders(symbol=symbol, order_state=OrderState.SUBMITTED,
                                        order_type=None, start_date=None, end_date=None,
                                    start_id=None, size=None, direct=QueryDirection.PREV)
        order_id_list = []
        if len(list_obj):
            a = __Autonomy__()
            current = sys.stdout
            sys.stdout = a
            LogInfo.output_list(list_obj)
            sys.stdout = current
            order_id_list = get_value("Order Id", a._buff)
    except:
        print("ExecuteError")

    return order_id_list
Exemple #3
0
def get_orders(symbols):
    try:
        trade_client = TradeClient(api_key=g_api_key, secret_key=g_secret_key)
        for symbol in symbols:
            list_obj = trade_client.get_orders(
                symbol=symbol,
                order_state=OrderState.SUBMITTED,
                order_type=None,
                start_date=None,
                end_date=None,
                start_id=None,
                size=None,
                direct=QueryDirection.PREV)

            LogInfo.output(" {symbol} {count} orders found".format(
                symbol=symbol, count=len(list_obj)))
            if len(list_obj):
                LogInfo.output_list(list_obj)

    except:
        print("ExecuteError")
Exemple #4
0
def has_buy_order(symbol, buy_price, sell_price, check_partial):
    try:
        trade_client = TradeClient(api_key=g_api_key, secret_key=g_secret_key)
        list_obj = trade_client.get_orders(symbol=symbol,
                                           order_state=OrderState.SUBMITTED,
                                           order_type=None,
                                           start_date=None,
                                           end_date=None,
                                           start_id=None,
                                           size=None,
                                           direct=QueryDirection.PREV)
        count = len(list_obj)
        order_type = []
        for obj in list_obj:
            a = __Autonomy__()
            current = sys.stdout
            sys.stdout = a
            obj.print_object()
            sys.stdout = current
            order_type = get_value("Order Type", a._buff)
            price = get_value("Price", a._buff)
            current_price = float(price[0])
            if (order_type[0] == "buy-limit"):
                if current_price == buy_price:
                    return True, True
            else:
                if current_price == sell_price:
                    return True, False
    except:
        print("ExecuteError")

    if check_partial:
        try:
            list_obj = trade_client.get_orders(
                symbol=symbol,
                order_state=OrderState.PARTIAL_FILLED,
                order_type=None,
                start_date=None,
                end_date=None,
                start_id=None,
                size=None,
                direct=QueryDirection.PREV)
            count = len(list_obj)
            order_type = []
            for obj in list_obj:
                a = __Autonomy__()
                current = sys.stdout
                sys.stdout = a
                obj.print_object()
                sys.stdout = current
                order_type = get_value("Order Type", a._buff)
                price = get_value("Price", a._buff)
                current_price = float(price[0])
                if (order_type[0] == "buy-limit"):
                    if current_price == buy_price:
                        return True, True
                else:
                    if current_price == sell_price:
                        return True, False
        except:
            print("ExecuteError")
    return False, False
Exemple #5
0
    def test_trade_order(self):
        trade_client = TradeClient(api_key=g_api_key,
                                   secret_key=g_secret_key,
                                   performance_test=True)

        client_order_id = "test_" + str(round(time.time())) + "_id"
        print("client order id : ", client_order_id)
        # case create_order
        tc = TimeCost(function_name=trade_client.create_order.__name__)
        result, tc.server_req_cost, tc.server_api_cost = trade_client.order_id = trade_client.create_order(
            symbol=trade_symbol,
            account_id=g_account_id,
            order_type=OrderType.BUY_LIMIT,
            source=OrderSource.API,
            amount=55,
            price=0.1,
            client_order_id=client_order_id,
            stop_price=0.08,
            operator="gte")
        order_id_tmp = result
        tc.run_status = RunStatus.SUCCESS if result else RunStatus.FAILED
        tc.add_record()

        # case get_order
        tc = TimeCost(function_name=trade_client.get_order.__name__)
        result, tc.server_req_cost, tc.server_api_cost = trade_client.order_id = trade_client.get_order(
            order_id=order_id_tmp)
        tc.run_status = RunStatus.SUCCESS if result else RunStatus.FAILED
        tc.add_record()

        # case get_order_by_client_order_id
        tc = TimeCost(
            function_name=trade_client.get_order_by_client_order_id.__name__)
        result, tc.server_req_cost, tc.server_api_cost = trade_client.order_id = trade_client.get_order_by_client_order_id(
            client_order_id=client_order_id)
        tc.run_status = RunStatus.SUCCESS if result else RunStatus.FAILED
        tc.add_record()

        # case get_open_orders
        tc = TimeCost(function_name=trade_client.get_open_orders.__name__)
        result, tc.server_req_cost, tc.server_api_cost = trade_client.order_id = trade_client.get_open_orders(
            symbol=trade_symbol, account_id=g_account_id)
        tc.run_status = RunStatus.SUCCESS if result and len(
            result) else RunStatus.FAILED
        tc.add_record()

        # case get_orders
        tc = TimeCost(function_name=trade_client.get_orders.__name__)
        result, tc.server_req_cost, tc.server_api_cost = trade_client.order_id = trade_client.get_orders(
            symbol=trade_symbol,
            order_type=OrderType.BUY_LIMIT,
            order_state=OrderState.SUBMITTED)
        tc.run_status = RunStatus.SUCCESS if result and len(
            result) else RunStatus.FAILED
        tc.add_record()

        # case cancel_order
        tc = TimeCost(function_name=trade_client.cancel_order.__name__)
        result, tc.server_req_cost, tc.server_api_cost = trade_client.order_id = trade_client.cancel_order(
            symbol=trade_symbol, order_id=order_id_tmp)
        tc.run_status = RunStatus.SUCCESS if result else RunStatus.FAILED
        tc.add_record()
from huobi.client.trade import TradeClient
from huobi.constant import *
from huobi.utils import *

symbol = "htusdt"
trade_client = TradeClient(api_key=g_api_key, secret_key=g_secret_key)
list_obj = trade_client.get_orders(symbol=symbol,
                                   order_state=OrderState.FILLED,
                                   order_type=OrderType.BUY_LIMIT,
                                   start_date=None,
                                   end_date=None,
                                   start_id=None,
                                   size=None,
                                   direct=QueryDirection.PREV)

LogInfo.output("===== step 1 ==== {symbol} {count} orders found".format(
    symbol=symbol, count=len(list_obj)))
LogInfo.output_list(list_obj)

symbol = "eosusdt"
list_obj = trade_client.get_orders(symbol=symbol,
                                   order_state=OrderState.CANCELED,
                                   order_type=OrderType.BUY_LIMIT,
                                   start_date="2020-05-21",
                                   end_date=None,
                                   start_id=None,
                                   size=None,
                                   direct=QueryDirection.PREV)
LogInfo.output(
    "===== step 2 ==== {symbol} {count} canceled buy limit orders found".
    format(symbol=symbol, count=len(list_obj)))
Exemple #7
0
            if float(balance_obj.balance
                     ) > 0.01 and balance_obj.currency not in hb_iglist:
                hb_balance[balance_obj.currency] = float(
                    balance_obj.balance
                ) if balance_obj.currency not in hb_balance else hb_balance[
                    balance_obj.currency] + float(balance_obj.balance)

    trade_client = TradeClient(api_key=hb_api_key, secret_key=hb_secret_key)
    for symbol, bcount in hb_balance.items():
        x, order_bcount = 0, 0
        hb_border = []
        while abs(order_bcount - bcount) > 0.1 and x < 30:
            list_obj = trade_client.get_orders(
                symbol=f'{symbol}usdt',
                start_date=(datetime.now() -
                            timedelta(days=2 * x + 1)).strftime('%Y-%m-%d'),
                end_date=(datetime.now() -
                          timedelta(days=2 * x)).strftime('%Y-%m-%d'),
                order_state="partial-filled,filled,partial-canceled")
            if len(list_obj) != 0:
                for order in list_obj:
                    hb_border.append({
                        "orderId":
                        order.id,
                        "price":
                        order.price,
                        "executedQty":
                        order.filled_amount,
                        "cummulativeQuoteQty":
                        order.filled_cash_amount,
                        "side":
Exemple #8
0
#!/usr/bin/python3

from huobi.client.trade import TradeClient
from huobi.constant import *
from huobi.utils import *

trade_client = TradeClient(api_key=g_api_key, secret_key=g_secret_key)
symbol = "eth3lusdt"
list_obj = trade_client.get_orders(symbol=symbol,
                                   order_state=OrderState.SUBMITTED,
                                   order_type=OrderType.BUY_LIMIT,
                                   start_date=None,
                                   end_date=None,
                                   start_id=None,
                                   size=None,
                                   direct=QueryDirection.PREV)

LogInfo.output("===== step 1 ==== {symbol} {count} orders found".format(
    symbol=symbol, count=len(list_obj)))
if len(list_obj):
    LogInfo.output_list(list_obj)