IB API HOWTOs and Guidelines - For Beginners

2rosy, you are correct. I do not know why there isn't just a reqOrderStatus() function. But I thought the client ID needed to unique. Now that I look at it, it looks like clientID should be 0 for the API orders with a unique orderId (incremented) and for TWS orders the orderId is 0 and clientId is any number other than zero. From IB:

reqAutoOpenOrders()

Call this method to request that newly created TWS orders be implicitly associated with the client. When a new TWS order is created, the order will be associated with the client and automatically fed back through the openOrder() and orderStatus() methods on the EWrapper.
Note: TWS orders can only be bound to clients with a clientId of 0.
void reqAutoOpenOrders(boolean bAutoBind)
 
I am trying to download historical data via rs43/ib-csharp
For example. Until 8 am EST today, I could get hist data using daily bars only till 28th. after 8 am, i can get till 29th.
Would the historical data skip a day?
Not sure where i was doing it wrong.
 
Below, I read something about timer based vs event driven based algo trading. In my opinion, the event driven algo is the way to go. Simply put, if nothing changes that may influence the algo, then why bother to re-evaluate what action to take? Of course, the algo should watch price changes but changes in bid/ask levels are just as important because those really determine what the traded security is worth.

From my experience, the (Java) IB API is meant to be used in an event driven way. Waiting loops with delays is bad practice in my view. If you really want to do something every certain time interval, you could add some sort of 'internal event' to the general event stream to wake up the algo.
 
Great thread and content. Had fun reading it. Joined ET new. I use another broker api now, but reminds me of the days of using the IB api. I will chime in where I can of help. Hello all
 
Great thread and content. Had fun reading it. Joined ET new. I use another broker api now, but reminds me of the days of using the IB api. I will chime in where I can of help. Hello all

glad you liked it, the code is really for demonstration, but as you can see it's quite simple

there is the issue of "OOP" vs "Process" programming. Many developers are only taught OOP these days, so they are lost when they have to deal with flow of information and process flow type of programming. OOP makes sense for "events" and managing objects visually. With data feeds and trader order flows, OOP is actually counter-productive and against the idea of Object Oriented Programming. Only HFT programming should be done in OOP, because of the events nature of the trade.

I keep being amazed by the level of incompetence from developers these days, they seem to be quite clueless and very "narrow" minded. They can do one trick and that's it.
 
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

Hi there,

sorry for the slow response, for some reasons ET was no longer sending me alerts when this thread was updated or when I received PM. Must be the new forum software.

To answer your question, you need to re-submit the same order object with the modified price or shares with the exact same order_id you created for submission to IB Queue Server. This means that you need to keep track of your orderID attached to the trade order. In case you don't track those order_id locally in your code, you can always ask IB Server for the "OpenOrders" and it will send the securities with price and shares attached to each order_id. I hope it sounds clear, it not let me know.

See below for an example to change the current price for an existing limit order:

Code:
# Create a contract object
# Update the parameters to be sent to the Market Order request
order_ticker = Contract()
order_ticker.m_symbol = 'GTAT'
order_ticker.m_secType = 'STK'
order_ticker.m_exchange = 'SMART'
order_ticker.m_primaryExch = 'SMART'
order_ticker.m_currency = 'USD'
order_ticker.m_localSymbol = 'GTAT'

# Create a new order
# Update the parameters to be sent to the Market Order request
newOrderID=8
order_desc = Order()
order_desc.m_minQty = 100
order_desc.m_lmtPrice = 11.00
order_desc.m_orderType = 'LMT'
order_desc.m_totalQuantity = 100
order_desc.m_action = 'SELL'

# Send the Market Order request
ibgw_conTradeChannel.placeOrder(newOrderID, order_ticker, order_desc)

# Now, change the price of the trade order and re-submit
order_desc.m_lmtPrice = 11.50
ibgw_conTradeChannel.placeOrder(newOrderID, order_ticker, order_desc)

# Here, we change the shares of the trade order and re-submit
order_desc.m_totalQuantity = 150
ibgw_conTradeChannel.placeOrder(newOrderID, order_ticker, order_desc)
 
heres your batch orderloader

not bad in principle and theory, but won't work on a real server, I can see an issue with the nextOrderID and your implementation of the code for IB connection to the MQ server.

Nice try though, but needs a lot of improvement and testing first.
 
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.

to answer your second question, you need to catch the OpenOrder complex objects and assign the "object" for OrderStatus within the complex object to a new "variable" so you can extract the AvgFill or Filled attribute.

I actually did that somewhere on my IB server but didn't publish it here yet. Will find it and try to post it here.
 
here this is how it is done...

Code:
# Define a function to catch "OrderStatus" and "OrderState" type messages from IB Server
def status_orders(msg):
  global ft
  #dump(msg)
  print "Status: ", msg.typeName, msg
  #ft.write("%s [%s] %s\n" % (datetime.datetime.now().strftime("%Y-%m-%d|%T"), msg.typeName, msg))
  ft.write("%s:%s:%s:%s:%s:%s:%s\n" % (msg.typeName, msg.orderId, msg.status, msg.whyHeld, msg.avgFillPrice, msg.filled, msg.remaining))

# Map server replies to "status_orders" function client requests
ibgw_conChannel.register(status_orders, 'OrderStatus','OrderState')

#print "Requesting All Open Orders..."
ibgw_conChannel.reqAllOpenOrders()
 
A quick question:

I have a working Java example using reqMktData that retrieves a quote for a single stock.

I am not yet familiar with the API. What is the best practice for requesting quotes for many contracts, say 100 or 500?

J
 
Back
Top