Komnomnomnom / swigibpy

Third party Interactive Brokers Python API generated from TWS C++ API using SWIG.
http://github.com/Komnomnomnom/swigibpy/
Other
157 stars 35 forks source link

AlgoParams not working #7

Closed Komnomnomnom closed 11 years ago

Komnomnomnom commented 12 years ago

Received via Email.

I have been successfully using swigibpy for a while but I now I would like to place an Algo order and I am not sure how to pass the TagValue list to algoParams property of Order Class

I have tried the following:

contract = Contract()
order = Order()
contract.exchange ='SMART'
contract.symbol =  'MSFT'
contract.secType = 'STK'
contract.currency = 'USD'
order.action = 'BUY'
order.totalQuantity = 100
order.orderType = 'LMT'
order.algoStrategy = 'ArrivalPx'
order.lmtPrice =  0.14

Tried:


order.algoParams.append(TagValue('maxPctVol','0.01'))
---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
/home/mauro/pytrader.dev/<ipython-input-15-2f2429c364fd> in <module>()
----> 1 order.algoParams.append(TagValue('maxPctVol','0.01'))

SystemError: error return without exception set

Tried:

order.algoParams.append(TagValue('maxPctVol','0.01').this)
order.algoParams.append(TagValue('riskAversion','Aggressive').this)
order.algoParams.append(TagValue('startTime','9:00:00 EST').this)
order.algoParams.append(TagValue('endTime','15:00:00 EST').this)
order.algoParams.append(TagValue('forceCompletion','1').this)
order.algoParams.append(TagValue('allowPastEndTime','1').this)

and seems to go ok, but when placing the order I get: "Algo attributes validation failed: 'Max Percentage' is invalid: value is required" So obviously, the attributes are not being set ..

Komnomnomnom commented 12 years ago

This is turning out to be a bit complicated unfortunately, because the algoParams attribute in the C++ API uses a shared_ptr

shared_ptr< std::vector< shared_ptr<TagValue> > > algoParams;

I'm still investigating if SWIG can properly generate a Python wrapper for this.

Komnomnomnom commented 11 years ago

Latest master code should now support this. See updated placeorder.py example.