質問
Bitcoinの自動取引botを作成し、bitFlyerのgetparentordersというapiを利用し親注文の状況を取得する関数を作ったのですが、繰り返すとたまにエラーが出ます。要求がタイムアウトになってしまっているようなのですがどうすればこれを解消できるか困っています。エラーが出てもプログラムが止まらないようにする方法、またはタイムアウトをしないようにはできないでしょうか。タイムアウト値を大きくすればタイムアウトすることは無くなりますか?
発生している問題・エラーメッセージ
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=30)
該当の関数
python
1def position(): 2 api_key = API_KEY 3 api_secret = API_SECRET 4 5 base_url = "https://api.bitflyer.jp" 6 path_url = "/v1/me/getparentorders?product_code=FX_BTC_JPY" 7 method = "GET" 8 9 timestamp = str(datetime.datetime.today()) 10 11 12 message = timestamp + method + path_url 13 #print(message) 14 signature = hmac.new(bytearray(api_secret.encode('utf-8')), message.encode('utf-8') , digestmod = hashlib.sha256 ).hexdigest() 15 #print(message.encode('utf-8')) 16 headers = { 17 'ACCESS-KEY' : api_key, 18 'ACCESS-TIMESTAMP' : timestamp, 19 'ACCESS-SIGN' : signature, 20 'Content-Type' : 'application/json' 21 } 22 23 response = requests.get( base_url + path_url , headers = headers , timeout = 30) 24 #pprint(response.json()) 25 return response.json()
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。