前提・実現したいこと
PythonでoandaのAPIを使いオーダーを送りたいと考えています。
oandapyV20を使っており、"environment"に'live'を挿入するとKeyErrorが発生します。
これを解消するにはどうしたら良いでしょうか?
発生している問題・エラーメッセージ
Traceback (most recent call last): File "/Users/**/**/**/**/python3.8/site-packages/oandapyV20/oandapyV20.py", line 192, in __init__ TRADING_ENVIRONMENTS[environment] KeyError: '"live"' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/**/**/**/main.py", line 21, in <module> api = API(access_token=access_token, environment=environment) File "/Users/**/**/**/**/python3.8/site-packages/oandapyV20/oandapyV20.py", line 195, in __init__ raise KeyError("Unknown environment: {}".format(environment)) KeyError: 'Unknown environment: "live"'
実行したコード
Python
1import json 2from oandapyV20.endpoints.orders import OrderCreate 3from oandapyV20 import API 4 5import settings 6 7access_token = *** 8account_id = *** 9environment = "live" 10instrument = EUR_USD 11 12data = { 13 "order":{ 14 "instrument":instrument, 15 "units": 1, 16 "type": "MARKET", 17 "positionFill": "DEFAULT" 18 } 19} 20 21api = API(access_token=access_token, environment=environment) 22eq = OrderCreate(accountID=account_id, data=data) 23rsp = api.request(eq) 24print(json.dump(rsp, indent=2))
##oandapyV20の該当箇所(153行目〜)
Python
1 def __init__(self, access_token, environment="practice", 2 headers=None, request_params=None): 3 """Instantiate an instance of OandaPy's API wrapper. 4 5 Parameters 6 ---------- 7 access_token : string 8 Provide a valid access token. 9 10 environment : string 11 Provide the environment for OANDA's REST api. Valid values: 12 'practice' or 'live'. Default: 'practice'. 13 14 headers : dict (optional) 15 Provide request headers to be set for a request. 16 17 18 .. note:: 19 20 There is no need to set the 'Content-Type: application/json' 21 for the endpoints that require this header. The API-request 22 classes covering those endpoints will take care of the header. 23 24 request_params : (optional) 25 parameters to be passed to the request. This can be used to apply 26 for instance a timeout value: 27 28 request_params={"timeout": 0.1} 29 30 See specs of the requests module for full details of possible 31 parameters. 32 33 .. warning:: 34 parameters belonging to a request need to be set on the 35 requestinstance and are NOT passed via the client. 36 37 """ 38 logger.info("setting up API-client for environment %s", environment) 39 try: 40 TRADING_ENVIRONMENTS[environment] 41 except: 42 logger.error("unkown environment %s", environment) 43 raise KeyError("Unknown environment: {}".format(environment)) 44 else: 45 self.environment = environment
試したこと
oandapyV20の再インストール
補足情報(FW/ツールのバージョンなど)
Python3.8
あなたの回答
tips
プレビュー