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.values[-2] < lowers.values[-2]) and (close.values[-1] >= lowers.values[-1]):
order.up_cross_order(symbol, 'K线上穿BOLL下轨,以市价做多')
# K线下穿BOLL上轨,以市价做空
elif (close.values[-2] > uppers.values[-2]) and (close.values[-1] <= uppers.values[-1]):
order.down_cross_order(symbol, 'K线下穿BOLL上轨,以市价做空')
# K线下穿BOLL中轨,以市价平多单
elif (close.values[-2] > middles.values[-2]) and (close.values[-1] <= middles.values[-1]):
order.close_long_positions(symbol, 'K线下穿BOLL中轨,以市价平多单')
# K线上穿BOLL中轨,以市价平空单
elif (close.values[-2] < middles.values[-2]) and (close.values[-1] >= middles.values[-1]):
order.close_short_positions(symbol, 'K线上穿BOLL中轨,以市价平空单')
time.sleep(5)
print("任务结束时间:", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
if __name__ == '__main__':
main()
标签:okx,symbol,boll,BOLL,values,time,close,区块,order From: https://www.cnblogs.com/nbjjy/p/17486112.html