質問編集履歴
1
コードを修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,87 +36,31 @@
|
|
36
36
|
|
37
37
|
message = json.loads(message)
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
if message["method"] == "channelMessage":
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
params_message_bid = message["params"]["message"]["bids"]
|
46
|
-
|
47
|
-
params_message_ask = message["params"]["message"]["asks"]
|
48
|
-
|
49
|
-
df_bid = pd.DataFrame(params_message_bid).set_index("price")
|
50
|
-
|
51
|
-
df_ask = pd.DataFrame(params_message_ask).set_index("price")
|
52
|
-
|
53
|
-
df = pd.concat([df_bid, df_ask])
|
54
|
-
|
55
|
-
mid_price = message["params"]["message"]["mid_price"]
|
56
|
-
|
57
|
-
loop()
|
58
|
-
|
59
|
-
print(df)
|
60
|
-
|
61
|
-
return df, mid_price
|
62
|
-
|
63
|
-
|
64
|
-
|
65
39
|
|
66
40
|
|
67
41
|
def on_open(ws):
|
68
42
|
|
69
|
-
ws.send(json.dumps({"method": "subscribe",
|
70
43
|
|
71
|
-
"params": {"channel": CHANNEL}}))
|
72
|
-
|
73
|
-
print('Websocket connected')
|
74
44
|
|
75
45
|
|
76
46
|
|
77
47
|
def disconnect(self):
|
78
48
|
|
79
|
-
self.ws.keep_running = False
|
80
49
|
|
81
|
-
self.ws.close()
|
82
50
|
|
83
51
|
|
84
52
|
|
85
53
|
def on_error(self, error):
|
86
54
|
|
87
|
-
self.disconnect()
|
88
55
|
|
89
|
-
time.sleep(0.5)
|
90
|
-
|
91
|
-
ws = websocket.WebSocketApp("wss://ws.lightstream.bitflyer.com/json-rpc",
|
92
|
-
|
93
|
-
on_message=on_message, on_open=on_open, on_error = on_error, on_close = on_close)
|
94
|
-
|
95
|
-
if CHANNEL == "lightning_board_snapshot_FX_BTC_JPY":
|
96
|
-
|
97
|
-
ws.keep_running = False;
|
98
56
|
|
99
57
|
|
100
58
|
|
101
59
|
def on_close(self):
|
102
60
|
|
103
|
-
print('Websocket disconnected')
|
104
61
|
|
105
62
|
|
106
63
|
|
107
|
-
def initial():
|
108
|
-
|
109
|
-
CHANNEL = "lightning_board_snapshot_FX_BTC_JPY"
|
110
|
-
|
111
|
-
ws = websocket.WebSocketApp("wss://ws.lightstream.bitflyer.com/json-rpc",
|
112
|
-
|
113
|
-
on_message = on_message, on_open = on_open, on_error = on_error, on_close = on_close)
|
114
|
-
|
115
|
-
ws.run_forever()
|
116
|
-
|
117
|
-
ws.keep_running = False;
|
118
|
-
|
119
|
-
|
120
64
|
|
121
65
|
def loop():
|
122
66
|
|
@@ -132,13 +76,7 @@
|
|
132
76
|
|
133
77
|
if __name__ == "__main__":
|
134
78
|
|
135
|
-
# note: reconnection handling needed.
|
136
79
|
|
137
|
-
CHANNEL = "lightning_board_FX_BTC_JPY"
|
138
|
-
|
139
|
-
ws = websocket.WebSocketApp("wss://ws.lightstream.bitflyer.com/json-rpc",
|
140
|
-
|
141
|
-
on_message = on_message, on_open = on_open, on_error = on_error, on_close = on_close)
|
142
80
|
|
143
81
|
ws.run_forever()
|
144
82
|
|