IB API HOWTOs and Guidelines - For Beginners

[/code]The Output will be something like this:
Server Version: 59
TWS Time at connection:20131109 22:01:26 ICT
IB: OrderID =
>>> 4
IB: Server Response = nextValidId <nextValidId orderId=4>
IB: Server Response = error <error id=5, errorCode=399, errorMsg=Order Message:
Warning: your order will not be placed at the exchange until 2013-11-11 09:30:00 US/Eastern>
IB: Server Response = openOrder <openOrder orderId=5, contract=<ib.ext.Contract.Contract object at 0x012C3C90>, order=<ib.ext.Order.Order object at 0x012C3BB0>,
orderState=<ib.ext.OrderState.OrderState object at 0x012C3A50>>
IB: Server Response = orderStatus <orderStatus orderId=5, status=PreSubmitted, filled=0, remaining=100,
avgFillPrice=0.0, permId=XXXXXX, parentId=0, lastFillPrice=0.0, clientId=123, whyHeld=None>
Butterfly, now that we've got an orderStatus response from IB, how can I cancel/replace an order only if its filled=0. I was hoping for an example of code for changing a price. You said in the first few posts that what we did with the IB responses is what makes the difference in an effective ATS. I hope you haven't given up on this thread as its the most helpful in explaining and providing simple examples I've seen anywhere. GnM
 
Butterfly, now that we've got an orderStatus response from IB, how can I cancel/replace an order only if its filled=0. I was hoping for an example of code for changing a price. You said in the first few posts that what we did with the IB responses is what makes the difference in an effective ATS. I hope you haven't given up on this thread as its the most helpful in explaining and providing simple examples I've seen anywhere. GnM

If not filled, you simply place again the order using the same order ID. Price (and entire order) will be updated accordingly.
 
If not filled, you simply place again the order using the same order ID. Price (and entire order) will be updated accordingly.

Thanks, appreciate all responses. But I am asking how my algorithm can get the "filled=0" field from the IB message into the code (as a variable or object....) so it can deal with it. Remember this is about developing an ATS and some of us really are beginners in programming.
 
Thanks, appreciate all responses. But I am asking how my algorithm can get the "filled=0" field from the IB message into the code (as a variable or object....) so it can deal with it. Remember this is about developing an ATS and some of us really are beginners in programming.

For each placed order the "filled so far" quantity is received periodically by the "AxTws1.orderStatus" event; signature:

Tws_orderStatus(ByVal Sender As Object, ByVal e As AxTWSLib._DTwsEvents_orderStatusEvent)

along with other crucial realtime info, such as:

e.id
e.status
e.filled
e.remaining
e.clientId
e.permId
e.avgFillPrice
e.lastFillPrice
...
etc.
 
I figured it out and because I'm not a total douche here is what I did:

Code:
def print_orderstatus(msg):
    global fillStatus
    if msg.filled == 0  and msg.orderId==NextOrderId:
        fillStatus = 'NextOrderId=',msg.orderId,'filled=',msg.filled
        print 'FillStatus =', fillStatus
if __name__ == '__main__':
    
    con = ibConnection(port=7496,clientId=1234)
    con.registerAll(watcher)
    con.register(NextValidIdHandler, 'NextValidId')
    con.register(ContractDetailsHandler, 'ContractDetails')
    con.register(error_handler, 'Error')
    con.register(print_orderstatus, 'OrderStatus')
Of course, this will only work once an order has been placed.
 
I figured it out and because I'm not a total douche here is what I did:

Code:
def print_orderstatus(msg):
    global fillStatus
    if msg.filled == 0  and msg.orderId==NextOrderId:
        fillStatus = 'NextOrderId=',msg.orderId,'filled=',msg.filled
        print 'FillStatus =', fillStatus
if __name__ == '__main__':
    
    con = ibConnection(port=7496,clientId=1234)
    con.registerAll(watcher)
    con.register(NextValidIdHandler, 'NextValidId')
    con.register(ContractDetailsHandler, 'ContractDetails')
    con.register(error_handler, 'Error')
    con.register(print_orderstatus, 'OrderStatus')
Of course, this will only work once an order has been placed.
Actually, this works only once but doesn't update the fillStatus variable every time an OrderStatus message is sent from IB. I looked at it's type and saw it was a tuple (immuttable) so I tried to define as a list and a dict but it still would not update on each new message (and you know IB sends lots of those). If anyone has a technique for this I'd be interested in learning. :confused:
 
Actually, this works only once but doesn't update the fillStatus variable every time an OrderStatus message is sent from IB. I looked at it's type and saw it was a tuple (immuttable) so I tried to define as a list and a dict but it still would not update on each new message (and you know IB sends lots of those). If anyone has a technique for this I'd be interested in learning. :confused:

This approach will send order status through the orderStatus() method whenever it changes. No registering callbacks just simple subclassing
 
This approach will send order status through the orderStatus() method whenever it changes. No registering callbacks just simple subclassing

Thanks for the link. It certainly looks possible, however, for a beginner in programming what you sent is like trying to take a sip of water from a firehose. Other, more specific help on how to implement this into my code is welcome, thanks. Until then I'll keep studying methods, modules and classes and see if it all comes together. GnM
 
Thanks for the link. It certainly looks possible, however, for a beginner in programming what you sent is like trying to take a sip of water from a firehose. Other, more specific help on how to implement this into my code is welcome, thanks. Until then I'll keep studying methods, modules and classes and see if it all comes together. GnM

Here's a bare bones order status execution reporter you can run from commandline. You can run it, hit 'm' key and enter, place orders, see those orders in command prompt.

maybe your problem was that you need to use reqAutoOpenOrders() and have clientID=0
 
Back
Top