Trading bot construction (IB)

Discussion in 'Automated Trading' started by doli, Jan 9, 2007.

  1. What if you wanted to monitor 500 stocks in real time ?
     
    #21     Jan 11, 2007
  2. maxpi

    maxpi

    You get Radarscreen from Tradestation, it's been around since 1999.
     
    #22     Jan 11, 2007
  3. doli

    doli

    MGJ: Thanks for the info. I should probably read an intro. statistics book.

    maxpi: I hope to do more than a random trading bot. That's just a start. I am a DIYer. I'd like to use tradestation, but there are months when I don't trade, so IB's $10 data fee is a lot less than the tradestation low activity fee. That could all change if I buy some yen and trade the nikkei 225 -- that market's regular trading hours are right for me.
     
    #23     Jan 11, 2007
  4. doli

    doli

    Something that syswizard mentioned about random entries, then exits at fixed profit/loss points got me thinking. Maybe a random bot should exit at a random time, just to be consistent with its entry at a random time. But I don't want to give up a stop loss order. Maybe it could exit at a random time, if its stop loss wasn't reached before the random time arrives. In my trading I am willing to risk 1% of capital on a trade and no more than 1% of capital on all trades, so I trade only one contract at a time.
     
    #24     Jan 11, 2007
  5. doli

    doli

    Maybe the best solution is to exit at a random time unless either the stop loss or profit target has been reached before the random exit time arrives. That would make treatment of stop/profit targets consistent.
     
    #25     Jan 11, 2007
  6. doli

    doli

    I was reading tradermojo's ATS thread and was trying to form a concept of what a complete ATS is. Here is what I came up with:

    +----------------------------+.....+---------------+....+--------------+
    |- data provider(s)------|<-->|-trader(s)-|<->|-broker(s)--|
    +----------------------------+.....+---------------+....+-------------+

    Trader(s) connect/disconnect from data provider(s).
    Trader(s) submit orders to broker(s) and get order status, account size, etc. from them.
    A trader implements a trading algorithm and manages risk, aside from the other things, mentioned above.

    Working with IB, there is only one broker and one data provider, but are there any reasons why more than one broker and more than one data provider ought to be available to a trader? A data feed might go down, so it's excellent to have an alternative. A broker might go down, so it would be nice to hedge a position that may be on the down broker with a position on one of the brokers still up. There may be other useful scenarios.

    I need to look into a drawing tool -- ET seems to strip out spaces and the font isn't constant width.
     
    #26     Jan 14, 2007
  7. You can use "code" tags to have fixed width font and to preserve spacing etc. More info at bottom of page: http://www.elitetrader.com/vb/misc.php?s=&action=bbcode

    e.g.

    Code:
    Fixed width
    
     
    #27     Jan 14, 2007
  8. doli

    doli

    I'll look into ET's html.

    What I was trying to show in that picture is that there are three actors/agents: trader, broker and data provider. They are each in a box and the arrows between boxes represent data/message flow. I think that a third entity, exchange(s), could be added. There is data flow betwen an exchange and broker(s)/provider(s). I'd add exchange(s), because it would be an improvement if a trader could at least have some input from an exchange -- even if indirectly, through some back channel -- as to whether the exchange is up/down.

    I think that's an adequate high level view. A second sheet, going into more detail, might place an intermediary between a trader/broker and between a trader/data provider. The reason is that it isn't likely that two brokers support the same protocol for submitting an order; two different data providers probably don't send data in the same format and may even use different names for the same instrument. So, some abstraction that supports communication between a trader/broker and a trader/data provider would be useful. The second sheet intermediary would then perform whatever translation is necessary in order to mediate between the trader and a particular broker/provider.
     
    #28     Jan 14, 2007
  9. doli

    doli

    Placing an order with the out-of-the box API:

    start TWS PAPERTRADING account
    configure->api check "Enable ActiveX and Socket Clients"

    java -jar jtsclient.jar

    Market data (again):

    hit the "Req Mkt Data" button, fill out these fields:
    Symbol: ES
    Security Type: FUT
    Expiry: 20070315
    Exchange: GLOBEX
    Primary Exchange: GLOBEX
    Local Symbol: ESH7

    Leave the other fields alone

    Hit "OK."

    Buy (limit):

    Hit "Place Order" on "Sample"
    In the Order Info section, set the limit price >= the ask price:
    Lmt Price 1420.25
    hit "OK"

    An API tab will appear on TWS
    If the order is filled, A position count will show
    On "Sample" there will be some execution details in the middle window


    Sell(market):

    Hit "Place Order" on "Sample"
    In the order info section
    change BUY to SELL in the Action field
    change LMT to MKT in the Order Type field
    Hit "OK" on "Sample"

    The TWS position counter should have gone to zero
    and there should be execution details in the middle window.

    That's how easy it is with the API. But what do those things do in the code. Looking in the 'java' directory under IBJts, wherever you dumped the '.jar' file, you'll see two directories, 'TestJavaClient' and 'com'. 'TestJavaClient has the high level code, 'com' has the low level code.
    In TestJavaClient/SampleFrame.java, search for onReqMktData; you'll see where the button is created, then later, in the same file, you'll see the handler that is invoked when the button is pressed. That handler invokes m_orderDlg.show, where the contract details are entered by the user; then, m_client.reqMktData() is invoked. That method is found in IBJts/java/com/ib/client/EClientSocket.java (search for reqMktData). There you'll see that the data that was entered into the form is extracted and sent, string by string, using the 'send' method -- 'send' is in the same file and is an overloaded method -- if it gets an integer argument, the argument is stringized before being "sent." So, TWS gets a sequence of strings from the API. Later today, I'll connect and find out what happens if I disconnect from the internet while doing some of these things.

    Does anybody know of a flow graph generator for Java? Does eclipse offer anything that might be useful for doing either static or dynamic analyis of a Java app?
     
    #29     Jan 14, 2007
  10. edil

    edil

    You can sample true random numbers here (not pseudo ramdom) http://random.org/

    Many serious applications are using this free service.
     
    #30     Jan 14, 2007