【发布时间】:2021-09-14 18:30:43
【问题描述】:
对于 Cryptotrading 的项目,我正在尝试制作自己的扫描仪。首先,我收集数据并将它们附加到列表中。然后我将列表转换为 np.array。然后该数组将字符串作为输入,但我需要将它们更改为整数。当我打印 np_closelist 时,它会给出所有所需的值,但在一个带有字符串的数组中。当我尝试打印 b (因此将 np_closelist 转换为整数)时,它不会打印任何内容。当我在具有简单值的不同文件中尝试此方法时,它确实有效。谁能帮我弄清楚如何解决这个问题? 提前致谢!
import numpy as np
import talib
import websocket, json, pprint
socket = "wss://stream.binance.com:9443/ws/btcusdt@kline_1m"
closelist = []
def on_open(ws):
print('open')
def on_close(ws):
print('close')
def on_message(ws, message):
global closelist
json_message = json.loads(message)
# pprint.pprint(json_message)
candle = json_message['k']
is_candle_closed = candle['x']
close = candle['c']
high = candle['h']
low = candle['l']
if is_candle_closed:
closelist.append(format(float(close)))
closelist.append(format(float(high)))
closelist.append(format(float(low)))
np_closelist = np.array(closelist)
b = np.array([int(i) for i in np_closelist])
print(b)
print(type(b))
print(type(b[1]))
ws = websocket.WebSocketApp(socket, on_open=on_open, on_message=on_message, on_close=on_close)
ws.run_forever()
【问题讨论】:
标签: python cryptocurrency