@run-out said in How to get the index of the current iteration in next?:
@borutf You can get the current bar but using
len(self)
Thanks.
@run-out said in How to get the index of the current iteration in next?:
@borutf You can get the current bar but using
len(self)
Thanks.
2022-05-17 23:59:59.999989
This happens to every datetime??
I always use bt.feeds.PandasData , it can work on yfinance downloads as well.
strat = results[0]
pyfoliozer = strat.analyzers.getbyname('pyfolio')
returns, positions, transactions, gross_lev = pyfoliozer.get_pf_items()
This is what the backtrader analyzer can return and then you can the returns, positions, transactions, gross_lev as arguments for the pyfolio library.
I am using the ccxbt library to retrieve live-data from binance. The problem is that my strategy only uses 15 minute intervals, so there is no need to make requests for the OHCLV every second, which it appears to be doing. I want to later scale the project to run several strategies concurrently and I am worried this calls will exceed Binance's limit of 1200 per minute.
Is there any way to limit this calls, the strategy run only on full intervals anyway.
So, I know about pyfolio, where you can get all the transactions with the get_pf_items, however I would like to see all the orders and that were made.
I am particularly interested in the Stop and Limit orders placed through buy_bracket/sell_bracket, I want to see the stop/limit prices they set.
I guess I could use notify_order to append the data to a pandas dataframe and save to csv in the end, but I would prefer a made solution before go deep into that.
@sunny-p for buy a limit order limits the price upwards.
you can do an Order.Stop that will be triggered at the price, however it will behave like a market order after that.
This Library is suggested one the website.
The data-connection works fine and normal market orders as well.
But for stop-orders I get this strange error that all required parameters are not set, stopPrice in the case STOP/TAKE_PROFIT, even though they are.
I went through the traceback and I found that the broker has this in the code:
try:
# all params are exchange specific: https://github.com/ccxt/ccxt/wiki/Manual#custom-order-params
params['created'] = created # Add timestamp of order creation for backtesting
ret_ord = self.store.create_order(symbol=data.p.dataname, order_type=order_type, side=side,
amount=amount, price=price, params=params)
except:
# save some API calls after failure
self.use_order_params = False
return None
If an error occurs it returns None and then sets the class variable use_order_params to False, which means additional parameters are not used anymore which leads to the error. It makes it impossible to debug what went wrong in the first call.
Anybody dealt with the STOP/TAKE_PROFIT ? It seems like a limitation of bt-ccxt.
@sunny-p You said it buys at 77.62 instead of 77.91, that is correct as when you have a buy limit order you specify the worst(maximum) possible price you would want to buy at.
What API do you want to connect to?
I want to do SFOX and I will try to model it on the way CCXT connects to different exchanges.
@rb88 I don't know any. But I am very interested in doing something similar myself.
Let me know if you would be interested in collaborating. I have a decent knowledge of backtrader and I think I am very experienced with dealing with different types of APIs.
@varsha-shingade with the help of analyzers:
cerebro.addanalyzer(bt.analyzers.PyFolio, _name='pyfolio')
strat = cerebro.run(tradehistory=True)
pyfoliozer = strat[0].analyzers.getbyname('pyfolio')
returns, positions, transactions, gross_lev = pyfoliozer.get_pf_items()
transactions.to_csv("transactions.csv")
There are other options with analyzers, because there is so much data you can save.
Seems unusual to me.
May I ask why do you even call super().sell_bracket ?
Why not just self.sell_bracket ? Did you change sell_bracket somehow?