1、新增cross_boll_order.py
# -*- coding: utf-8 -*- import talib import cross_order as order import time BOLL_N = 20 # BBands参数N BOLL_M = 2 # BBands参数M 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(BOLL_N + 1)) close = data['close'].values # 计算BBands uppers, middles, lowers = talib.BBANDS(close, timeperiod=BOLL_N, nbdevdn=BOLL_N, nbdevup=BOLL_M) # BBands策略 # K线上穿BOLL下轨,以市价做多 if (close[-2] < lowers[-2]) and (close[-1] >= lowers[-1]): order.up_cross_order(symbol=symbol,ordtype='market', message='K线上穿BOLL下轨,以市价做多') # K线下穿BOLL上轨,以市价做空 elif (close[-2] > uppers[-2]) and (close[-1] <= uppers[-1]): order.down_cross_order(symbol=symbol,ordtype='market', message='K线下穿BOLL上轨,以市价做空') # K线下穿BOLL中轨,以市价平多单 elif (close[-2] > middles[-2]) and (close[-1] <= middles[-1]): order.close_positions(symbol=symbol, side='sell', positionside='long', message='K线下穿BOLL中轨,以市价平多单') # K线上穿BOLL中轨,以市价平空单 elif (close[-2] < middles[-2]) and (close[-1] >= middles[-1]): order.close_short_positions(symbol=symbol, side='buy', positionside='short', message='K线上穿BOLL中轨,以市价平空单') time.sleep(5) print("任务结束时间:", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) if __name__ == '__main__': main()