happydasch / btoandav20

Support for Oanda-V20 API in backtrader
Apache License 2.0
128 stars 52 forks source link

Starting Algorithm With Pending Order #15

Closed haimivan closed 6 years ago

haimivan commented 6 years ago

Hi,

again this could be related to Backtrader... :-)

Before I start the script oandav20test.py, I create a Buy Stop order via the OANDA Web Trading Platform that will not be executed, because it's weekend.

Afterwards I start oandav20test.py.

How is it possible to recognize this existing (pending) order within the code?

happydasch commented 6 years ago

it is not possible. You will not be able to recognize orders which were created outside the session. The same goes for trades that were closed outside backtrader, they will also not get recognized.

It will only process transactions, that were created by the _order_create method. It would be possible to fill backtrader with all open trades when starting, but this would require some work. Currently, the store will fetch open positions. This data is used to create a simulated order, so backtrader can close that position.

At the moment, its good to close all pending stuff or open trades/positions before starting backtrader.

haimivan commented 6 years ago

Thanks for your reply.

I understand you correctly, that not being able to get existing orders and trades/positions during startup is not backtrader related, but the present behaviour of backtrader-oandav20?

In my humble opinion, it would be very helpful to have such a feature, as otherwise any interruption of a running process of oandav20test.py (like intermediate change from my laptop to my desktop, own programming errors...) would force me to continue my trading manually.

I understand it very well, that intercepting a running algo program with manual trading leads to a high complexity, but my humble hope would be to have such a feature that looks during start() or __init__() in the present state of the account to fill internal variables accordingly.

happydasch commented 6 years ago

Yes, this is store related. We have the possibility to fetch the information on startup and recreate pending orders and open trades via the api. From this data we could fill and prepare backtrader.

I have this already on my todo List but i will not be able to work on it in near future.

I need this to be able to close trades manually from oanda.

happydasch commented 6 years ago

I have commited a new version today, give it a try. This should work now :grinning: