TWS Internetconnection

Discussion in 'Automated Trading' started by Iljah, Apr 8, 2008.

  1. Iljah


    Hi at all,

    can someone tell me the way to find out, when TWS lost the internet connection? I can't find any method in the api.
  2. You can use error codes from the errMsg() Event. You don't have to call a Method first.

    void errMsg(long id, long errorCode, String errorMsg)

    id- this is the orderId or tickerId of the request that generated the error

    errorCode - error codes are documented in the Error Codes topic.

    errorString - this is the textual description of the error, also documented in the Error Codes topic.

    This event is called when there is an error with the communication or when TWS wants to send a message to the client.

    Warning Message Codes


    New account data requested from TWS. API client has been unsubscribed from account data.

    Unable to subscribe to account as the following clients are subscribed to a different account.

    Unable to modify this order as it is still being processed.

    A market data farm is disconnected.

    A market data farm is connected.

    A historical data farm is disconnected.

    A historical data farm is connected.

    A historical data farm connection has become inactive but should be available upon demand.

    A market data farm connection has become inactive but should be available upon demand.

    Order Event Warning: Attribute 'Outside Regular Trading Hours' is ignored based on the order type and destination. PlaceOrder is now processed.
  3. Iljah


    Hi all,

    this question is a reply becaus i couldn't start a new thread. However:

    I've written a framework to implement strategys for automated trading, using Java and the TWS API. Till now trading works fine on the paper trading account (still testing and debugging), even for several days with automatic reconnect and all those features. But I've sent each order (trading forex pairs) to the TWS like "fire and forget". This means I calculated the commission on my own, based on the actual bid or ask. Since orders in my "dimension" are always filled.

    Now: To improve my work I currently add the handling of incoming order messages and got a few questions.

    The TWS calls these three functions:

    openOrder() - contains the ID and the order state with: OrderStatus, Commission (Min, Max, Total, Currency) and some more
    orderStatus() - contains the ID and the order state, avg fill price and some more
    execDetails() - contains the ID and an execution with another orderid, avg fill price, cumulative quantity

    This leads me to the following questions:

    1) Why is there such a large redundancy with avg fill prices, quantitys etc.
    2) The orderId of the execDetails is -1. The orderId in the Execution-Object ist correctly mapped to my reffering order. Why ?
    3) The min AND max commission is (in my last order) stated with: 1.7976931348623157E308. Why? I would think +inf and -inf. But both +?
    4) I traded Eur.Jpy and the last orderStatus call gave me a commission of 2.5 with a currency JPY. But the trade was to small. Thus the 2.5 is the min commission in USD. Is the currency always in USD? Or just in USD if its below the minimum?? Or even random? ;)

    It is not that easy to get the most important and reliable information out of them. Any instructions or experiences would be great.

    With regards,