@backtrader sorry to bother but is there any chance you can suggest anything for this or that question?
Latest posts made by Dimasik007
- RE: split position in chunks and issue limit orders at X minutes intervals
- RE: CCXTbt make market order if limit order is not filled in X minutes
Hi @balibou ! thanks for your reply and suggestion.
validunfortunately doesn't work because it's not implemented in the ccxtbt. But thanks to your suggestion I decided to create limit orders in the next and add a variable
validwhich I am using to check how long the order was on the order book and if it wasn't filled in the required time, I am creating a new market order from the
notify_order.
The problem now is that when I am using a market order, it's executing immediately and I can't get back into the notify order until the next candle. I am using around 10 orders to scale into position when the signal is generated, so I am still stuck. If there are any other suggestions on how to solve this or that question, I would really appreciate anyones help.
- CCXTbt make market order if limit order is not filled in X minutes
Hi, I am using ccxtbt to trade on Binance. I use limit orders and trade on 1, 2 and 4 hour candles. Occasionally, limit orders might not get filled and I want to add a condition to the ccxtbroker "next" method to send market orders if the limit order is not filled within 2-3 minutes.
Buy/sell methods take owner, data, size and exectype parameters, so I was wondering how would I specify them within the next() of the CCXTBroker class?
My code goes in the next function after this comment: # execute order with market if limit is not filled after X amount of time
Can anyone suggest how would I properly cancel existing limit order and create a new market buy/sell order?
self.buy(self, owner, data, size, exectype)
def next(self): if self.debug: print('Broker next() called') for o_order in list(self.open_orders): oID = o_order.ccxt_order['id'] # Print debug before fetching so we know which order is giving an # issue if it crashes if self.debug: print('Fetching Order ID: {}'.format(oID)) # Get the order ccxt_order = self.store.fetch_order(oID, o_order.data.p.dataname, params={'type': 'future'}) # ADDED PARAMS HERE # Check for new fills if self.debug: print(f'checking for trades in ccxt_order - ccxt_order is {ccxt_order}') if ccxt_order['trades'] is not None: # added explicit check for None otherwise it was proceeding if self.debug: print('reading trades in ccxt_order') for fill in ccxt_order['trades']: if fill not in o_order.executed_fills: o_order.execute(fill['datetime'], fill['amount'], fill['price'], 0, 0.0, 0.0, 0, 0.0, 0.0, 0.0, 0.0, 0, 0.0) o_order.executed_fills.append(fill['id']) # execute order with market if limit is not filled after X amount of time if float(ccxt_order['info']['executedQty']) < abs(float(ccxt_order['info']['origQty'])): now = datetime.utcnow() time_created = datetime.strptime(ccxt_order['datetime'][:-5], '%Y-%m-%dT%H:%M:%S') timedelta_diff = now - time_created diff_s = timedelta_diff.total_seconds() / 60 print(f'time now: {now}, order time {time_created} and diff: {diff_s}') if diff_s > 0.1: print(f'difference is greater than {diff_s} seconds - make market order') # cancel the limit order here self.cancel(ccxt_order, params={'type': 'future'}) self.open_orders.remove(o_order) o_order.cancel() self.notify(o_order) if ccxt_order['side'] == 'buy': print('send market buy order') # market_order = self.buy(size=o_order.size, exectype='market') elif ccxt_order['side'] == 'sell': print('send market sell order') # market_order = self.sell(size=o_order.size, exectype='market') if self.debug: print(json.dumps(ccxt_order, indent=self.indent)) # Check if the order is closed if ccxt_order[self.mappings['closed_order']['key']] == self.mappings['closed_order']['value']: # # check if order is closed and add commission info if self.debug: print('checking for closed status to notify of trade') pos = self.getposition(o_order.data, clone=False) pos.update(o_order.size, o_order.price) o_order.completed() self.notify(o_order) self.open_orders.remove(o_order) self.get_balance() # Manage case when an order is being Canceled from the Exchange # from if ccxt_order[self.mappings['canceled_order']['key']] == self.mappings['canceled_order']['value']: self.open_orders.remove(o_order) o_order.cancel() self.notify(o_order)
Thanks a lot!
- RE: backtrader-plotting control panel doesn't show up in Jupyter notebook
@kian-hong-Tan thanks for your reply. Yes, I've tried all of that already and it doesn't work in Jupyter unfortunately so I guess I just won't use jupyter for now. I only noticed that some space is allocated for the toolbar but the toolbar itself doesn't want to show up.
@vbs no problem, thanks for your reply and for backtrader-plotting!
- split position in chunks and issue limit orders at X minutes intervals
I am using ccxtbt to do live trading. My strategy is based on hourly candles. When I am getting a long or short signal I want to split my position in 5-10 chunks and every 2-5 minutes generate a limit order if the limit order is not filled in 2 minutes then the market order will be sent and after another 2 minutes I want to start again with the next chunk. Can anyone suggest how would I implement something like this?
I assume sizers would be the best place to start and I understand that I can send portions of the position in tranches. Although, I want to send multiple tranches during a single candle after my signal was generated.
Thanks a lot in advance.
- RE: backtrader-plotting control panel doesn't show up in Jupyter notebook posted in General Code/Help
- backtrader-plotting control panel doesn't show up in Jupyter notebook
Hi, I am using backtrader-plotting to make Bokeh plot in the Jupyter notebook. For some reason Bokeh control panel doesn't show up when I am making a plot inside the notebook. It works well when I am running a backtest from the terminal and the plot pops up in the browser.
Does anyone know how this could be solved? Appreciate any help!
- Observers/Analyzers per asset in multi-asset strategy?
Firstly, thanks a lot for an excellent framework!
I am testing a multi-asset trading strategy - short one asset and long the other at the same time.
I want to see the maximum DrawDown each position can have during the trade. How could I achieve this?
I understand that I can't apply DrawDown observer separately for each asset because it is based on the Broker which tracks cash, correct?
Is it possible to modify DataTrades Observer to implement something similar to what I've made on the picture below? So that I could see PnL of each position during the trade and find out/record the highest DrawDown position could have. If it is possible, any directions on how to do this?
Thanks!