Ejemplo n.º 1
0
    DD_LAG = 45

    conn = xutils.getLocalConn()
    cursor = conn.cursor()

    client = Client(api_key, api_secret)

    codes = {'BTC': 'BTCUSDT', 'ETH': 'ETHUSDT', 'EOS': 'EOSUSDT'}

    for code in codes:
        print('Get Close', codes[code])

        candles = client.get_klines(symbol=codes[code],
                                    interval=Client.KLINE_INTERVAL_1DAY)

        upsert_sql = xutils.buildUpsertOnDuplicateSql(
            'coin_close', ['code', 'date', 'close'])

        # discard last one
        for c in candles[:-1]:
            dt = datetime.fromtimestamp(c[0] / 1000).date()
            cursor.execute(upsert_sql, (code, dt, float(c[4])) * 2)
        conn.commit()
        time.sleep(3)

    s_lst = []
    for code in codes:
        sql = "select date, close from coin_close where code = %(code)s order by date"
        df = pd.read_sql(sql, con=conn, params={'code': code})
        df = df.set_index('date')
        s_lst.append(df['close'])
Ejemplo n.º 2
0
    conn = xutils.getLocalConn()
    cursor = conn.cursor()

    client = Client(api_key, api_secret)

    # 熊市只从BTC和ETH里面选择
    codes = {'BTC': 'BTCUSDT', 'ETH': 'ETHUSDT', 'LTC': 'LTCUSDT'}

    for code in codes:
        print('Get Close', codes[code])

        candles = client.get_klines(symbol=codes[code],
                                    interval=Client.KLINE_INTERVAL_1DAY)

        upsert_sql = xutils.buildUpsertOnDuplicateSql(
            'coin_close', ['code', 'date', 'close'])

        # discard last one
        for c in candles[:-1]:
            dt = datetime.fromtimestamp(c[0] / 1000).date()
            cursor.execute(upsert_sql, (code, dt, float(c[4])) * 2)
        conn.commit()
        time.sleep(5)

    s_lst = []
    for code in codes:
        sql = "select date, close from coin_close where code = %(code)s order by date"
        df = pd.read_sql(sql, con=conn, params={'code': code})
        df = df.set_index('date')
        s_lst.append(df['close'])
Ejemplo n.º 3
0
    for row in rows:
        cols = row.find_all('td')
        cols = [ele.text.strip() for ele in cols]
        data.append([ele for ele in cols if ele])  # Get rid of empty values

    cap_lst = []
    volume_lst = []
    max_dt = None
    for row in data:
        dt = datetime.strptime(row[0], '%b %d, %Y').date()
        if not max_dt or max_dt < dt:
            max_dt = dt
        if row[6] == '-':
            cap = 0.0
        else:
            cap = float(row[6].replace(',', ''))
        if row[5] == '-':
            volume = 0.0
        else:
            volume = float(row[5].replace(',', ''))
        cap_lst.append(cap)
        volume_lst.append(volume)
    cap = AdjustedData(cap_lst, CAP_ALPHA)
    volume = AdjustedData(volume_lst, VOL_ALPHA)
    print code, max_dt, cap, volume
    upsert_sql = xutils.buildUpsertOnDuplicateSql(
        'coin_cap', ['code', 'date', 'cap', 'volume'])

    cursor.execute(upsert_sql, (code, max_dt, cap, volume) * 2)

conn.commit()
Ejemplo n.º 4
0
    cursor = conn.cursor()

    client = Client(api_key, api_secret)

    codes = {
        'BTC': 'BTCUSDT',
        'ETH': 'ETHUSDT',
        # 'LTC': 'LTCUSDT'
    }

    for code in codes:
        print ('Get Close', codes[code])

        candles = client.get_klines(symbol=codes[code], interval=Client.KLINE_INTERVAL_1DAY)

        upsert_sql = xutils.buildUpsertOnDuplicateSql('coin_close', ['code', 'date', 'close'])

        # discard last one
        for c in candles[:-1]:
            dt = datetime.fromtimestamp(c[0]/1000).date()
            cursor.execute(upsert_sql, (code, dt, float(c[4])) * 2)
        conn.commit()
        time.sleep(5)

    s_lst = []
    for code in codes:
        sql = "select date, close from coin_close where code = %(code)s order by date"
        df = pd.read_sql(sql, con=conn, params={'code':code})
        df = df.set_index('date')
        s_lst.append(df['close'])