teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

間違いがあったので修正しました。

2021/03/20 13:32

投稿

step595
step595

スコア2

title CHANGED
File without changes
body CHANGED
@@ -80,6 +80,7 @@
80
80
 
81
81
  追記
82
82
  ```python3
83
+ (c.py)
83
84
  import websocket
84
85
  import json
85
86
 

2

コメントするにあたりコードを追記しました。

2021/03/20 13:32

投稿

step595
step595

スコア2

title CHANGED
File without changes
body CHANGED
@@ -76,4 +76,55 @@
76
76
  ws.on_open = on_open
77
77
  ws.run_forever()
78
78
 
79
+ ```
80
+
81
+ 追記
82
+ ```python3
83
+ import websocket
84
+ import json
85
+
86
+
87
+ def main(closea, closeb):
88
+ closea = closea + 10
89
+ closeb = closeb + 10
90
+
91
+ print (closea, closeb)
92
+
93
+
94
+ def on_message(ws, message):
95
+ try:
96
+ rs = json.loads(message)
97
+ channel = rs["params"]["channel"]
98
+ if channel == "lightning_ticker_FX_BTC_JPY":
99
+ closefx = round(float('{ltp}'.format(**(rs["params"]["message"]))))
100
+ elif channel == "lightning_ticker_BTC_JPY":
101
+ closespot = round(float('{ltp}'.format(**(rs["params"]["message"]))))
102
+ else:
103
+ print("Got other channel data:", channel, rs)
104
+ except Exception as e:
105
+ print(e)
106
+
107
+
108
+ main(closefx, closespot)
109
+
110
+ def on_error(ws, error):
111
+ print(error)
112
+
113
+
114
+ def on_close(ws):
115
+ print("### closed ###")
116
+
117
+
118
+ def on_open(ws):
119
+ print("### open ###")
120
+ ws.send(json.dumps([{'method': 'subscribe', 'params': {'channel': 'lightning_ticker_FX_BTC_JPY'}},{'method': 'subscribe', 'params': {'channel': 'lightning_ticker_BTC_JPY'}}]))
121
+
122
+
123
+ if __name__ == "__main__":
124
+ ws = websocket.WebSocketApp("wss://ws.lightstream.bitflyer.com/json-rpc",
125
+ on_message=on_message,
126
+ on_error=on_error,
127
+ on_close=on_close)
128
+ ws.on_open = on_open
129
+ ws.run_forever()
79
130
  ```

1

コードを間違えていました。

2021/03/20 13:31

投稿

step595
step595

スコア2

title CHANGED
File without changes
body CHANGED
@@ -11,13 +11,12 @@
11
11
  ```python3
12
12
  (a.py)
13
13
 
14
- import requests
15
14
  import websocket
16
15
  import json
17
16
 
18
17
  def on_message(ws, message):
19
18
  rs = json.loads(message)['params']['message']
20
- close_fx = round(float('{ltp}'.format(**rs)))
19
+ close_a = round(float('{ltp}'.format(**rs)))
21
20
  print(close_a)
22
21
 
23
22
  def on_error(ws, error):
@@ -47,13 +46,12 @@
47
46
  ```python3
48
47
  (b.py)
49
48
 
50
- import requests
51
49
  import websocket
52
50
  import json
53
51
 
54
52
  def on_message(ws, message):
55
53
  rs = json.loads(message)['params']['message']
56
- close_fx = round(float('{ltp}'.format(**rs)))
54
+ close_b = round(float('{ltp}'.format(**rs)))
57
55
  print(close_b)
58
56
 
59
57
  def on_error(ws, error):