kieran-mackle / AutoTrader

A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.
https://kieran-mackle.github.io/AutoTrader/
GNU General Public License v3.0
937 stars 216 forks source link

Not clear how to login, needing simple example template #76

Closed RobertAgee closed 1 year ago

RobertAgee commented 1 year ago

Is your feature request related to a problem? Please describe. I am frustrated that I have no clear idea of how to login to my broker via Autotrader. I have reviewed the docs and updated the keys.yaml file with the correct details.

Describe the solution you'd like A basic template file to login to a broker and check balances, get account details. A really simple example case to get over the initial hurdle will be of great help, especially to noobs.

What I've tried

at = AutoTrader()

login = at.configure(broker="oanda")

balance = autotrader.OandaBroker.get_balance()

print(balance)

Returns "TypeError: Broker.get_balance() missing 1 required positional argument: 'self'"

at = AutoTrader()

login = at.configure(broker="oanda")

balance = autotrader.OandaBroker.get_balance(login)

print(balance)

Returns "AttributeError: 'NoneType' object has no attribute '_check_connection'"

Temporary solution I got AT to work via below but I doubt it's the intended syntax.

oanda = autotrader.OandaBroker(oanda_config={ "API": "api-fxtrade.oanda.com",
                                              "ACCESS_TOKEN": "my_access_token",
                                              "ACCOUNT_ID": "my_account_id",
                                              "PORT": 443 })

balance = autotrader.OandaBroker.get_balance(oanda)

print(balance)
kieran-mackle commented 1 year ago

Hi @RobertAgee,

Sorry the docs aren't too clear on this.

To keep things basic, the first thing you want to do is set up your working directory according to the recommended structure. This will simplify things when getting started. Part of this process is creating your keys.yaml file, inside of your config/ directory. The docs for this file provide an example of providing your login details with Oanda. I'll paste it here for completeness. Just update the values with your own.

OANDA:
  LIVE_API: "api-fxtrade.oanda.com"
  LIVE_ACCESS_TOKEN: "12345678900987654321-abc34135acde13f13530"
  PRACTICE_API: "api-fxpractice.oanda.com"
  PRACTICE_ACCESS_TOKEN: "12345678900987654321-abc34135acde13f13530"
  DEFAULT_ACCOUNT_ID: "xxx-xxx-xxxxxxxx-001"
  PORT: 443

Now, you can connect to Oanda and start getting familiar. For this, the click trading tutorial will be useful. Again, for completeness sake, I will provide a sample of code below. After importing the main AutoTrader class, instantiate it, configure it (providing your broker oanda, and trading environment) and finally run it, capturing the returned broker object as you do so. This is the easiest way to manually interact with a broker instance, rather than the approach you have tried above.

from autotrader import AutoTrader

# Instantiate AutoTrader and run to return broker
at = AutoTrader()
at.configure(broker='oanda', environment="paper")
broker = at.run()

# Now you can interact with the broker
print(broker.get_balance())

After this, you can play around with the returned broker object, which is consistent with the broker interface.

Let me know if you have any other questions!

RobertAgee commented 1 year ago

Great, thanks!