質問編集履歴

3

エラー追加

2022/08/22 00:21

投稿

161
161

スコア1

test CHANGED
File without changes
test CHANGED
@@ -9,7 +9,48 @@
9
9
 
10
10
  ### 発生している問題・エラーメッセージ
11
11
 
12
+ --- Logging error ---
13
+ Traceback (most recent call last):
14
+ File "/Users/a1/opt/anaconda3/envs/m/lib/python3.9/site-packages/websocket/_app.py", line 383, in run_forever
15
+ dispatcher.read(self.sock.sock, read, check)
16
+ File "/Users/a1/opt/anaconda3/envs/m/lib/python3.9/site-packages/websocket/_app.py", line 64, in read
17
+ r = self.select()
18
+ File "/Users/a1/opt/anaconda3/envs/m/lib/python3.9/site-packages/websocket/_app.py", line 78, in select
12
- エラーは特に出ていませんが、やり方がわかりませんでした
19
+ r = sel.select(self.ping_timeout)
20
+ File "/Users/a1/opt/anaconda3/envs/m/lib/python3.9/selectors.py", line 562, in select
21
+ kev_list = self._selector.control(None, max_ev, timeout)
22
+ KeyboardInterrupt
23
+
24
+ During handling of the above exception, another exception occurred:
25
+
26
+ Traceback (most recent call last):
27
+ File "/Users/a1/opt/anaconda3/envs/m/lib/python3.9/site-packages/websocket/_app.py", line 424, in _callback
28
+ callback(self, *args)
29
+ TypeError: on_close() takes 2 positional arguments but 4 were given
30
+
31
+ During handling of the above exception, another exception occurred:
32
+
33
+ Traceback (most recent call last):
34
+ File "/Users/a1/opt/anaconda3/envs/m/lib/python3.9/logging/__init__.py", line 1086, in emit
35
+ stream.write(msg + self.terminator)
36
+ AttributeError: 'int' object has no attribute 'write'
37
+ Call stack:
38
+ File "/Users/a1/Desktop/ml/main.py", line 14, in <module>
39
+ json_rpc = RealtimeAPI(url=url, channel=channel)
40
+ File "/Users/a1/Desktop/ml/bitflyer.py", line 15, in __init__
41
+ self.connect()
42
+ File "/Users/a1/Desktop/ml/bitflyer.py", line 22, in connect
43
+ self.ws.run_forever()
44
+ File "/Users/a1/opt/anaconda3/envs/m/lib/python3.9/site-packages/websocket/_app.py", line 390, in run_forever
45
+ teardown()
46
+ File "/Users/a1/opt/anaconda3/envs/m/lib/python3.9/site-packages/websocket/_app.py", line 318, in teardown
47
+ self._callback(self.on_close, close_status_code, close_reason)
48
+ File "/Users/a1/opt/anaconda3/envs/m/lib/python3.9/site-packages/websocket/_app.py", line 429, in _callback
49
+ self.on_error(self, e)
50
+ File "/Users/a1/Desktop/ml/bitflyer.py", line 35, in on_error
51
+ logger.error(error)
52
+ Message: TypeError('on_close() takes 2 positional arguments but 4 were given')
53
+ Arguments: ()
13
54
 
14
55
  ### 該当のソースコード
15
56
 

2

プログラム変更

2022/08/22 00:15

投稿

161
161

スコア1

test CHANGED
File without changes
test CHANGED
@@ -24,6 +24,7 @@
24
24
  import pybitflyer
25
25
 
26
26
  logger = logging.getLogger(__name__)#logging
27
+ ticker_data = 0#追記
27
28
 
28
29
  class RealtimeAPI(object):
29
30
 
@@ -74,6 +75,11 @@
74
75
  print(ticker)
75
76
  logger.info(f'ticker={ticker}')
76
77
 
78
+ global ticker_data#追記
79
+ ticker_data = ticker#追記
80
+
81
+ print(ticker_data)#ここにAPIから入ってくるtickerのデータを入れたいです
82
+
77
83
  ---------------------------------ここからもう一つのファイル---------------------------------------
78
84
  #ファイル名 main.py
79
85
  import logging

1

不用部分の削除

2022/08/21 11:50

投稿

161
161

スコア1

test CHANGED
File without changes
test CHANGED
@@ -69,11 +69,8 @@
69
69
  def set_realtime_ticker(self, resp):
70
70
  timestamp = resp['timestamp']
71
71
  product_code = resp['product_code']
72
- bid = float(resp['best_bid'])
73
- ask = float(resp['best_ask'])
74
- spread = (ask - bid) / ((bid + ask) / 2)
75
72
  volume = float(resp['volume'])
76
- ticker = [product_code, timestamp, bid, ask, spread, volume]
73
+ ticker = [product_code, timestamp, volume]
77
74
  print(ticker)
78
75
  logger.info(f'ticker={ticker}')
79
76