# -*- coding: utf-8 -*-
import talib
import cross_order as order
import time
CCI_TIMEPERIOD = 20 # CCI计算周期
CCI_OVER_SOLD_THRESH = -250 # 超卖阈值
CCI_OVER_BOUGHT_THRESH = 350 # 超买阈值
def main():
print("任务开始时间:", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
for symbol in order.symbol_pool:
# 设置杠杆倍数
order.set_leverage(symbol=symbol, leverage='25')
# 获取标的的最新价
data = order.get_candlesticks(symbol=symbol, interval='15m', limit=str(CCI_TIMEPERIOD + 1))
close = data['close']
high = data['high']
low = data['low']
# 计算CCI
cci = talib.CCI(high, low, close, timeperiod=CCI_TIMEPERIOD)
# CCI策略
# CCi值上穿超卖阈值,做多
if (cci.iloc[-2] < CCI_OVER_SOLD_THRESH) and (cci.iloc[-1] >= CCI_OVER_SOLD_THRESH):
order.up_cross_order(symbol, 'CCi值上穿超卖阈值,做多')
# CCI值下穿超买阈值,做空
elif (cci.iloc[-2] > CCI_OVER_BOUGHT_THRESH) and (cci.iloc[-1] <= CCI_OVER_BOUGHT_THRESH):
order.down_cross_order(symbol, 'CCI值下穿超买阈值,做空')
time.sleep(5)
print("任务结束时间:", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
if __name__ == '__main__':
main()