回答編集履歴
1
シンプル化
answer
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
二つのchannelにアクセスしたいならば、下記のように2つのチャンネル取得用のデータをsendするだけです。
|
2
2
|
|
3
|
+
|
3
4
|
```
|
4
5
|
import websocket
|
5
6
|
import json
|
@@ -9,15 +10,8 @@
|
|
9
10
|
try:
|
10
11
|
rs = json.loads(message)
|
11
12
|
channel = rs["params"]["channel"]
|
12
|
-
if channel == "lightning_executions_FX_BTC_JPY":
|
13
|
-
price = round(float('{price}'.format(**(rs["params"]["message"][0]))))
|
14
|
-
print(channel, price)
|
15
|
-
elif channel == "lightning_ticker_FX_BTC_JPY":
|
16
|
-
|
17
|
-
|
13
|
+
close_fx = round(float('{ltp}'.format(**(rs["params"]["message"]))))
|
18
|
-
|
14
|
+
print(channel, close_fx)
|
19
|
-
else:
|
20
|
-
print("Got other channel data:", channel, rs)
|
21
15
|
except Exception as e:
|
22
16
|
print(e)
|
23
17
|
|
@@ -33,7 +27,7 @@
|
|
33
27
|
def on_open(ws):
|
34
28
|
print("### open ###")
|
35
29
|
ws.send(json.dumps([{'method': 'subscribe', 'params': {'channel': 'lightning_ticker_FX_BTC_JPY'}},
|
36
|
-
{'method': 'subscribe', 'params': {'channel': '
|
30
|
+
{'method': 'subscribe', 'params': {'channel': 'lightning_ticker_BTC_JPY'}}]))
|
37
31
|
|
38
32
|
|
39
33
|
if __name__ == "__main__":
|