atreyuxtrading / atreyu-backtrader-api Goto Github PK
View Code? Open in Web Editor NEWAtreyu's integration of IB Native API with backtrader
License: BSD 2-Clause "Simplified" License
Atreyu's integration of IB Native API with backtrader
License: BSD 2-Clause "Simplified" License
As we all known, TWS/IBG restarts everyday, now, on the latest versions the session token lasts for a week so you don't have to enter username/password. What I am struggling to make it work, on the restart, is the live data when the IB Gateway restarts.
Looking at the code, the msg=-504 is well recognized, however, there is no way to resuscribe to the live data feed. Tried many things but there is no way to take it back.
Thanks
I'm trying to test the example codes but no matter what it keeps returning.
Error: {'reqId': 16777217, 'errorCode': 354, 'errorString': 'Requested market data is not subscribed.Delayed market data is available.Error&BEST/STK/Top&BEST/STK/Top', 'advancedOrderRejectJson': ''}
Looks like the TWS API for cancelling orders has changed - I get the following error when running in a Paper Trading Environment when I try to cancel orders:
File "/usr/local/lib/python3.10/site-packages/backtrader/strategy.py", line 772, in cancel
self.broker.cancel(order)
File "/usr/local/lib/python3.10/site-packages/atreyu_backtrader_api-0.1.0-py3.10.egg/atreyu_backtrader_api/ibbroker.py", line 324, in cancel
File "/usr/local/lib/python3.10/site-packages/atreyu_backtrader_api-0.1.0-py3.10.egg/atreyu_backtrader_api/ibstore.py", line 1993, in cancelOrder
TypeError: EClient.cancelOrder() missing 1 required positional argument: 'manualCancelOrderTime'
File ~/anaconda3/lib/python3.9/site-packages/atreyu_backtrader_api-0.1.0-py3.9.egg/atreyu_backtrader_api/ibbroker.py:358 in submit
order.ocaGroup = self.orderbyid[order.oco.orderId].ocaGroup
AttributeError: 'int' object has no attribute 'orderId'
Exception: 'Execution' object has no attribute 'OrderId'
Traceback (most recent call last):
File "/home/tim/anaconda3/lib/python3.9/site-packages/atreyu_backtrader_api-0.1.0-py3.9.egg/atreyu_backtrader_api/ibbroker.py", line 520, in push_commissionreport
oid = ex.OrderId
AttributeError: 'Execution' object has no attribute 'OrderId'
ExecId: 0000e1a7.641848b4.01.01, Commission: 0.770000, Currency: USD, RealizedPnL: , Yield: , YieldRedemptionDate: 0
Hey Atreyu trading,
Great library, thanks for integrating with original TWS API. Very clean code. However, there still seems to be a glitch with threading. Running the sample from the readme that has more than one symbol doesn't work for me. If first data is GOOG, then it retrieves a batch with Google historical data, as I can see with debug set to True, but then hangs and never gets the response for the AAPL request. If change the order in the code, then I get the AAPL data, but no GOOG data.
Thanks
Reinke
Below is the output in debug mode from your example (I ran it with AMZN instead of AAPL, but result is the same):
Calling connectAck()
Calling managedAccounts('DUXXXXXX')
Calling reqCurrentTime()
Calling nextValidId(1)
Calling error(-1, 2104, 'Market data farm connection is OK:hfarm')
Calling error(-1, 2104, 'Market data farm connection is OK:eufarmnj')
Calling error(-1, 2104, 'Market data farm connection is OK:cashfarm')
Calling error(-1, 2104, 'Market data farm connection is OK:usfuture')
Calling error(-1, 2104, 'Market data farm connection is OK:jfarm')
Calling error(-1, 2104, 'Market data farm connection is OK:usfarm.nj')
Calling error(-1, 2104, 'Market data farm connection is OK:eufarm')
Calling error(-1, 2104, 'Market data farm connection is OK:usfarm')
Calling error(-1, 2106, 'HMDS data farm connection is OK:euhmds')
Calling error(-1, 2106, 'HMDS data farm connection is OK:ushmds.nj')
Calling error(-1, 2106, 'HMDS data farm connection is OK:cashhmds')
Calling error(-1, 2106, 'HMDS data farm connection is OK:fundfarm')
Calling error(-1, 2106, 'HMDS data farm connection is OK:ushmds')
Calling error(-1, 2158, 'Sec-def data farm connection is OK:secdefnj')
Calling currentTime(1663164990)
Calling contractDetails(16777216, 140192311566224: 3691937,AMZN,STK,,0.0,,,SMART,NASDAQ,USD,AMZN,NMS,False,,combo:,NMS,0.01,ACTIVETIM,AD,ADJUST,ALERT,ALGO,ALLOC,AON,AVGCOST,BASKET,BENCHPX,CASHQTY,COND,CONDORDER,DARKONLY,DARKPOLL,DAY,DEACT,DEACTDIS,DEACTEOD,DIS,DUR,GAT,GTC,GTD,GTT,HID,IBKRATS,ICE,IMB,IOC,LIT,LMT,LOC,MIDPX,MIT,MKT,MOC,MTL,NGCOMB,NODARK,NONALGO,OCA,OPG,OPGREROUT,PEGBENCH,PEGMID,POSTATS,POSTONLY,PREOPGRTH,PRICECHK,REL,REL2MID,RELPCTOFS,RPI,RTH,SCALE,SCALEODD,SCALERST,SIZECHK,SMARTSTG,SNAPMID,SNAPMKT,SNAPREL,STP,STPLMT,SWEEP,TRAIL,TRAILLIT,TRAILLMT,TRAILMIT,WHATIF,SMART,AMEX,NYSE,CBOE,PHLX,ISE,CHX,ARCA,ISLAND,DRCTEDGE,BEX,BATS,EDGEA,CSFBALGO,JEFFALGO,BYX,IEX,EDGX,FOXRIVER,PEARL,NYSENAT,LTSE,MEMX,TPLUS1,PSX,1,0,AMAZON.COM INC,,Communications,Internet,E-Commerce/Products,US/Eastern,20220914:0400-20220914:2000;20220915:0400-20220915:2000;20220916:0400-20220916:2000;20220917:CLOSED;20220918:CLOSED;20220919:0400-20220919:2000,20220914:0930-20220914:1600;20220915:0930-20220915:1600;20220916:0930-20220916:1600;20220917:CLOSED;20220918:CLOSED;20220919:0930-20220919:1600,,0,100,,,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,1,[140192311564448: ISIN=US0231351067;],,COMMON,,,,,,False,False,0,False,,,,,False,)
Calling contractDetailsEnd(16777216)
Calling reqHistoricalDataEx(contract=140192311564496: 3691937,AMZN,STK,,0.0,,,SMART,NASDAQ,USD,AMZN,NMS,False,,combo:, enddate=datetime.datetime(2018, 5, 1, 0, 0), begindate=datetime.datetime(2018, 1, 1, 0, 0), timeframe=5, compression=1, what='TRADES', useRTH=False, tz=None, sessionend=datetime.time(23, 59, 59, 999990))
Calling historicalData(16777217, 140192311562864: Date: 20180102, Open: 58.390000, High: 59.500000, Low: 58.390000, Close: 59.300000, Volume: 362006, Average: 59.214400, BarCount: 10587)
Calling historicalData(16777217, 140192310323872: Date: 20180103, Open: 59.440000, High: 60.270000, Low: 59.330000, Close: 60.150000, Volume: 428208, Average: 59.995700, BarCount: 13522)
Calling historicalData(16777217, 140192310323440: Date: 20180104, Open: 60.400000, High: 60.790000, Low: 60.230000, Close: 60.510000, Volume: 415628, Average: 60.504250, BarCount: 12929)
Calling historicalData(16777217, 140192310324208: Date: 20180105, Open: 60.550000, High: 61.560000, Low: 60.500000, Close: 61.530000, Volume: 482647, Average: 61.088200, BarCount: 14759)
Calling historicalData(16777217, 140192310324064: Date: 20180108, Open: 61.670000, High: 62.650000, Low: 61.500000, Close: 62.360000, Volume: 558346, Average: 62.216000, BarCount: 17556)
Calling historicalData(16777217, 140192310323488: Date: 20180109, Open: 62.410000, High: 62.970000, Low: 62.090000, Close: 62.640000, Volume: 520424, Average: 62.540200, BarCount: 15995)
Calling historicalData(16777217, 140192310324784: Date: 20180110, Open: 62.500000, High: 62.800000, Low: 61.860000, Close: 62.800000, Volume: 379151, Average: 62.417450, BarCount: 11669)
Calling historicalData(16777217, 140192310324352: Date: 20180111, Open: 62.850000, High: 63.900000, Low: 62.820000, Close: 63.890000, Volume: 446149, Average: 63.307650, BarCount: 14075)
Calling historicalData(16777217, 140192310324640: Date: 20180112, Open: 64.100000, High: 65.350000, Low: 63.630000, Close: 65.350000, Volume: 774483, Average: 64.858800, BarCount: 24457)
Calling historicalData(16777217, 140192310324448: Date: 20180116, Open: 65.780000, High: 67.000000, Low: 64.610000, Close: 64.950000, Volume: 1031908, Average: 65.927700, BarCount: 32467)
Calling historicalData(16777217, 140192310318496: Date: 20180117, Open: 65.500000, High: 65.810000, Low: 64.040000, Close: 64.940000, Volume: 752364, Average: 64.770750, BarCount: 22903)
Calling historicalData(16777217, 140192310324928: Date: 20180118, Open: 64.800000, High: 65.230000, Low: 64.200000, Close: 64.700000, Volume: 564736, Average: 64.755350, BarCount: 17042)
Calling historicalData(16777217, 140192310325072: Date: 20180119, Open: 64.890000, High: 65.950000, Low: 64.650000, Close: 64.720000, Volume: 658129, Average: 65.014000, BarCount: 18755)
Calling historicalData(16777217, 140192310325216: Date: 20180122, Open: 64.800000, High: 66.870000, Low: 64.730000, Close: 66.740000, Volume: 566553, Average: 65.753050, BarCount: 16272)
Calling historicalData(16777217, 140192310325360: Date: 20180123, Open: 66.950000, High: 68.290000, Low: 66.560000, Close: 68.060000, Volume: 671661, Average: 67.580900, BarCount: 20338)
Calling historicalData(16777217, 140192310325504: Date: 20180124, Open: 68.250000, High: 69.410000, Low: 66.900000, Close: 67.980000, Volume: 959970, Average: 68.117150, BarCount: 29466)
Calling historicalData(16777217, 140192310325648: Date: 20180125, Open: 68.330000, High: 68.920000, Low: 67.880000, Close: 68.900000, Volume: 665466, Average: 68.507900, BarCount: 20322)
Calling historicalData(16777217, 140192310325792: Date: 20180126, Open: 69.100000, High: 70.340000, Low: 69.040000, Close: 70.320000, Volume: 669755, Average: 69.817500, BarCount: 19615)
Calling historicalData(16777217, 140192310325936: Date: 20180129, Open: 70.400000, High: 71.570000, Low: 70.020000, Close: 70.950000, Volume: 762968, Average: 70.828200, BarCount: 23325)
Calling historicalData(16777217, 140192310326080: Date: 20180130, Open: 70.580000, High: 71.960000, Low: 69.600000, Close: 71.900000, Volume: 777056, Average: 71.013050, BarCount: 24213)
Calling historicalData(16777217, 140192310326224: Date: 20180131, Open: 72.400000, High: 73.630000, Low: 72.200000, Close: 73.150000, Volume: 872497, Average: 72.975200, BarCount: 25801)
Calling historicalData(16777217, 140192310326368: Date: 20180201, Open: 73.420000, High: 74.250000, Low: 69.000000, Close: 73.860000, Volume: 1149704, Average: 71.438850, BarCount: 36877)
Calling historicalData(16777217, 140192310326512: Date: 20180202, Open: 73.590000, High: 74.900000, Low: 70.700000, Close: 71.350000, Volume: 1516359, Average: 72.896650, BarCount: 50362)
Calling historicalData(16777217, 140192310326752: Date: 20180205, Open: 71.050000, High: 72.950000, Low: 66.040000, Close: 68.750000, Volume: 1509764, Average: 70.963950, BarCount: 47544)
Calling historicalData(16777217, 140192310327040: Date: 20180206, Open: 68.700000, High: 72.240000, Low: 67.500000, Close: 72.150000, Volume: 1434275, Average: 70.328850, BarCount: 46821)
Calling historicalData(16777217, 140192310326848: Date: 20180207, Open: 71.770000, High: 73.050000, Low: 70.450000, Close: 70.650000, Volume: 927001, Average: 72.113550, BarCount: 29203)
Calling historicalData(16777217, 140192310326656: Date: 20180208, Open: 71.160000, High: 71.820000, Low: 67.090000, Close: 67.600000, Volume: 1063411, Average: 69.301600, BarCount: 34831)
Calling historicalData(16777217, 140192310327232: Date: 20180209, Open: 67.750000, High: 69.170000, Low: 63.300000, Close: 67.110000, Volume: 1817615, Average: 66.171950, BarCount: 61785)
Calling historicalData(16777217, 140192310327376: Date: 20180212, Open: 67.550000, High: 69.690000, Low: 67.200000, Close: 69.350000, Volume: 829939, Average: 68.645400, BarCount: 25870)
Calling historicalData(16777217, 140192310327520: Date: 20180213, Open: 69.240000, High: 70.990000, Low: 68.750000, Close: 70.800000, Volume: 779296, Average: 70.395150, BarCount: 24080)
Calling historicalData(16777217, 140192310327664: Date: 20180214, Open: 71.100000, High: 72.600000, Low: 70.000000, Close: 72.580000, Volume: 772207, Average: 71.706200, BarCount: 24053)
Calling historicalData(16777217, 140192310327808: Date: 20180215, Open: 73.350000, High: 73.450000, Low: 71.840000, Close: 73.140000, Volume: 752165, Average: 72.935800, BarCount: 23814)
Calling historicalData(16777217, 140192310328288: Date: 20180216, Open: 73.500000, High: 73.550000, Low: 72.330000, Close: 72.340000, Volume: 608836, Average: 72.767300, BarCount: 16914)
Calling historicalData(16777217, 140192310328144: Date: 20180220, Open: 72.010000, High: 74.440000, Low: 71.500000, Close: 73.630000, Volume: 890691, Average: 73.426600, BarCount: 25738)
Calling historicalData(16777217, 140192310327904: Date: 20180221, Open: 73.600000, High: 75.170000, Low: 73.450000, Close: 73.850000, Volume: 834251, Average: 74.559450, BarCount: 26049)
Calling historicalData(16777217, 140192310328384: Date: 20180222, Open: 73.860000, High: 75.130000, Low: 73.790000, Close: 74.460000, Volume: 643798, Average: 74.447750, BarCount: 20040)
Calling historicalData(16777217, 140192310328528: Date: 20180223, Open: 74.750000, High: 75.030000, Low: 74.330000, Close: 75.020000, Volume: 596366, Average: 74.745450, BarCount: 17679)
Calling historicalData(16777217, 140192310328672: Date: 20180226, Open: 75.250000, High: 76.250000, Low: 75.250000, Close: 76.240000, Volume: 682149, Average: 75.852900, BarCount: 19996)
Calling historicalData(16777217, 140192310328816: Date: 20180227, Open: 76.450000, High: 76.450000, Low: 75.360000, Close: 75.800000, Volume: 636656, Average: 75.899650, BarCount: 18741)
Calling historicalData(16777217, 140192310328960: Date: 20180228, Open: 76.000000, High: 76.440000, Low: 75.600000, Close: 75.800000, Volume: 574773, Average: 75.969950, BarCount: 15816)
Calling historicalData(16777217, 140192310329104: Date: 20180301, Open: 76.540000, High: 76.540000, Low: 73.250000, Close: 74.780000, Volume: 881505, Average: 74.710100, BarCount: 28275)
Calling historicalData(16777217, 140192310329248: Date: 20180302, Open: 74.310000, High: 75.150000, Low: 72.750000, Close: 75.140000, Volume: 931552, Average: 74.039400, BarCount: 28693)
Calling historicalData(16777217, 140192310317632: Date: 20180305, Open: 75.180000, High: 76.270000, Low: 74.050000, Close: 76.200000, Volume: 712181, Average: 75.457050, BarCount: 21367)
Calling historicalData(16777217, 140192310317488: Date: 20180306, Open: 76.350000, High: 77.110000, Low: 75.600000, Close: 75.650000, Volume: 617349, Average: 76.778100, BarCount: 18280)
Calling historicalData(16777217, 140192310317344: Date: 20180307, Open: 75.990000, High: 77.300000, Low: 75.900000, Close: 77.200000, Volume: 553375, Average: 76.845050, BarCount: 15820)
Calling historicalData(16777217, 140192310317200: Date: 20180308, Open: 77.250000, High: 77.740000, Low: 77.250000, Close: 77.600000, Volume: 484936, Average: 77.542200, BarCount: 14072)
Calling historicalData(16777217, 140192310317056: Date: 20180309, Open: 77.700000, High: 78.950000, Low: 77.630000, Close: 78.930000, Volume: 617069, Average: 78.462000, BarCount: 18324)
Calling historicalData(16777217, 140192310316912: Date: 20180312, Open: 79.500000, High: 80.270000, Low: 79.110000, Close: 80.000000, Volume: 723762, Average: 79.894750, BarCount: 20471)
Calling historicalData(16777217, 140192310316768: Date: 20180313, Open: 80.000000, High: 80.900000, Low: 78.900000, Close: 79.210000, Volume: 867711, Average: 79.798800, BarCount: 27325)
Calling historicalData(16777217, 140192310316624: Date: 20180314, Open: 80.000000, High: 80.320000, Low: 79.540000, Close: 79.740000, Volume: 566616, Average: 79.879600, BarCount: 18074)
Calling historicalData(16777217, 140192310316480: Date: 20180315, Open: 79.900000, High: 80.000000, Low: 78.910000, Close: 79.350000, Volume: 546749, Average: 79.202000, BarCount: 18714)
Calling historicalData(16777217, 140192310316336: Date: 20180316, Open: 79.250000, High: 79.500000, Low: 78.380000, Close: 78.580000, Volume: 726484, Average: 78.789950, BarCount: 18210)
Calling historicalData(16777217, 140192310316192: Date: 20180319, Open: 77.420000, High: 78.750000, Low: 76.270000, Close: 77.000000, Volume: 827655, Average: 77.130500, BarCount: 28198)
Calling historicalData(16777217, 140192310316048: Date: 20180320, Open: 77.460000, High: 79.550000, Low: 77.250000, Close: 79.530000, Volume: 595279, Average: 78.469950, BarCount: 18875)
Calling historicalData(16777217, 140192310315904: Date: 20180321, Open: 79.400000, High: 79.530000, Low: 78.160000, Close: 79.000000, Volume: 650365, Average: 78.998300, BarCount: 19522)
Calling historicalData(16777217, 140192310315760: Date: 20180322, Open: 78.640000, High: 78.700000, Low: 75.910000, Close: 76.350000, Volume: 778647, Average: 77.753700, BarCount: 24433)
Calling historicalData(16777217, 140192310315616: Date: 20180323, Open: 76.430000, High: 77.450000, Low: 74.690000, Close: 74.750000, Volume: 1005688, Average: 75.934250, BarCount: 31117)
Calling historicalData(16777217, 140192310315472: Date: 20180326, Open: 75.550000, High: 78.000000, Low: 74.960000, Close: 78.000000, Volume: 724545, Average: 76.628750, BarCount: 21907)
Calling historicalData(16777217, 140192310315328: Date: 20180327, Open: 78.650000, High: 78.800000, Low: 74.120000, Close: 75.500000, Volume: 871486, Average: 76.945250, BarCount: 26807)
Calling historicalData(16777217, 140192310315184: Date: 20180328, Open: 74.200000, High: 75.500000, Low: 69.310000, Close: 71.350000, Volume: 1734968, Average: 71.314800, BarCount: 57774)
Calling historicalData(16777217, 140192310315040: Date: 20180329, Open: 71.390000, High: 72.770000, Low: 68.260000, Close: 72.300000, Volume: 1691011, Average: 70.868850, BarCount: 52600)
Calling historicalData(16777217, 140192310314896: Date: 20180402, Open: 71.810000, High: 71.810000, Low: 67.750000, Close: 68.250000, Volume: 1295412, Average: 69.065650, BarCount: 41786)
Calling historicalData(16777217, 140192310314752: Date: 20180403, Open: 68.650000, High: 70.700000, Low: 67.770000, Close: 69.250000, Volume: 1347075, Average: 69.182950, BarCount: 44297)
Calling historicalData(16777217, 140192310314608: Date: 20180404, Open: 68.100000, High: 70.940000, Low: 67.310000, Close: 70.900000, Volume: 916870, Average: 69.239700, BarCount: 28747)
Calling historicalData(16777217, 140192310314464: Date: 20180405, Open: 71.550000, High: 72.980000, Low: 70.650000, Close: 71.000000, Volume: 833907, Average: 72.251950, BarCount: 27169)
Calling historicalData(16777217, 140192310314320: Date: 20180406, Open: 71.580000, High: 72.630000, Low: 70.010000, Close: 70.250000, Volume: 768701, Average: 71.229150, BarCount: 24097)
Calling historicalData(16777217, 140192310314176: Date: 20180409, Open: 71.040000, High: 71.920000, Low: 70.050000, Close: 70.250000, Volume: 544898, Average: 71.179050, BarCount: 16984)
Calling historicalData(16777217, 140192310314032: Date: 20180410, Open: 71.250000, High: 71.920000, Low: 70.790000, Close: 71.760000, Volume: 544186, Average: 71.422200, BarCount: 16328)
Calling historicalData(16777217, 140192310313888: Date: 20180411, Open: 71.600000, High: 72.440000, Low: 71.080000, Close: 71.670000, Volume: 463640, Average: 71.835600, BarCount: 13292)
Calling historicalData(16777217, 140192310313744: Date: 20180412, Open: 71.440000, High: 72.610000, Low: 71.440000, Close: 72.280000, Volume: 415622, Average: 72.328750, BarCount: 12676)
Calling historicalData(16777217, 140192310313600: Date: 20180413, Open: 72.010000, High: 72.990000, Low: 71.230000, Close: 71.650000, Volume: 488615, Average: 72.079900, BarCount: 14075)
Calling historicalData(16777217, 140192310313456: Date: 20180416, Open: 71.700000, High: 72.500000, Low: 71.370000, Close: 72.450000, Volume: 355231, Average: 71.941000, BarCount: 11875)
Calling historicalData(16777217, 140192310313312: Date: 20180417, Open: 72.550000, High: 75.460000, Low: 72.550000, Close: 75.400000, Volume: 675998, Average: 74.309250, BarCount: 21354)
Calling historicalData(16777217, 140192310313168: Date: 20180418, Open: 75.550000, High: 77.900000, Low: 75.210000, Close: 77.700000, Volume: 677134, Average: 76.139750, BarCount: 21940)
Calling historicalData(16777217, 140192310313072: Date: 20180419, Open: 77.990000, High: 78.430000, Low: 76.950000, Close: 78.070000, Volume: 814515, Average: 77.721150, BarCount: 26674)
Calling historicalData(16777217, 140192310322000: Date: 20180420, Open: 77.500000, High: 78.290000, Low: 75.800000, Close: 76.630000, Volume: 711019, Average: 76.950400, BarCount: 22029)
Calling historicalData(16777217, 140192310322144: Date: 20180423, Open: 76.600000, High: 77.400000, Low: 75.170000, Close: 76.150000, Volume: 592521, Average: 76.323850, BarCount: 17659)
Calling historicalData(16777217, 140192310322288: Date: 20180424, Open: 76.450000, High: 76.980000, Low: 72.420000, Close: 73.280000, Volume: 1004716, Average: 73.822900, BarCount: 32606)
Calling historicalData(16777217, 140192310322432: Date: 20180425, Open: 73.130000, High: 74.400000, Low: 70.750000, Close: 74.320000, Volume: 877031, Average: 72.399000, BarCount: 28898)
Calling historicalData(16777217, 140192310322576: Date: 20180426, Open: 74.250000, High: 82.050000, Low: 73.920000, Close: 80.900000, Volume: 1023704, Average: 76.403850, BarCount: 33547)
Calling historicalData(16777217, 140192310322720: Date: 20180427, Open: 80.360000, High: 83.240000, Low: 78.300000, Close: 78.400000, Volume: 1617421, Average: 79.796450, BarCount: 53245)
Calling historicalData(16777217, 140192310421360: Date: 20180430, Open: 79.250000, High: 79.800000, Low: 78.050000, Close: 78.580000, Volume: 691444, Average: 78.816600, BarCount: 20803)
Calling historicalDataEnd(16777217, '20180101 08:00:00', '20180501 08:00:00')
Calling contractDetails(16777218, 140192311564688: 208813720,GOOG,STK,,0.0,,,SMART,NASDAQ,USD,GOOG,NMS,False,,combo:,NMS,0.01,ACTIVETIM,AD,ADJUST,ALERT,ALGO,ALLOC,AON,AVGCOST,BASKET,BENCHPX,CASHQTY,COND,CONDORDER,DARKONLY,DARKPOLL,DAY,DEACT,DEACTDIS,DEACTEOD,DIS,DUR,GAT,GTC,GTD,GTT,HID,IBKRATS,ICE,IMB,IOC,LIT,LMT,LOC,MIDPX,MIT,MKT,MOC,MTL,NGCOMB,NODARK,NONALGO,OCA,OPG,OPGREROUT,PEGBENCH,PEGMID,POSTATS,POSTONLY,PREOPGRTH,PRICECHK,REL,REL2MID,RELPCTOFS,RPI,RTH,SCALE,SCALEODD,SCALERST,SIZECHK,SMARTSTG,SNAPMID,SNAPMKT,SNAPREL,STP,STPLMT,SWEEP,TRAIL,TRAILLIT,TRAILLMT,TRAILMIT,WHATIF,SMART,AMEX,NYSE,CBOE,PHLX,ISE,CHX,ARCA,ISLAND,DRCTEDGE,BEX,BATS,EDGEA,CSFBALGO,JEFFALGO,BYX,IEX,EDGX,FOXRIVER,PEARL,NYSENAT,LTSE,MEMX,TPLUS1,PSX,1,0,ALPHABET INC-CL C,,Communications,Internet,Web Portals/ISP,US/Eastern,20220914:0400-20220914:2000;20220915:0400-20220915:2000;20220916:0400-20220916:2000;20220917:CLOSED;20220918:CLOSED;20220919:0400-20220919:2000,20220914:0930-20220914:1600;20220915:0930-20220915:1600;20220916:0930-20220916:1600;20220917:CLOSED;20220918:CLOSED;20220919:0930-20220919:1600,,0,100,,,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,1,[140192311564592: ISIN=US02079K1079;],,COMMON,,,,,,False,False,0,False,,,,,False,)
Calling contractDetailsEnd(16777218)
Calling reqHistoricalDataEx(contract=140192311564640: 208813720,GOOG,STK,,0.0,,,SMART,NASDAQ,USD,GOOG,NMS,False,,combo:, enddate=datetime.datetime(2018, 5, 1, 0, 0), begindate=datetime.datetime(2018, 1, 1, 0, 0), timeframe=5, compression=1, what='TRADES', useRTH=False, tz=None, sessionend=datetime.time(23, 59, 59, 999990))
Calling connectionClosed()
Final Portfolio Value: 100000.00
data = IBData(host='127.0.0.1', port=7497, clientId=2, name="GOOG", # Data name dataname='GOOG', # Symbol name secType='STK', # SecurityType is STOCK exchange='SMART',# Trading exchange IB's SMART exchange currency='USD', # Currency of SecurityType fromdate = dt.datetime(2016, 1, 1), todate = dt.datetime(2018, 1, 1), historical=True, what='TRADES', )
The code will hang on there on second run if clientId is not changed
tws api doesn't provide wap anymore?
AttributeError: 'BarData' object has no attribute 'wap'
I'm just getting things up and running here - but it seems like maybe the example code is out of date?
After setting up the environment and testing my connections, executing a python script with the following IBData object:
data = IBData(host='127.0.0.1', port=7497, clientId=35,
name="GOOG", # Data name
dataname='GOOG', # Symbol name
secType='STK', # SecurityType is STOCK
exchange='SMART',# Trading exchange IB's SMART exchange
currency='USD', # Currency of SecurityType
what='BID_ASK', # Get data fields (see note below)
rtbar=True, # Request Realtime bars
_debug=True # Set to True to print out debug messagess from IB TWS API
)
Results in a stream of 321 errors from the TWS API Client complaining about the 'What to show field':
Calling reqRealTimeBars(4557295888: 208813720,GOOG,STK,,0,,,SMART,NASDAQ,USD,GOOG,NMS,False,,,,combo:, what='BID_ASK')
Calling error(16780436, 321, "Error validating request.-'bY' : cause - What to show field is missing or incorrect.", '')
{'reqId': 16780436, 'errorCode': 321, 'errorString': "Error validating request.-'bY' : cause - What to show field is missing or incorrect.", 'advancedOrderRejectJson': ''}
Error: {'reqId': 16780436, 'errorCode': 321, 'errorString': "Error validating request.-'bY' : cause - What to show field is missing or incorrect.", 'advancedOrderRejectJson': ''}
Cancel data queue for 16780436
Should the 'what' field maybe be 'TRADES' instead of 'BID_ASK'?
Trying to run TestStrategy in paper trading mode. I can get data if ibstore.getbroker()
is not run, otherwise the following error appears. Would be grateful for any help!
File "/Users/stefan/strategies/come_on/at_api_test_live.py", line 134, in <module> cerebro.run() File "/Users/stefan/strategies/.venv/lib/python3.9/site-packages/backtrader/cerebro.py", line 1127, in run runstrat = self.runstrategies(iterstrat) File "/Users/stefan/strategies/.venv/lib/python3.9/site-packages/backtrader/cerebro.py", line 1187, in runstrategies self._broker.start() File "/Users/stefan/strategies/.venv/lib/python3.9/site-packages/atreyu_backtrader_api-0.1.0-py3.9.egg/atreyu_backtrader_api/ibbroker.py", line 288, in start File "/Users/stefan/strategies/.venv/lib/python3.9/site-packages/atreyu_backtrader_api-0.1.0-py3.9.egg/atreyu_backtrader_api/ibstore.py", line 2050, in reqAccountUpdates IndexError: list index out of range
Hi, I'm following the example TestPrinter, and I'm unable to print the output.
I just get this object printed as the output:
[<main.TestStrategy at 0x122e96450>]
I'm doing something very basically wrong here?
Thanks
Hi,
I am following this tutorial to simply try to print some live data from TWS
As result I get the following error
Error: {'reqId': 16777217, 'errorCode': 10314, 'errorString': 'End Date/Time: The date, time, or time-zone entered is invalid. The correct format is yyyymmdd hh:mm:ss xx/xxxx where yyyymmdd and xx/xxxx are optional. E.g.: 20031126 15:59:00 US/Eastern Note that there is a space between the date and time, and between the time and time-zone. If no date is specified, current date is assumed. If no time-zone is specified, local time-zone is assumed(deprecated). You can also provide yyyymmddd-hh:mm:ss time is in UTC. Note that there is a dash between the date and time in UTC notation.', 'advancedOrderRejectJson': ''}
Is there a way to overcome it? Look's like requests need a different time zone specification as discussed here
What would be the simplest way to solve this issue?
Thanks
Hi, Atreyutrading:
when i run following code on Jupyter Notebook:
from atreyu_backtrader_api import IBData
It shows following error message, can you take a look? thanks a lot
Traceback (most recent call last):
File ~\anaconda3\lib\site-packages\IPython\core\interactiveshell.py:3398 in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
Input In [14] in <cell line: 1>
import backtrader as bt
File ~\anaconda3\lib\site-packages\backtrader_init_.py:62 in
from .cerebro import *
File ~\anaconda3\lib\site-packages\backtrader\cerebro.py:35 in
from .brokers import BackBroker
File ~\anaconda3\lib\site-packages\backtrader\brokers_init_.py:30 in
from .ibbroker import IBBroker
File ~\anaconda3\lib\site-packages\backtrader\brokers\ibbroker.py:30 in
import ib.ext.Order
File ~\anaconda3\lib\site-packages\ib\ext\Order.py:9 in
from ib.lib import Double, Integer
File ~\anaconda3\lib\site-packages\ib\lib_init_.py:239
except (socket.error, ), ex:
^
SyntaxError: invalid syntax
Also having a problem with the historical quote example. In this case:
data = IBData(host='127.0.0.1', port=7497, clientId=35,
name="GOOG", # Data name
dataname='GOOG', # Symbol name
secType='STK', # SecurityType is STOCK
exchange='SMART',# Trading exchange IB's SMART exchange
currency='USD', # Currency of SecurityType
historical=True,
what='BID_ASK', # Update this parameter to select data type
)
Is returning the following error on execution:
Error: {'reqId': 16777217, 'errorCode': 10314, 'errorString': 'End Date/Time: The date, time, or time-zone entered is invalid. The correct format is yyyymmdd hh:mm:ss xx/xxx where yyyymmdd and xx/xxx are optional. E.g.: 20031126 15:59:00 US/Eastern Note that there is a space between the date and time, and between the time and time-zone. If no date is specified, current date is assumed. If no time-zone is specified, local time-zone is assumed(deprecated). You can also provide yyyymmddd-hh:mm:ss time is in UTC. Note that there is a dash between the date and time in UTC notation.', 'advancedOrderRejectJson': ''}
Hi atreyu and thanks for this great adaptation for backtrader.
I am playing with your library for one of my projects that involve IB and backtrader, and I am not able to backfill my indicators (simple RSI and MACD) resampling data from rtbars to 1 min data. If no indicator is used, the library works perfectly. Is this supported?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.