質問編集履歴

3

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

2021/03/20 13:32

投稿

step595
step595

スコア2

test CHANGED
File without changes
test CHANGED
@@ -162,6 +162,8 @@
162
162
 
163
163
  ```python3
164
164
 
165
+ (c.py)
166
+
165
167
  import websocket
166
168
 
167
169
  import json

2

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

2021/03/20 13:32

投稿

step595
step595

スコア2

test CHANGED
File without changes
test CHANGED
@@ -155,3 +155,105 @@
155
155
 
156
156
 
157
157
  ```
158
+
159
+
160
+
161
+ 追記
162
+
163
+ ```python3
164
+
165
+ import websocket
166
+
167
+ import json
168
+
169
+
170
+
171
+
172
+
173
+ def main(closea, closeb):
174
+
175
+ closea = closea + 10
176
+
177
+ closeb = closeb + 10
178
+
179
+
180
+
181
+ print (closea, closeb)
182
+
183
+
184
+
185
+
186
+
187
+ def on_message(ws, message):
188
+
189
+ try:
190
+
191
+ rs = json.loads(message)
192
+
193
+ channel = rs["params"]["channel"]
194
+
195
+ if channel == "lightning_ticker_FX_BTC_JPY":
196
+
197
+ closefx = round(float('{ltp}'.format(**(rs["params"]["message"]))))
198
+
199
+ elif channel == "lightning_ticker_BTC_JPY":
200
+
201
+ closespot = round(float('{ltp}'.format(**(rs["params"]["message"]))))
202
+
203
+ else:
204
+
205
+ print("Got other channel data:", channel, rs)
206
+
207
+ except Exception as e:
208
+
209
+ print(e)
210
+
211
+
212
+
213
+
214
+
215
+ main(closefx, closespot)
216
+
217
+
218
+
219
+ def on_error(ws, error):
220
+
221
+ print(error)
222
+
223
+
224
+
225
+
226
+
227
+ def on_close(ws):
228
+
229
+ print("### closed ###")
230
+
231
+
232
+
233
+
234
+
235
+ def on_open(ws):
236
+
237
+ print("### open ###")
238
+
239
+ ws.send(json.dumps([{'method': 'subscribe', 'params': {'channel': 'lightning_ticker_FX_BTC_JPY'}},{'method': 'subscribe', 'params': {'channel': 'lightning_ticker_BTC_JPY'}}]))
240
+
241
+
242
+
243
+
244
+
245
+ if __name__ == "__main__":
246
+
247
+ ws = websocket.WebSocketApp("wss://ws.lightstream.bitflyer.com/json-rpc",
248
+
249
+ on_message=on_message,
250
+
251
+ on_error=on_error,
252
+
253
+ on_close=on_close)
254
+
255
+ ws.on_open = on_open
256
+
257
+ ws.run_forever()
258
+
259
+ ```

1

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

2021/03/20 13:31

投稿

step595
step595

スコア2

test CHANGED
File without changes
test CHANGED
@@ -24,8 +24,6 @@
24
24
 
25
25
 
26
26
 
27
- import requests
28
-
29
27
  import websocket
30
28
 
31
29
  import json
@@ -36,7 +34,7 @@
36
34
 
37
35
  rs = json.loads(message)['params']['message']
38
36
 
39
- close_fx = round(float('{ltp}'.format(**rs)))
37
+ close_a = round(float('{ltp}'.format(**rs)))
40
38
 
41
39
  print(close_a)
42
40
 
@@ -96,8 +94,6 @@
96
94
 
97
95
 
98
96
 
99
- import requests
100
-
101
97
  import websocket
102
98
 
103
99
  import json
@@ -108,7 +104,7 @@
108
104
 
109
105
  rs = json.loads(message)['params']['message']
110
106
 
111
- close_fx = round(float('{ltp}'.format(**rs)))
107
+ close_b = round(float('{ltp}'.format(**rs)))
112
108
 
113
109
  print(close_b)
114
110