Пример #1
0
def get_coin_balance(coin):
    balance = HuobiService.get_balance()
    result = 0
    for e in balance["data"]["list"]:
        if e["type"] == "trade" and e["currency"] == coin:
            # result = float(int(float(e["balance"]) * 10000)) / 10000
            result = common_utils.get_round(float(e["balance"]), 4)
        if result:
            # 获取到想要的值, 跳出循环
            break
    return result
Пример #2
0
def get_coin_balance(coin):
    if not is_debug:
        # 正式请求
        balance = HuobiService.get_balance()
        if balance['status'] == 'ok':
            result = 0
            for e in balance["data"]["list"]:
                if e["type"] == "trade" and e["currency"] == coin:
                    # result = float(int(float(e["balance"]) * 10000)) / 10000
                    result = common_utils.get_round(float(e["balance"]), 2)
                if result:
                    # 获取到想要的值, 跳出循环
                    break
            return result
        else:
            time.sleep(2)
            # 第一次请求失败, 再试一次
            balance = HuobiService.get_balance()
            if balance['status'] == 'ok':
                result = 0
                for e in balance["data"]["list"]:
                    if e["type"] == "trade" and e["currency"] == coin:
                        # result = float(int(float(e["balance"]) * 10000)) / 10000
                        result = common_utils.get_round(float(e["balance"]), 2)
                    if result:
                        # 获取到想要的值, 跳出循环
                        break
                return result
            else:
                # 第二次还失败, 这里停掉程序
                return -100
    else:
        # 测试模式, 设置 回测的数据
        json_count = common_utils.read_json("debug_count.json")
        if "soc" == coin:
            return json_count['soc_count']
        if "wicc" == coin:
            return json_count['wicc_count']
        return -100
Пример #3
0
def get_soc_wicc_balance():
    balance = HuobiService.get_balance()
    soc_balance = 0
    wicc_balance = 0
    for e in balance["data"]["list"]:
        if e["type"] == "trade" and e["currency"] == "soc":
            soc_balance = int(float(e["balance"]))
        if e["type"] == "trade" and e["currency"] == "wicc":
            wicc_balance = int(float(e["balance"]))
        if soc_balance and wicc_balance:
            break
    j_balance = common_utils.get_json(balance, map)
    # print j_balance
    print "soc_balance = %s; wicc_balance = %s" % (str(soc_balance),
                                                   str(wicc_balance))
Пример #4
0
def get_balance():
    if not DEBUG:
        return HuobiService.get_balance()['data']['list']
    else:
        return {'usdt': {'type': 'trace', 'balance': 10000.0}}