def test_empty(): assert list2dict([]) == {}
def test_abc(): dictionary = list2dict(["a", "b", "c"]) assert dictionary == {1: 'a', 2: 'b', 3: 'c'}
def test_abc(): dictionary = list2dict(['a', 'b', 'c']) assert dictionary == {1: 'a', 2: 'b', 3: 'c'}
def test_swapem(): dictionary=list2dict(["a", "b", "c"]) assert swapem(dictionary) == {"a": 1, "b": 2, "c": 3}
# 使用179地址的david库1h表做测试 engine = create_engine( 'mysql+pymysql://' + 'ops:ops!@#[email protected]:3308/david') # ?charset=utf8&autocommit=true with engine.connect() as conn: # 日期格式调整 UTC_FORMAT = "%Y-%m-%dT%H:%M:%S.0000000Z" # coinapi的日期格式 LOCAL_FORMAT = "%Y-%m-%d %H:%M:%S" # live的日期格式 def time_format(inputT): return dt.datetime.strptime(inputT, UTC_FORMAT).strftime(LOCAL_FORMAT) # 需要更新的品种,每天分市场补全,对BINA--BTC--USDT,BINANCE_SPOT_BTC_USDT无数据,使用BITFINEX_SPOT_BTC_USD替换 df = pd.read_csv('symbols.csv') symbols = l2d.list2dict(list(df['symbol'].values), exchange='BITFINEX_SPOT') # 需要更新的时间段,补全间断,没有后接,待处理 dateStart = '2018-05-31 00:00:00' dateEnd = '2018-08-01 00:00:00' with open('d:\\update_1791h.csv', 'a') as f: # append方式打开文档 # csv存一份,sql更新一份 s = 'ts,symbol,open,high,low,close,quantity\n' f.write(s) # 遍历每一个品种,先查日期是否间断,有则下载数据填充mysql for key in symbols.keys(): # 取1h表的某key的ts列 query = """ SELECT DISTINCT ts FROM david.1h
# coding:utf-8 import list2dict as l2d import pandas as pd df = pd.read_csv('symbols.csv') symbols = list(df['symbol'].values) d = l2d.list2dict(symbols) print(d)
def test_swap(): dictionary = swapem(list2dict(["a", "b", "c"])) assert dictionary == {'a': 1, 'b': 2, 'c': 3}