Esempio n. 1
0
def get_data(trade_coin_list):
    result = []
    connPool = urllib3.PoolManager()
    http = connPool.request(method='get', url="https://data.gateio.io/api2/1/tickers")
    con = eval(http.data)
    total_num = len(con.keys())
    cur_num = 0
    for cur_pair in con.keys():
        cur_num = cur_num + 1
        coin_names = cur_pair.split('_')
        coin_name = coin_names[0]
        trade_coin_name = coin_names[1]
        if trade_coin_name not in trade_coin_list:
            continue
        cur_price = float(con[cur_pair]['last'])
        # get deep
        deep_url = "https://data.gateio.io/api2/1/orderBook/" + cur_pair
        http = connPool.request(method='get', url=deep_url)
        deep_con = eval(http.data)
        sell_con_list = deep_con['asks']
        buy_con_list = deep_con['bids']
        sell_list = []
        buy_list = []
        for cur_sell in sell_con_list:
            price = float(cur_sell[0])
            amount = float(cur_sell[1])
            cur_deep = common.DeepUnit(price=price, num=amount)
            sell_list.append(cur_deep)
        for cur_buy in buy_con_list:
            price = float(cur_buy[0])
            amount = float(cur_buy[1])
            cur_deep = common.DeepUnit(price=price, num=amount)
            buy_list.append(cur_deep)
        kline_list = []
        kline_url = "https://data.gateio.io/api2/1/candlestick2/" \
                    "%s?group_sec=30&range_hour=1" % cur_pair
        kline_data = eval(connPool.request(method='get', url=kline_url).data)
        for cur_kline in kline_data["data"]:
            cur_time = float(cur_kline[0])
            high = float(cur_kline[3])
            low = float(cur_kline[4])
            close = float(cur_kline[2])
            cur_k = common.KlineUnit(cur_time, high, low, close)
            kline_list.append(cur_k)
        cur_data = common.CoinData(coin_name, trade_coin_name, buy_list, sell_list, cur_price, kline_list)
        log.warning("gate :" + cur_pair + "  " + str(cur_num) + "/" + str(total_num))
        result.append(cur_data)
    return result
Esempio n. 2
0
def get_deep_list_from_ele(depth_ele):
    result_list = []
    cur_html = etree.HTML(etree.tostring(depth_ele))
    inner_divs = cur_html.xpath("//div[@class='inner']")
    for cur_div in inner_divs:
        cur_h = etree.HTML(etree.tostring(cur_div))
        spans = cur_h.xpath("//span")
        cur_price = spans[1].text
        cur_amount = spans[3].text
        cur_deep = common.DeepUnit(price=cur_price, num=cur_amount)
        result_list.append(cur_deep)
    return result_list
Esempio n. 3
0
def get_data(trade_coin_list):
    result = []
    conn_pool = urllib3.PoolManager()
    pairs_url = "http://api.zb.com/data/v1/markets"
    con = conn_pool.request(method='get', url=pairs_url)
    con = eval(con.data)

    all_price_url = "http://api.zb.com/data/v1/allTicker"
    all_price_con = eval(conn_pool.request(method='get', url=all_price_url).data)
    total_num = len(con.keys())
    cur_num2 = 0
    for cur_pair in con.keys():
        cur_num2 = cur_num2 + 1
        names = cur_pair.split('_')
        coin_name = names[0]
        trade_coin_name = names[1]
        if trade_coin_name not in trade_coin_list:
            continue
        cur_price = float(all_price_con[coin_name+trade_coin_name]['last'])
        deep_url = "http://api.zb.com/data/v1/depth?market=" + coin_name + "_" + trade_coin_name + "&size=20"
        deep_http = conn_pool.request(method='get', url=deep_url)
        deep_con = eval(deep_http.data)
        sell_list = []
        for cur_sell in deep_con['asks']:
            cur_price = cur_sell[0]
            cur_num = cur_sell[1]
            cur_sell_unit = common.DeepUnit(price=cur_price, num=cur_num)
            sell_list.append(cur_sell_unit)

        buy_list = []
        for cur_buy in deep_con['bids']:
            cur_price = cur_buy[0]
            cur_num = cur_buy[1]
            cur_buy_unit = common.DeepUnit(price=cur_price, num=cur_num)
            buy_list.append(cur_buy_unit)

        # get kline
        kline_url = "http://api.zb.com/data/v1/kline?market="+coin_name+"_"+trade_coin_name+"&type=1min"
        con = eval(conn_pool.request(method='get', url=kline_url).data)
        kline_list = []
        time.sleep(1)
        ok_flag = False
        for i in range(10):
            try:
                con['data']
                ok_flag = True
            except:
                time.sleep(5*i)
                con = eval(conn_pool.request(method='get', url=kline_url).data)
            else:
                break
        if not ok_flag:
            continue
        for cur_k in con['data']:
            cur_time = cur_k[0]
            high = cur_k[2]
            low = cur_k[3]
            close = cur_k[4]
            cur_k_unit = common.KlineUnit(time=cur_time, high=high, low=low, close=close)
            kline_list.append(cur_k_unit)
        cur_data = common.CoinData(coin_name, trade_coin_name, buy_list, sell_list, cur_price, kline_list)
        log.warning("zb:" + coin_name + ":" + trade_coin_name + ":  " + str(cur_num2) + "/" + str(total_num))
        result.append(cur_data)
    return result
Esempio n. 4
0
def get_data(trade_coin_list):
    result = []
    conn = urllib3.PoolManager()
    coin_list_url = "https://www.okex.com/marketList"
    #http = conn.request(method='get', url=coin_list_url).data
    http = common.phantom_get(url=coin_list_url)
    html = etree.HTML(http)
    usdt_tables = html.xpath(
        "//div[@class='market-list-tickers']/table[@data-type='usdt']/tbody/tr/@data-product"
    )
    btc_tables = html.xpath(
        "//div[@class='market-list-tickers']/table[@data-type='btc']/tbody/tr/@data-product"
    )
    eth_tables = html.xpath(
        "//div[@class='market-list-tickers']/table[@data-type='eth']/tbody/tr/@data-product"
    )
    okb_tables = html.xpath(
        "//div[@class='market-list-tickers']/table[@data-type='okb']/tbody/tr/@data-product"
    )
    total_num = len(usdt_tables + btc_tables + eth_tables + okb_tables)
    cur_num2 = 0
    for cur_pair in usdt_tables + btc_tables + eth_tables + okb_tables:
        cur_num2 = cur_num2 + 1
        names = cur_pair.split('_')
        coin_name = names[0]
        trade_coin_name = names[1]
        if trade_coin_name not in trade_coin_list:
            continue

        price_url = "https://www.okex.com/api/v1/ticker.do?symbol=" + coin_name + "_" + trade_coin_name
        http = conn.request(method='get', url=price_url).data
        http = eval(http)
        cur_price = float(http['ticker']['last'])

        deep_url = "https://www.okex.com/api/v1/depth.do?symbol=" + coin_name + "_" + trade_coin_name
        http = eval(conn.request(method='get', url=deep_url).data)
        sell_list = []
        for cur_sell in http['asks']:
            cur_price = cur_sell[0]
            cur_amount = cur_sell[1]
            cur_deep = common.DeepUnit(price=cur_price, num=cur_amount)
            sell_list.append(cur_deep)
        buy_list = []
        for cur_buy in http['bids']:
            cur_price = cur_buy[0]
            cur_amount = cur_buy[1]
            cur_deep = common.DeepUnit(price=cur_price, num=cur_amount)
            buy_list.append(cur_deep)

        kline_url = "https://www.okex.com/api/v1/kline.do?symbol=" + coin_name + "_" + trade_coin_name + "&type=1min"
        http = conn.request(method='get', url=kline_url).data
        http = eval(http)
        kline_list = []
        for cur_k in http:
            cur_time = cur_k[0]
            high = float(cur_k[2])
            low = float(cur_k[3])
            close = float(cur_k[4])
            cur_k_unit = common.KlineUnit(time=cur_time,
                                          high=high,
                                          low=low,
                                          close=close)
            kline_list.append(cur_k_unit)

        cur_data = common.CoinData(coin_name, trade_coin_name, buy_list,
                                   sell_list, cur_price, kline_list)
        result.append(cur_data)
        log.warning("okex: " + coin_name + ":" + trade_coin_name + ":   " +
                    str(cur_num2) + "/" + str(total_num))
    return result
Esempio n. 5
0
def get_data(trade_coin_list):
    result = []
    connPool = urllib3.PoolManager()
    http = connPool.request(method='get',
                            url="https://api.huobipro.com/v1/common/symbols")
    http = eval(http.data)

    total_num = len(http['data'])
    cur_num = 0
    for cur_coin in http['data']:
        cur_num = cur_num + 1
        cur_coin_name = cur_coin["base-currency"]
        trade_coin_name = cur_coin["quote-currency"]
        if trade_coin_name not in trade_coin_list:
            continue

        trade_url = "https://api.huobipro.com/market/detail?symbol=" + cur_coin_name + trade_coin_name
        http = connPool.request(method='get', url=trade_url)
        http = eval(http.data)
        cur_price = http['tick']['close']

        sell_list = []
        buy_list = []
        deep_url = "https://api.huobipro.com/market/depth?symbol="+\
                   cur_coin_name+trade_coin_name+"&type=step1"
        http = connPool.request(method='get', url=deep_url)
        http = eval(http.data)
        cur_deep = http['tick']
        for cur_buy_deep in cur_deep['bids']:
            cur_price = cur_buy_deep[0]
            amount = cur_buy_deep[1]
            cur_deepcon = common.DeepUnit(price=cur_price, num=amount)
            buy_list.append(cur_deepcon)
        for cur_buy_deep in cur_deep['asks']:
            cur_price = cur_buy_deep[0]
            amount = cur_buy_deep[1]
            cur_deepcon = common.DeepUnit(price=cur_price, num=amount)
            sell_list.append(cur_deepcon)

        kline_list = []
        url = 'https://api.huobipro.com/market/history/kline?period=1min&size=200&symbol=' \
              + cur_coin_name + trade_coin_name
        kline_http = connPool.request(method='get', url=url)
        kline_con = eval(kline_http.data)
        for cur_k in kline_con['data']:
            cur_time = cur_k['id']
            high = cur_k['high']
            low = cur_k['low']
            close = cur_k['close']
            cur_k_data = common.KlineUnit(time=cur_time,
                                          high=high,
                                          low=low,
                                          close=close)
            kline_list.append(cur_k_data)
        cur_data = common.CoinData(coin_name=cur_coin_name,
                                   trade_coin_name=trade_coin_name,
                                   buy_list=buy_list,
                                   sell_list=sell_list,
                                   cur_price=cur_price,
                                   kline_list=kline_list)
        result.append(cur_data)
        log.warning("huobi %s_%s:  " % (cur_coin_name, trade_coin_name) +
                    str(cur_num) + "/" + str(total_num))
    return result