【发布时间】:2021-07-29 17:07:15
【问题描述】:
我正在使用 unicorn_binance_websocket_api 流式传输 100 个加密货币和来自 2 个不同时间范围的价格数据, 我想处理这些数据以存储不同加密货币各自时间范围的收盘价,然后执行我的策略以查看我需要交易的加密货币和时间范围
我将分享我如何为单一加密货币和单一时间框架编写策略的代码
from unicorn_binance_websocket_api.unicorn_binance_websocket_api_manager import
BinanceWebSocketApiManager
import json, numpy, talib
binance_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.com-futures")
binance_websocket_api_manager.create_stream('kline_1m', 'btcusdt')
closes =[]
RSI_PERIOD = 14
RSI_OVERBOUGHT = 70
RSI_OVERSOLD = 30
while True:
received_stream_data_json = binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
if received_stream_data_json:
json_data = json.loads(received_stream_data_json)
candle_data = json_data.get('data',{})
candle = candle_data.get('k', {})
symboll = candle.get('s',{})
timeframe = candle.get('i',{})
close_prices = candle.get('c',{})
open_prices = candle.get('o',{})
is_candle_closed = candle.get('x',{})
if is_candle_closed:
closes.append(float(close_prices))
if len(closes) > RSI_PERIOD:
np_closes = numpy.array(closes)
rsi = talib.RSI(np_closes,RSI_PERIOD)
if (rsi[-1] > RSI_OVERBOUGHT):
print("SELL")
elif (rsi[-1] < RSI_OVERSOLD):
print('BUY')
【问题讨论】:
标签: python json websocket algorithmic-trading binance