Beispiel #1
0
def get_zb_balance(currency='BCC'):
    zb_api_temp = zb_api(get_chbtc_api_key(), get_chbtc_api_secret())
    account_info = zb_api_temp.query_account()
    for coin in account_info['result']['coins']:
        print "coin info = {}".format(coin)
        if coin['enName'] == currency:
            print "{} balance = {}".format(currency, coin['available'])
            return coin['available']
    return -1
Beispiel #2
0
def buyCHBTCBTC():
    zb_api_trading = zb_api(get_zb_api_key(), get_zb_api_secret())
    zb_bcc_market = zb_api_trading.query_market("bcc_cny")
    print zb_bcc_market
    last_bcc_price = -1
    if zb_bcc_market == "error":
        zb_bcc_price = last_bcc_price
    else:
        zb_bcc_price = zb_bcc_market["ticker"]["last"]
        last_bcc_price = zb_bcc_price
    if zb_bcc_price > 0:
        """TODO: need to sync amount from different exchanges"""
        zb_api_trading.buy_bcc_order(str(zb_bcc_price), str(0.01))
Beispiel #3
0
def sellCHBTCETC():
    zb_api_trading = zb_api(get_zb_api_key(), get_zb_api_secret())
    zb_usdt_market = zb_api_trading.query_market("usdt_cny")
    print zb_usdt_market
    last_usdt_price = -1
    if zb_usdt_market == "error":
        zb_usdt_price = last_usdt_price
    else:
        zb_usdt_price = zb_usdt_market["ticker"]["last"]
        last_usdt_price = zb_usdt_price
    if zb_usdt_price > 0:
        """TODO: need to sync amount from different exchanges"""
        zb_api_trading.sell_usdt_order(str(zb_usdt_price), str(1.0))
Beispiel #4
0
def get_zb_status():
    zb_api2 = zb_api(get_chbtc_api_key(), get_chbtc_api_secret())
    result = zb_api2.get_zb_withdraw_status('BCC')
    print result
Beispiel #5
0
def get_overview():
    global OP_COUNT

    global INIT_BCC_AMOUNT
    global INIT_USDT_AMOUNT
    global realtime_bcc_amount
    global realtime_usdt_amount
    """balances = Balances(trading_api.return_complete_balances())
    dw_history = DWHistory(trading_api.return_deposits_withdrawals())
    deposits, withdrawals = dw_history.get_dw_history()
    utils.print_dw_history(deposits, withdrawals)
    balance = dw_history.get_bcc_balance(public_api.return_ticker())
    current = balances.get_bcc_total()

    usd_bcc_price = return_usd_bcc()
    balance_percentage = float("{:.4}".format(current / balance * 100))
    bcc_balance_sum = current - balance
    usd_balance_sum = "{:.2f}".format(bcc_balance_sum * usd_bcc_price)
    """
    if realtime_bcc_amount == INIT_BCC_AMOUNT or realtime_bcc_amount == -1 or realtime_usdt_amount == INIT_USDT_AMOUNT or realtime_usdt_amount == -1:
        realtime_bcc_amount = get_zb_balance('BCC')
        realtime_usdt_amount = get_zb_balance('USDT')

    bcc_usdt_price = return_usd_bcc()
    print "bcc usdt price in poloniex ={}".format(bcc_usdt_price)

    count = 0
    last_bcc_price = -1
    record = open('log.txt', 'a')
    record.write("----------------------\n")
    record.write(time.ctime() + "\n")

    zb_api1 = zb_api(get_chbtc_api_key(), get_chbtc_api_secret())
    """zb_api1.query_account();"""
    zb_bcc_market = zb_api1.query_market("bcc_usdt")
    zb_bcc_orderBook = zb_api1.query_depth("bcc_usdt")
    """print zb_bcc_market;
    print zb_bcc_orderBook;"""
    if zb_bcc_market == "error":
        zb_bcc_price = last_bcc_price
    else:
        zb_bcc_price = float(zb_bcc_market["ticker"]["last"])
        last_bcc_price = zb_bcc_price

    orderBook = return_orderbook_usdt_bcc()
    bid_highest = orderBook["bids"][0]
    bid_price = float(bid_highest[0])
    bid_amount = float(bid_highest[1])
    ask_lowest = orderBook["asks"][0]
    ask_price = float(ask_lowest[0])
    ask_amount = float(ask_lowest[1])
    print "the highest bid price is {}, amount is {} ".format(
        bid_price, bid_amount)
    print "the lowest ask price is {}, amount is {}".format(
        ask_price, ask_amount)
    record.write("the highest bid price is {}, amount is {} \n ".format(
        bid_price, bid_amount))
    record.write("the lowest ask price is {}, amount is {} \n".format(
        ask_price, ask_amount))
    """print zb_bcc_price;"""

    record.write("BCC price in zb =" + str(zb_bcc_price) + "\n")
    record.write("POLONIEX BCC/USDT =" + str(bcc_usdt_price) + "\n")
    print("POLONIEX BCC/USDT =" + str(bcc_usdt_price))

    string_zb = "CHBCC BCC/USDT =" + str(zb_bcc_price)
    record.write(string_zb + "\n")
    print string_zb
    if (bcc_usdt_price > 0) and (zb_bcc_price > 0):
        delta = abs(zb_bcc_price - bcc_usdt_price)
        delta_percent = delta / bcc_usdt_price * 100
        print str(delta_percent) + "%"
        record.write("delta percent =" + str(delta_percent) + "%\n")
        if delta_percent > 1.5:
            print "here is a arbitrage opportunity!!!!"
            OP_COUNT = OP_COUNT + 1
            print "we have observed " + str(OP_COUNT) + " times opportunities"
            if zb_bcc_price > bcc_usdt_price:
                """we need to sell out bcc and buy usdt in zb 
                   then sell out usdt and buy bcc in poloniex """
                try:

                    zb_bcc_order_price = float(zb_bcc_orderBook["bids"][0][0])
                    zb_bcc_order_amount = float(zb_bcc_orderBook["bids"][0][1])
                    print "zb_bcc_bids_0_price ={}".format(zb_bcc_order_price)
                    """zb_bcc_order_price = float(zb_usdt_orderBook["asks"][9][0]);
                    zb_bcc_order_amount = float(zb_usdt_orderBook["asks"][9][1]);"""
                    double_check_percent = 100 * (zb_bcc_order_price -
                                                  ask_price) / ask_price
                    print "double check percent ={}".format(
                        double_check_percent)
                    if double_check_percent > 1.0:
                        bcc_trading_amount = min(ask_amount,
                                                 zb_bcc_order_amount, 1.00)
                        bcc_trading_amount = Decimal(
                            bcc_trading_amount).quantize(Decimal('0.0000'))
                        """
                        zb_api1.sell_bcc_order(zb_bcc_order_price, bcc_trading_amount);
                        buy_usdt_bcc(ask_price, bcc_trading_amount);
                        """
                        print "selling {} bcc in {} price in zb \n".format(
                            bcc_trading_amount, zb_bcc_order_price)
                        print "buying {} bcc in {} price in poloniex \n".format(
                            bcc_trading_amount, ask_price)

                        record.write(
                            "buying {} bcc in {} price in poloniex \n".format(
                                bcc_trading_amount, ask_price))
                        record.write(
                            "selling {} bcc in {} price in zb \n".format(
                                bcc_trading_amount, zb_bcc_order_price))
                        realtime_bcc_amount = realtime_bcc_amount - float(
                            bcc_trading_amount)
                        realtime_usdt_amount = realtime_usdt_amount + float(
                            bcc_trading_amount) * zb_bcc_order_price
                        print "realtime bcc in zb = {} \n".format(
                            realtime_bcc_amount)
                        print "realtime usdt in zb = {} \n".format(
                            realtime_usdt_amount)
                        if (realtime_bcc_amount < 0.1 * INIT_BCC_AMOUNT) or (
                                realtime_ustd_amount < 0.1 * INIT_USDT_AMOUNT):
                            withdraw_between_exchanges(
                                realtime_bcc_amount - INIT_BCC_AMOUNT,
                                realtime_usdt_amount - INIT_USDT_AMOUNT)

                    else:
                        print "it is a pity that double check percent is less than 1.0"
                except Exception, ex:
                    print 'zb cannel_order exception,{}'.format(ex)
            else:
                """we need to sell out usdt and buy bcc in zb 
                    then sell out bcc and buy usdt in poloniex """
                try:

                    zb_bcc_order_price = float(zb_bcc_orderBook["asks"][9][0])
                    zb_bcc_order_amount = float(zb_bcc_orderBook["asks"][9][1])
                    print "zb_bcc_asks_9_price = {}".format(zb_bcc_order_price)
                    """zb_usdt_order_price = float(zb_usdt_orderBook["bids"][0][0]);
                    zb_usdt_order_amount = float(zb_usdt_orderBook["bids"][0][1]);"""
                    double_check_percent = 100 * (
                        bid_price - zb_bcc_order_price) / bid_price
                    print "double check percent ={}".format(
                        double_check_percent)
                    if double_check_percent > 1.0:
                        bcc_trading_amount = min(bid_amount,
                                                 zb_bcc_order_amount, 1.00)
                        bcc_trading_amount = Decimal(
                            bcc_trading_amount).quantize(Decimal('0.0000'))
                        """
                        sell_usdt_bcc(bid_price, bcc_trading_amount);
                        zb_api1.buy_bcc_order(zb_bcc_order_price, bcc_trading_amount);
                        """
                        print "buying {} bcc in {} price in zb \n".format(
                            bcc_trading_amount, zb_bcc_order_price)
                        print "selling {} bcc in {} price in poloniex \n".format(
                            bcc_trading_amount, bid_price)

                        record.write(
                            "selling {} bcc in {} price in poloniex \n".format(
                                bcc_trading_amount, bid_price))
                        record.write(
                            "buying {} bcc in {} price in zb \n".format(
                                bcc_trading_amount, zb_bcc_order_price))
                        realtime_bcc_amount = realtime_bcc_amount + float(
                            bcc_trading_amount)
                        realtime_usdt_amount = realtime_usdt_amount - float(
                            bcc_trading_amount) * zb_bcc_order_price
                        print "realtime bcc in zb = {} \n".format(
                            realtime_bcc_amount)
                        print "realtime usdt in zb = {} \n".format(
                            realtime_usdt_amount)
                        if (realtime_bcc_amount < 0.1 * INIT_BCC_AMOUNT) or (
                                realtime_ustd_amount < 0.1 * INIT_USDT_AMOUNT):
                            withdraw_between_exchanges(
                                realtime_bcc_amount - INIT_BCC_AMOUNT,
                                realtime_usdt_amount - INIT_USDT_AMOUNT)
                    else:
                        print "it is a pity that double check percent is less than 1.0"
                except Exception, ex:
                    print 'zb cannel_order exception, {}'.format(ex)
            record.write("!!!Opportunity!!! =" + str(OP_COUNT) + "!!!!\n")
Beispiel #6
0
def getCHBTCETCorders():
    zb_api_trading = zb_api(get_zb_api_key(), get_zb_api_secret())
    zb_usdt_market = zb_api_trading.query_depth("usdt_cny")
    print zb_usdt_market