前提・実現したいこと
FXのoandaの自動売買をpythonで実装しようと試みております。
oanda apiの中からticker情報を取得しようとしたときに、指定した情報が存在しないとエラーが起きました。
どなたかわかる方おりましたら、ご教授していたでけますと幸いです。
発生している問題・エラーメッセージ
エラーメッセージ INFO:oandapyV20.oandapyV20:setting up API-client for environment practice Traceback (most recent call last): File "/Users/kensho/python/pyfxtrading/main.py", line 41, in <module> ticker=api_client.get_ticker(settings.product_code) AttributeError: 'APIClient' object has no attribute 'get_ticker'
該当のソースコード
main.py #!/usr/bin/env python # coding: utf-8 import logging import sys from oanda.oanda import APIClient import settings logging.basicConfig(level=logging.INFO,stream=sys.stdout) if __name__=="__main__": api_client=APIClient(settings.access_token,settings.account_id) ticker=api_client.get_ticker(settings.product_code)
oanda.py from datetime import datetime import logging import dateutil.parser from oandapyV20 import API from oandapyV20.endpoints import accounts from oandapyV20.exceptions import V20Error from oandapyV20.endpoints.pricing import PricingInfo logger=logging.getLogger(__name__) class Balance(object): def __init__(self,currency,available): self.currency=currency self.available=available class Ticker(object): def __init__(self,product_code,timestamp,bid,ask,volume): self.product_code=product_code self.timestamp=timestamp self.bid=bid self.ask=ask self.volume=volume class APIClient(object): def __init__(self,access_token,account_id,environment='practice'): self.access_token=access_token self.account_id=account_id self.client=API(access_token=access_token,environment=environment) def get_balance(self) -> Balance: req=accounts.AccountSummary(accountID=self.account_id) try: resp=self.client.request(req) except V20Error as e: logger.error(f'action=get_balance error={e}') raise available=float(resp['account']['balance']) currency=resp['account']['currency'] return Balance(currency,available) def get_ticker(self,product_code) -> Ticker: params={ 'instruments':product_code } req = PricingInfo(accountID=self.account_id,params=params) try: resp=self.client.request(req) except V20Error as e: logger.error(f'action=get_ticker error={e}') raise print(resp)
試したこと
上記のimportでまだインストールされてないものがあるのではと思い、importの内容は全てインストールしました。
エラー内容にAPI-clientとあったのでAPIClientを全てAPI-clientに変更したのですが、ダメでした。
既にデモアカウントは作っていて、oanda.pyのdef get_ticker(self,product_code) -> Ticker:の行より前の情報は取得できました。
tickerを取得しようとするとエラーが起きます。
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー