Skip to content

Instantly share code, notes, and snippets.

@HHIR
Last active January 16, 2022 23:10
Show Gist options
  • Save HHIR/be54af17c7f34eb27a89a219dc060f27 to your computer and use it in GitHub Desktop.
Save HHIR/be54af17c7f34eb27a89a219dc060f27 to your computer and use it in GitHub Desktop.
How can get variable from unicorn-binance-websocket-api stream results?
from unicorn_binance_websocket_api.unicorn_binance_websocket_api_manager import BinanceWebSocketApiManager
import os
import time
from unicorn_fy.unicorn_fy import UnicornFy
import talib
import pandas as pd
import pandas_ta as pta
import numpy as np
import os
import threading
import itertools
ubwa = BinanceWebSocketApiManager(exchange="binance.com")
ubwa.create_stream(['kline_1m'], ['btcusdt', 'bnbbtc', 'ethbtc'])
closes, highs, lows, data = [], [], [], []
index1 = 0
while True:
oldest_data_from_stream_buffer = ubwa.pop_stream_data_from_stream_buffer()
closes, highs, lows = [], [], []
if oldest_data_from_stream_buffer:
unicorn_fied_stream_data = UnicornFy.binance_com_websocket(oldest_data_from_stream_buffer)
try:
index1 = index1 + 1
close = float(unicorn_fied_stream_data['kline']['close_price']) #CLOSE PRICE
high = float(unicorn_fied_stream_data['kline']['high_price']) #HIGH PRICE
low = float(unicorn_fied_stream_data['kline']['low_price']) #LOW PRICE
time.sleep(2)
if close:
print (index1)
closes.append(close)
highs.append(high)
lows.append(low)
if index1 < 2:
data = []
dataq = []
price_data= []
data.append([ closes, highs, lows])
# print (data())
# print (data)
price_data = pd.DataFrame(data)#.transpose()
price_data.columns=['close', 'high', 'low']
print (price_data["close"])
print ("______________")
if len(price_data["close"]) > 15:
Close_array= np.array((list(itertools.chain(*price_data["close"])) ))
RSI = talib.RSI(Close_array,timeperiod=14)
# RSI= pta.rsi(price_data["close"], length = 14)
print ("RSI :")
print (RSI)
time.sleep(2)
except:
print("Something went wrong")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment