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

質問編集履歴

6

2018/05/28 04:40

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- 例外の無視 タイムアウト HTTPSConnectionPool(host='api.zaif.jp', port=443): Read timed out. (read timeout=10)
1
+ 例外の無視 タイムアウト
body CHANGED
@@ -16,151 +16,4 @@
16
16
  参考URL:
17
17
 
18
18
  https://code.i-harness.com/ja/q/b268c
19
- https://teratail.com/questions/109954
20
-
21
- ポイント:
22
-
23
- 例外(エラー)が発生しそうな処理「だけ」try: except:で囲う
24
-
25
-
26
- 対象pgm
27
-
28
- ```ここに言語を入力
29
- r = exchange[1].create_order(
30
- symbol=target_currency,
31
- type="limit",
32
- side="buy",
33
- amount= 100,
34
- price= 100
35
- ```
36
-
37
- ERROR
38
-
39
- ```ここに言語を入力
40
- 1つめ
41
- raise exception_type(output)
42
- ccxt.base.errors.RequestTimeout: zaif POST https://api.zaif.jp/tapi HTTPSConnectionPool(host='api.zaif.jp', port=443): Read timed out. (read timeout=10)
43
-
44
- 2つめ
45
- raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
46
- urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
47
-
48
- ```
49
-
50
- 参考にしたtry 文
51
- ```ここに言語を入力
52
- from_datetime = '2017-01-01 00:00:00'
53
- from_timestamp = exchange.parse8601(from_datetime)
54
-
55
- # -----------------------------------------------------------------------------
56
-
57
- now = exchange.milliseconds()
58
-
59
- # -----------------------------------------------------------------------------
60
-
61
- data = []
62
-
63
- while from_timestamp < now:
64
-
65
- try:
66
-
67
- print(exchange.milliseconds(), 'Fetching candles starting from', exchange.iso8601(from_timestamp))
68
- ohlcvs = exchange.fetch_ohlcv('BTC/USD', '5m', from_timestamp)
69
- print(exchange.milliseconds(), 'Fetched', len(ohlcvs), 'candles')
70
- first = ohlcvs[0][0]
71
- last = ohlcvs[-1][0]
72
- print('First candle epoch', first, exchange.iso8601(first))
73
- print('Last candle epoch', last, exchange.iso8601(last))
74
- from_timestamp += len(ohlcvs) * minute * 5
75
- data += ohlcvs
76
-
77
- except (ccxt.ExchangeError, ccxt.AuthenticationError, ccxt.ExchangeNotAvailable, ccxt.RequestTimeout) as error:
78
-
79
- print('Got an error', type(error).__name__, error.args, ', retrying in', hold, 'seconds...')
80
- time.sleep(hold)
81
- ```
82
-
83
-
84
- RequestTimeoutについての説明
85
-
86
- This exception is raised when the connection with the exchange fails or data is not fully received in a specified amount of time. This is controlled by the timeout option. When a RequestTimeout is raised, the user doesn't know the outcome of a request (whether it was accepted by the exchange server or not).
87
-
88
- Thus it's advised to handle this type of exception in the following manner:
89
-
90
- for fetching requests it is safe to retry the call
91
- for a request to cancelOrder a user is required to retry the same call the second time. If instead of a retry a user calls a fetchOrder, fetchOrders, fetchOpenOrders or fetchClosedOrders right away without a retry to call cancelOrder, this may cause the .orders cache to fall out of sync. A subsequent retry to cancelOrder will return one of the following possible results:
92
- a request is completed successfully, meaning the order has been properly canceled now
93
- an OrderNotFound exception is raised, which means the order was either already canceled on the first attempt or has been executed (filled and closed) in the meantime between the two attempts. Note, that the order will still have an 'open' status in the .orders cache. To determine the actual order status you'll need to call fetchOrder to update the cache properly (where available from the exchange). If the fetchOrder method is 'emulated' the ccxt library will mark the order as 'closed'. The user has to call fetchBalance and set the order status to 'canceled' manually if the balance hasn't changed (a trade didn't not occur).
94
-
95
- **今回エラーが出ているcreateorderのtimeoutにおける2つの対応推奨案**
96
-
97
- if a request to createOrder fails with a RequestTimeout the user should:
98
- update the .orders cache with a call to fetchOrders, fetchOpenOrders, fetchClosedOrders to check if the request to place the order has succeeded and the order is now open
99
- if the order is not 'open' the user should fetchBalance to check if the balance has changed since the order was created on the first run and then was filled and closed by the time of the second check. Note that fetchBalance relies on the .orders cache for balance inference and thus should only be called after updating the cache!
100
-
101
-
102
- 同じソース箇所で出た2つ目のエラー
103
-
104
- ```ここに言語を入力
105
- raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
106
- urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
107
- ```
108
-
109
- **エラー詳細**
110
-
111
- ```ここに言語を入力
112
- Traceback (most recent call last):
113
-
114
- socket.timeout: The read operation timed out
115
-
116
- During handling of the above exception, another exception occurred:
117
-
118
- Traceback (most recent call last):
119
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\adapters.py", line 440, in send
120
- timeout=timeout
121
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
122
- _stacktrace=sys.exc_info()[2])
123
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\util\retry.py", line 357, in increment
124
- raise six.reraise(type(error), error, _stacktrace)
125
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\packages\six.py", line 686, in reraise
126
- raise value
127
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
128
- chunked=chunked)
129
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 389, in _make_request
130
- self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
131
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 309, in _raise_timeout
132
- raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
133
- urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
134
-
135
- During handling of the above exception, another exception occurred:
136
-
137
- Traceback (most recent call last):
138
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 357, in fetch
139
- proxies=self.proxies
140
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\sessions.py", line 508, in request
141
- resp = self.send(prep, **send_kwargs)
142
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\sessions.py", line 618, in send
143
- r = adapter.send(request, **kwargs)
144
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\adapters.py", line 521, in send
145
- raise ReadTimeout(e, request=request)
146
- requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
147
-
148
- During handling of the above exception, another exception occurred:
149
-
150
- File "C:/pythonfiles/price_check/pricecheck04-easyorder/arb8.py", line 229, in process_get_price
151
- orderbook = exchange_get.fetch_order_book(target_currency) # ここです。■■■■■■■■■■■■■■
152
-   File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\bitflyer.py", line 155, in fetch_order_book
153
- }, params))
154
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 306, in request
155
- return self.fetch2(path, api, method, params, headers, body)
156
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 303, in fetch2
157
- return self.fetch(request['url'], request['method'], request['headers'], request['body'])
158
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 367, in fetch
159
- self.raise_error(RequestTimeout, method, url, e)
160
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 288, in raise_error
161
- raise exception_type(output)
162
-
163
- ccxt.base.errors.RequestTimeout: bitflyer GET https://api.bitflyer.jp/v1/getboard?product_code=BTC_JPY HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
164
-
165
- Process finished with exit code 1
166
- ```
19
+ https://teratail.com/questions/109954

5

ほそく4

2018/05/28 04:40

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -9,8 +9,10 @@
9
9
  ぜひお知恵を拝借したく、宜しくお願いいたします。
10
10
 
11
11
  例外による無視が出来れば良いのですが、exceptionが出来ません。
12
- またtry文にこだわっているつもりはありません。
12
+ またtry文にこだわっているつもりはありません。ccxt.RequestTimeoutが使えたらいいと思っています。
13
13
 
14
+ 大変お手数をおかけします。よろしくお願いします。
15
+
14
16
  参考URL:
15
17
 
16
18
  https://code.i-harness.com/ja/q/b268c

4

ほそく3

2018/05/23 02:04

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -35,8 +35,14 @@
35
35
  ERROR
36
36
 
37
37
  ```ここに言語を入力
38
+ 1つめ
38
39
  raise exception_type(output)
39
40
  ccxt.base.errors.RequestTimeout: zaif POST https://api.zaif.jp/tapi HTTPSConnectionPool(host='api.zaif.jp', port=443): Read timed out. (read timeout=10)
41
+
42
+ 2つめ
43
+ raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
44
+ urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
45
+
40
46
  ```
41
47
 
42
48
  参考にしたtry 文
@@ -84,8 +90,75 @@
84
90
  a request is completed successfully, meaning the order has been properly canceled now
85
91
  an OrderNotFound exception is raised, which means the order was either already canceled on the first attempt or has been executed (filled and closed) in the meantime between the two attempts. Note, that the order will still have an 'open' status in the .orders cache. To determine the actual order status you'll need to call fetchOrder to update the cache properly (where available from the exchange). If the fetchOrder method is 'emulated' the ccxt library will mark the order as 'closed'. The user has to call fetchBalance and set the order status to 'canceled' manually if the balance hasn't changed (a trade didn't not occur).
86
92
 
87
- **今回エラーが出ているcreateorderのtimeout**
93
+ **今回エラーが出ているcreateorderのtimeoutにおける2つの対応推奨案**
88
94
 
89
95
  if a request to createOrder fails with a RequestTimeout the user should:
90
96
  update the .orders cache with a call to fetchOrders, fetchOpenOrders, fetchClosedOrders to check if the request to place the order has succeeded and the order is now open
91
- if the order is not 'open' the user should fetchBalance to check if the balance has changed since the order was created on the first run and then was filled and closed by the time of the second check. Note that fetchBalance relies on the .orders cache for balance inference and thus should only be called after updating the cache!
97
+ if the order is not 'open' the user should fetchBalance to check if the balance has changed since the order was created on the first run and then was filled and closed by the time of the second check. Note that fetchBalance relies on the .orders cache for balance inference and thus should only be called after updating the cache!
98
+
99
+
100
+ 同じソース箇所で出た2つ目のエラー
101
+
102
+ ```ここに言語を入力
103
+ raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
104
+ urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
105
+ ```
106
+
107
+ **エラー詳細**
108
+
109
+ ```ここに言語を入力
110
+ Traceback (most recent call last):
111
+
112
+ socket.timeout: The read operation timed out
113
+
114
+ During handling of the above exception, another exception occurred:
115
+
116
+ Traceback (most recent call last):
117
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\adapters.py", line 440, in send
118
+ timeout=timeout
119
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
120
+ _stacktrace=sys.exc_info()[2])
121
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\util\retry.py", line 357, in increment
122
+ raise six.reraise(type(error), error, _stacktrace)
123
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\packages\six.py", line 686, in reraise
124
+ raise value
125
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
126
+ chunked=chunked)
127
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 389, in _make_request
128
+ self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
129
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 309, in _raise_timeout
130
+ raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
131
+ urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
132
+
133
+ During handling of the above exception, another exception occurred:
134
+
135
+ Traceback (most recent call last):
136
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 357, in fetch
137
+ proxies=self.proxies
138
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\sessions.py", line 508, in request
139
+ resp = self.send(prep, **send_kwargs)
140
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\sessions.py", line 618, in send
141
+ r = adapter.send(request, **kwargs)
142
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\adapters.py", line 521, in send
143
+ raise ReadTimeout(e, request=request)
144
+ requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
145
+
146
+ During handling of the above exception, another exception occurred:
147
+
148
+ File "C:/pythonfiles/price_check/pricecheck04-easyorder/arb8.py", line 229, in process_get_price
149
+ orderbook = exchange_get.fetch_order_book(target_currency) # ここです。■■■■■■■■■■■■■■
150
+   File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\bitflyer.py", line 155, in fetch_order_book
151
+ }, params))
152
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 306, in request
153
+ return self.fetch2(path, api, method, params, headers, body)
154
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 303, in fetch2
155
+ return self.fetch(request['url'], request['method'], request['headers'], request['body'])
156
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 367, in fetch
157
+ self.raise_error(RequestTimeout, method, url, e)
158
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 288, in raise_error
159
+ raise exception_type(output)
160
+
161
+ ccxt.base.errors.RequestTimeout: bitflyer GET https://api.bitflyer.jp/v1/getboard?product_code=BTC_JPY HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
162
+
163
+ Process finished with exit code 1
164
+ ```

3

ほそく2

2018/05/23 02:03

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -9,6 +9,7 @@
9
9
  ぜひお知恵を拝借したく、宜しくお願いいたします。
10
10
 
11
11
  例外による無視が出来れば良いのですが、exceptionが出来ません。
12
+ またtry文にこだわっているつもりはありません。
12
13
 
13
14
  参考URL:
14
15
 
@@ -38,6 +39,40 @@
38
39
  ccxt.base.errors.RequestTimeout: zaif POST https://api.zaif.jp/tapi HTTPSConnectionPool(host='api.zaif.jp', port=443): Read timed out. (read timeout=10)
39
40
  ```
40
41
 
42
+ 参考にしたtry 文
43
+ ```ここに言語を入力
44
+ from_datetime = '2017-01-01 00:00:00'
45
+ from_timestamp = exchange.parse8601(from_datetime)
46
+
47
+ # -----------------------------------------------------------------------------
48
+
49
+ now = exchange.milliseconds()
50
+
51
+ # -----------------------------------------------------------------------------
52
+
53
+ data = []
54
+
55
+ while from_timestamp < now:
56
+
57
+ try:
58
+
59
+ print(exchange.milliseconds(), 'Fetching candles starting from', exchange.iso8601(from_timestamp))
60
+ ohlcvs = exchange.fetch_ohlcv('BTC/USD', '5m', from_timestamp)
61
+ print(exchange.milliseconds(), 'Fetched', len(ohlcvs), 'candles')
62
+ first = ohlcvs[0][0]
63
+ last = ohlcvs[-1][0]
64
+ print('First candle epoch', first, exchange.iso8601(first))
65
+ print('Last candle epoch', last, exchange.iso8601(last))
66
+ from_timestamp += len(ohlcvs) * minute * 5
67
+ data += ohlcvs
68
+
69
+ except (ccxt.ExchangeError, ccxt.AuthenticationError, ccxt.ExchangeNotAvailable, ccxt.RequestTimeout) as error:
70
+
71
+ print('Got an error', type(error).__name__, error.args, ', retrying in', hold, 'seconds...')
72
+ time.sleep(hold)
73
+ ```
74
+
75
+
41
76
  RequestTimeoutについての説明
42
77
 
43
78
  This exception is raised when the connection with the exchange fails or data is not fully received in a specified amount of time. This is controlled by the timeout option. When a RequestTimeout is raised, the user doesn't know the outcome of a request (whether it was accepted by the exchange server or not).

2

補足2

2018/05/23 01:56

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -10,7 +10,16 @@
10
10
 
11
11
  例外による無視が出来れば良いのですが、exceptionが出来ません。
12
12
 
13
+ 参考URL:
13
14
 
15
+ https://code.i-harness.com/ja/q/b268c
16
+ https://teratail.com/questions/109954
17
+
18
+ ポイント:
19
+
20
+ 例外(エラー)が発生しそうな処理「だけ」try: except:で囲う
21
+
22
+
14
23
  対象pgm
15
24
 
16
25
  ```ここに言語を入力

1

補足2

2018/05/23 01:48

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -29,9 +29,8 @@
29
29
  ccxt.base.errors.RequestTimeout: zaif POST https://api.zaif.jp/tapi HTTPSConnectionPool(host='api.zaif.jp', port=443): Read timed out. (read timeout=10)
30
30
  ```
31
31
 
32
- 英語が読めずヒントが書かれてると思うですが理解できません。泣
32
+ RequestTimeout説明
33
33
 
34
- RequestTimeout
35
34
  This exception is raised when the connection with the exchange fails or data is not fully received in a specified amount of time. This is controlled by the timeout option. When a RequestTimeout is raised, the user doesn't know the outcome of a request (whether it was accepted by the exchange server or not).
36
35
 
37
36
  Thus it's advised to handle this type of exception in the following manner:
@@ -40,6 +39,9 @@
40
39
  for a request to cancelOrder a user is required to retry the same call the second time. If instead of a retry a user calls a fetchOrder, fetchOrders, fetchOpenOrders or fetchClosedOrders right away without a retry to call cancelOrder, this may cause the .orders cache to fall out of sync. A subsequent retry to cancelOrder will return one of the following possible results:
41
40
  a request is completed successfully, meaning the order has been properly canceled now
42
41
  an OrderNotFound exception is raised, which means the order was either already canceled on the first attempt or has been executed (filled and closed) in the meantime between the two attempts. Note, that the order will still have an 'open' status in the .orders cache. To determine the actual order status you'll need to call fetchOrder to update the cache properly (where available from the exchange). If the fetchOrder method is 'emulated' the ccxt library will mark the order as 'closed'. The user has to call fetchBalance and set the order status to 'canceled' manually if the balance hasn't changed (a trade didn't not occur).
42
+
43
+ **今回エラーが出ているcreateorderのtimeout**
44
+
43
45
  if a request to createOrder fails with a RequestTimeout the user should:
44
46
  update the .orders cache with a call to fetchOrders, fetchOpenOrders, fetchClosedOrders to check if the request to place the order has succeeded and the order is now open
45
47
  if the order is not 'open' the user should fetchBalance to check if the balance has changed since the order was created on the first run and then was filled and closed by the time of the second check. Note that fetchBalance relies on the .orders cache for balance inference and thus should only be called after updating the cache!