For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
IBKR live place an order
-
Hi!
Like to humbly ask for help.
I tried to place an order to TWS with this code.
if self.action == 'long': print('price decide on: {:.5f} '.format(self.data0.close[0]), self.data0.datetime.datetime(0)) self.ATR_at_exe = self.atr[0] self.long_parent_order = self.buy(exectype=bt.Order.Market, size=exe_size, transmit=False, valid=60) self.long_stoploss = self.sell(price=sl_px, exectype=bt.Order.Stop, transmit=True, parent=self.long_parent_order) self.long_parent_order.addinfo(name='Parent Long Bracket Main-cond 1xATR, Target 1ATR {:.5f}, SL: {:.5f}'.format(self.data0.close[0] + self.ATR_at_exe, sl_px)) self.long_stoploss.addinfo(name='Parent Long Bracket Stoploss-cond 1.5xATR, sl_px {:.5f}'.format(sl_px)) self.action = 'nothing'
But I am getting this error:
Traceback (most recent call last): File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\ib\ext\EClientSocket.py", line 1029, in placeOrder self.send(order.m_goodTillDate) File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\ib\lib\overloading.py", line 82, in __call__ return func(*args) File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\ib\ext\EClientSocket.py", line 1754, in send_1 self.m_dos.write(val) File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\ib\lib\__init__.py", line 152, in write send(pack('!c', char)) ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/quaer/Dropbox/Trade/AlgoStocks/runLive.py", line 44, in <module> main() File "C:/Users/quaer/Dropbox/Trade/AlgoStocks/runLive.py", line 27, in main cerebro.run() File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\cerebro.py", line 1127, in run runstrat = self.runstrategies(iterstrat) File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\cerebro.py", line 1298, in runstrategies self._runnext(runstrats) File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\cerebro.py", line 1630, in _runnext strat._next() File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\strategy.py", line 347, in _next super(Strategy, self)._next() File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\lineiterator.py", line 275, in _next self.prenext() File "C:\Users\quaer\Dropbox\Trade\AlgoStocks\Strat\MyStratLive.py", line 105, in prenext self.next(frompre=True) File "C:\Users\quaer\Dropbox\Trade\AlgoStocks\Strat\MyStratLive.py", line 200, in next self.long_parent_order = self.buy(exectype=bt.Order.Market, size=exe_size, transmit=False, valid=60) File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\strategy.py", line 933, in buy return self.broker.buy( File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\brokers\ibbroker.py", line 379, in buy return self.submit(order) File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\brokers\ibbroker.py", line 337, in submit self.ib.placeOrder(order.m_orderId, order.data.tradecontract, order) File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\stores\ibstore.py", line 1300, in placeOrder self.conn.placeOrder(orderid, contract, order) File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\ib\lib\__init__.py", line 60, in inner return func(*args, **kwds) File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\ib\ext\EClientSocket.py", line 1155, in placeOrder self.error_0(id, EClientErrors.FAIL_SEND_ORDER, str(e)) File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\ib\lib\__init__.py", line 60, in inner return func(*args, **kwds) File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\ib\ext\EClientSocket.py", line 1709, in error_0 self.m_anyWrapper.error(id, errorCode, errorMsg) File "C:\Users\quaer\AppData\Local\Programs\Python\Python38\lib\site-packages\ib\lib\overloading.py", line 82, in __call__ return func(*args) TypeError: error() takes 2 positional arguments but 4 were given
Any help much appreciated!
thanks.