bartosh / backtrader

Python Backtesting library for trading strategies
http://www.backtrader.com
GNU General Public License v3.0
158 stars 55 forks source link

Broker and Store updates #7

Closed Dave-Vallance closed 6 years ago

Dave-Vallance commented 6 years ago

Hi Ed! Here are the suggestions for the issues discussed here:

Backtrader Community

Dave-Vallance commented 6 years ago

Hi Ed, Just pushed some new updates. I removed the parse_trade() method.

I also have a proposal in the code for how to track when orders are filled. It doesn't feel too elegant but it seems to work in my test environment.

Let me know if you what you think about it and if you have any questions. Maybe you have a better idea?

BTW - To parse stop loss orders (if you decide to test them) and you use bitmex, you will need to update to the latest development version of CCXT. I reported an issue with parsing orders when orders are created using extra non-unified parameters. The stop loss is one such case where a stopPx level is set rather than price

EDIT: I think there is an issue with removing the order from my open_orders list. I will look into it tomorrow.

Dave-Vallance commented 6 years ago

Hi Ed, Updates from today.

I have done some more work on detecting order status and fills.

Using fetch_closed_orders worked well for one day then resulted in an issue on bitmex. Essentially, the returned list for closed orders was limited and did not return the most recent history. Further, the since parameter did not affect the returned results. Not sure if that is a CCXT issue. I was able to work around this by passing exchange specific parameters to the call but that is not a satisfactory solution.

To work around this, I am calling fetch_order on each call of next to check the status one by one. It is more reliable but the downside is that it can result in more API calls if you have lots of open orders.

I have now been able to successfully detect fills reliably for market and stop loss orders.

bartosh commented 6 years ago

Hi Dave,

Now I can see 9 commits in this PR. They're quite hard to review. Can you squash them into smaller amount of commits? It would be great if you can split your changes into several PRs if they're independent from each other. That would greatly simplify review process for me. Thanks.

Dave-Vallance commented 6 years ago

Hi Ed, Sure, I have admittedly gone a bit crazy in the past couple of days trying to get a project off the ground. Let me review and try to split things up as you have suggested.