Ejemplo n.º 1
0
#客户端调用,用于查看API返回结果

from OkcoinSpotAPI import OKCoinSpot
import pandas as pd

pd.set_option('display.max_columns', None)
pd.set_option('display.width', 1000)

#初始化apikey,secretkey,url
apikey = '9c02dad0-7ab3-421f-9bea-7e8959c356bd'
secretkey = '32C80E2D1C4B6C833656284BB2DD7B1F'
okcoinRESTURL = 'www.okcoin.com'  #请求注意:国内账号需要 修改为 www.okcoin.cn

#现货API
okcoinSpot = OKCoinSpot(okcoinRESTURL, apikey, secretkey)
result = okcoinSpot.getKline("etc_usdt", "1min")
print(result)

#期货API

# print (u' 现货行情 ')
# print (okcoinSpot.ticker('btc_usd'))
#
# print (u' 现货深度 ')
# print (okcoinSpot.depth('btc_usd'))

#print (u' 现货历史交易信息 ')
#print (okcoinSpot.trades())

#print (u' 用户现货账户信息 ')
#print (okcoinSpot.userinfo())
Ejemplo n.º 2
0
          trade_coin_amount)

    # # ===sleep直到运行时间
    run_time = next_run_time(time_interval)
    sleep(max(0, (run_time - datetime.now()).seconds))
    while True:  # 在靠近目标时间时
        if datetime.now() < run_time:
            continue
        else:
            break

    # ===获取最新数据
    while True:
        okcoinSpot = OKCoinSpot(okcoinRESTURL, apikey, secretkey)
        # 获取数据
        df = okcoinSpot.getKline(symbol_okex, type)
        # print(df)
        # df = get_okex_candle_data(exchange, symbol, time_interval)
        # 判断是否包含最新的数据
        _temp = df[df['candle_begin_time_GMT8'] == (
            run_time - timedelta(minutes=int(type.strip('min'))))]
        if _temp.empty:
            print('获取数据不包含最新的数据,重新获取')
            continue
        else:
            break

    # ===产生交易信号
    df = df[df['candle_begin_time_GMT8'] <
            pd.to_datetime(run_time)]  # 去除target_time周期的数据
    df = signal_moving_average(df, para=para)