Esempio n. 1
0
def callback(upd_event: 'OrderUpdateEvent'):
    print("---- order update : ----")
    #upd_event.print_object()

    try:
        b = __Autonomy__()
        current = sys.stdout
        sys.stdout = b
        upd_event.print_object()
        sys.stdout = current

        order_type = get_value("Order Type", b._buff)
        price = get_value("Trade Price", b._buff)
        order_state = get_value("Order State", b._buff)
        order_symbol = get_value("Symbol", b._buff)
        order_id = get_value("Order Id", b._buff)
        amount = get_value("Trade Volume", b._buff)

        order_type = get_first_value(order_type)
        order_state = get_first_value(order_state)
        order_symbol = get_first_value(order_symbol)
        price = get_first_value(price)
        price = price if price == "" else float(price)
        order_id = int(get_first_value(order_id))
        amount = get_first_value(amount)
        amount = amount if amount == "" else float(amount)

        print(b._buff)

        if order_type == "sell-limit":
            order_type = "sell"
        elif order_type == "buy-limit":
            order_type = "buy"

        if order_state == "filled":
            order_state = "done"
        elif order_state == "partial-filled":
            order_state = "part done"

        if price or amount:
            order_info = "%s, %s, price=%s, Volume=%s" % (
                order_type, order_state, price, amount)
        else:
            order_info = "%s, %s" % (order_type, order_state)

        print(order_info)

        current = sys.stdout
        a = __Autonomy__()
        sys.stdout = a
        print(b._buff)
        print("\n===== check SUBMITTED order =====\n")
        get_orders(order_symbol)

        sys.stdout = current

        send_email("HB: " + order_info, a._buff)
    except Exception as e:
        print("callback ExecuteError", e)
Esempio n. 2
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)
            order_id = get_value("Order Id", a._buff)
            amount = get_value("Amount", 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,int(order_id[0]),float(amount[0])
            else:
                if current_price == sell_price:
                    return True,False,int(order_id[0]),float(amount[0])
    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)
                order_id = get_value("Order Id", a._buff)
                amount = get_value("Amount", 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,int(order_id[0]),float(amount[0])
                else:
                    if current_price == sell_price:
                        return True,False,int(order_id[0]),float(amount[0])
        except:
            print("ExecuteError")
    return False,False,0,0
Esempio n. 3
0
def get_eth3l_trade_balance():
    account_id = 23455585
    account_client = AccountClient(api_key=g_api_key, secret_key=g_secret_key)
    list_obj = account_client.get_balance(account_id=account_id)
    for balance_obj in list_obj:
        if float(balance_obj.balance) > 0.1:  # only show account with balance
            order_type = []
            a = __Autonomy__()
            current = sys.stdout
            sys.stdout = a
            balance_obj.print_object("\t")
            sys.stdout = current
            order_type = get_value("eth3l", a._buff)
            if order_type:
                #print(order_type)
                #print(a._buff)
                order_type = get_value("trade", a._buff)
                if order_type:
                    #print(order_type)
                    #print(a._buff)
                    order_type = get_value("Balance", a._buff)
                    if order_type:
                        #print(order_type[1])
                        return order_type[1]
    return 0.0
Esempio n. 4
0
def get_usdt_trade_balance():
    try:
        account_client = AccountClient(api_key=g_api_key,
                                       secret_key=g_secret_key)
        list_obj = account_client.get_balance(account_id=account_id)
        for balance_obj in list_obj:
            if float(balance_obj.balance
                     ) > 0.1:  # only show account with balance
                order_type = []
                a = __Autonomy__()
                current = sys.stdout
                sys.stdout = a
                balance_obj.print_object("\t")
                sys.stdout = current
                order_type = get_value("usdt", a._buff)
                if order_type:
                    #print(order_type)
                    #print(a._buff)
                    order_type = get_value("trade", a._buff)
                    if order_type:
                        #print(order_type)
                        #print(a._buff)
                        order_type = get_value("Balance", a._buff)
                        if order_type:
                            #print(order_type[1])
                            return order_type[1]
    except:
        print("ExecuteError:", inspect.stack()[1][4])
    return 0.0
Esempio n. 5
0
def handle_order_update(upd_event: 'OrderUpdateEvent'):
    try:
        print("handle order update now...")
        b = __Autonomy__()
        current = sys.stdout
        sys.stdout = b
        upd_event.print_object()
        sys.stdout = current

        order_type = get_value("Order Type", b._buff)
        order_id = get_value("Order Id", b._buff)
        price = get_value("Trade Price", b._buff)
        order_state = get_value("Order State", b._buff)
        amount = get_value("Trade Volume", b._buff)

        if get_first_value(order_state) != "filled":
            return

        order_type = get_first_value(order_type)
        order_state = get_first_value(order_state)
        price = float(get_first_value(price))
        order_id = int(get_first_value(order_id))
        amount = float(get_first_value(amount))

        print("order_state=", order_state)
        print("order_type=", order_type)
        print("price=", price)
        print("order_id=", order_id)
        print("amount=", amount)

        handle_order_id(order_id, order_type, price)

    except Exception as e:
        print("ExecuteError in handle_order_update", e)
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
Esempio n. 7
0
def handle_order_update(upd_event: 'OrderUpdateEvent'):
    print("handle order update now...")
    b = __Autonomy__()
    current = sys.stdout
    sys.stdout = b
    upd_event.print_object()
    sys.stdout = current

    order_type = get_value("Order Type", b._buff)
    order_id = get_value("Order Id", b._buff)
    price = get_value("Trade Price", b._buff)
    order_state = get_value("Order State", b._buff)
    amount = get_value("Trade Volume", b._buff)

    o_state = get_first_value(order_state)
    if o_state == "partial-filled":
        partial_filled_flag = True
        return
    elif o_state != "filled":
        return

    order_type = get_first_value(order_type)
    order_state = get_first_value(order_state)
    price = float(get_first_value(price))
    order_id = int(get_first_value(order_id))
    amount = float(get_first_value(amount))

    print("order_state=", order_state)
    print("order_type=", order_type)
    print("price=", price)
    print("order_id=", order_id)
    print("amount=", amount)

    handle_order_id(order_id, order_type, price)

    update_order_implement("Event")
Esempio n. 8
0
def callback(upd_event: 'OrderUpdateEvent'):
    print("---- order update : ----")
    #upd_event.print_object()

    try:
        b = __Autonomy__()
        current = sys.stdout
        sys.stdout = b
        upd_event.print_object()
        sys.stdout = current

        order_type = get_value("Order Type", b._buff)
        price = get_value("Trade Price", b._buff)
        order_state = get_value("Order State", b._buff)
        amount = get_value("Trade Volume", b._buff)

        if len(order_type):
            order_type = order_type[0]
        else:
            order_type = ""
        if len(order_state):
            order_state = order_state[0]
        else:
            order_state = ""
        if len(price):
            price = price[0]
        else:
            price = ""
        if len(amount):
            amount = amount[0]
        else:
            amount = ""

        print(b._buff)

        if order_type == "sell-limit":
            order_type = "sell"
        elif order_type == "buy-limit":
            order_type = "buy"

        if order_state == "filled":
            order_state = "done"
        elif order_state == "partial-filled":
            order_state = "part done"

        if price or amount:
            order_info = "%s, %s, price=%s, Volume=%s" % (
                order_type, order_state, price, amount)
        else:
            order_info = "%s, %s" % (order_type, order_state)

        print(order_info)

        current = sys.stdout
        a = __Autonomy__()
        sys.stdout = a
        print(b._buff)
        print("\n===== check SUBMITTED order =====\n")
        get_orders(['eth3lusdt', 'dogeusdt', 'ethusdt'])
        sys.stdout = current

        if order_type == "sell" and order_state != "submitted" and order_state != "canceled":
            send_email("HB: " + order_info, a._buff)

        elif order_type == "buy" and order_state != "submitted" and order_state != "canceled":
            send_email("HB: " + order_info, a._buff)

        print()
    except:
        print("ExecuteError")