TWSLink for linking your Application to TWS

Discussion in 'Trading Software' started by maxchinaski, Apr 24, 2007.

  1. hello retief,
    do you know about the yahoo group ?

    http://tech.groups.yahoo.com/group/twslink/messages

    - "MOC" - orders
    this is just another order type like "LMT" or "STP"

    -> PLACE_ORDER(uid,oid,"SELL","MOC",...)

    - hidden
    all order properties that can't be set with PLACE_ORDER
    can be set with
    SET_ORDERVAL(uidorder,propid,valastring,transmit)
    for that you should prior call PLACE_ORDER
    with transmit = -1 or 0 and
    SET_ORDERVAL with transmit = 1

    sample:
    oid = PLACE_ORDER(uid,0,"SELL","MOC",...,"GTC",0,...)
    SET_ORDERVAL(oid,15,"1",1)

    15 is propertyid of hidden. (table 6.6)
    "1" is true, "0" is false

    - ibcontroller
    i am glad you like twslink.
    i think ibcontroller links amibroker to IB. this a one to one relation.

    TWSLink links any application (that can use DLL or COM), high language as C++, VB.NET,c#,
    script language like perl to IB. this is a one to x > 0 relation.
    that makes it easier to change the host of your strategies for instance if you say
    "i want to change from amibroker to tradestation or from wealth-lab to eSignal or.."
    changing the TWSLink related code (if needed) won't be a problem. the core of your strategy
    implementation code remains the same.
     
    #31     Jun 27, 2007
  2. Retief

    Retief

    maxchinaski,

    I cannot get hidden orders to work. I think the problem is because hidden orders only work with the ISLAND exchange, and I am using the SMART exchange. From the log file, it appears that TWS-Link is setting the flag for hidden orders, but the IB TWS ignores it and does not show the hidden box as checked in the IB TWS display.

    So what I did was to use SET_ORDERVAL to always have a DisplaySize of 100. Does anyone know if its worth setting the exhange to ISLAND just to use hidden orders?

    With respect to MOC orders, I cannot get TWS-Link to do this. Here is the code that I am using:

    SellOrderID = TWSLink.Place_Order(ID, 0,"SELL","MOC",position,0.0,0.0,"DAY",0,0,"","", 0);

    The IB TWS just ignores this. If "MOC" is changed to "MKT", the TWS will accept the order, but as a market order, not an MOC order.

    Thanks for your reply. I'll post future questions at the Yahoo group.
     
    #32     Jun 28, 2007
  3. hello retief,
    a logfile can help, which was recorded with loglevel1.
    additionally you may should raise the TWS loglevel
    INITDLL(ordertimeout,logfilename,flags,twsloglevel,dllloglevel,reconnectcycletime)

    if something is going wrong within TWSLink, we can easily find it.
    but i guess this is not the case, because all these orderproterties just got carried to TWS.
    the TWS logfile should show the hidden flag and the MOC type. once you have found this line in the log, pay attention for potentional following error messages in the tws logfile.


    you could also try to place such an order manually in TWS - for the same underlying.
    if it fails, there are some general issues
    like:

    MOC is not allowed for the contract:
    check GET_CONTRACT_VAL(uid,16,...)
    to retrieve valid exchanges. if
    the returned string does not contain MOC, you can't use this ordertype.

    hidden is not allowed, for instance your are not institutional trader.
     
    #33     Jun 28, 2007
  4. Max,

    so if i wanted to hook my strat up to IB..
    (ts2000i)

    do i make the signal (w/ all my exits included?) in 1 file according to the examples listed? or.. could you build the strat w/ multiple files(buy/sell - exits).. assuming they are all compatable w/ twslink? if so.. which is preferable?

    is it that simple?
    stupid questions probably.. but i seem to be hung up on this.

    thanks,
    bb
     
    #34     Jun 30, 2007
  5. hello bb,
    that's no problem
     
    #35     Jul 1, 2007
  6. Hi maxchinaski,

    This is really great work. I am looking through your tradestation examples right now.

    Question: you declare a rather lengthy list of dll functions in the strategy code. Is it possible to declare these dll functions inside an EL function, so that when the EL function is called in the strategy, the dll functions will be declared? Or would the declaration scope be limited to inside that function?

    Similarly, if I write an EL function that calls these dll functions, will the declarations be seen outside this EL function?

    Basically, I'm wondering how the scope of these declarations works....

    Thanks,

    rt
     
    #36     Aug 6, 2008
  7. Hi.
    unfortunately i don't TS very well. i would be a nice feature
    if you could outsource DLL declarations into a separate modul/function. but i don't know how to do this.
    i am sorry.
     
    #37     Aug 6, 2008
  8. maxpi

    maxpi

    Hyperorder and Dyanorder worked like that I think. After installation you had to import a lot of functions. In your code you used what they called wrapper functions that had the EL calls to the other functions. It made coding with it very easy...

    I never tried it but you might be able to make EL functions with all the dll stuff in them that you call from your EL strategy.
     
    #38     Aug 6, 2008
  9. Yeah those wrapper functions are what I'm talking about.

    The ideal thing is to make the code as readable as possible, and separating execution code from algorithm code makes sense. Either way, it will work.

    rt
     
    #39     Aug 6, 2008
  10. After a little investigation, I found that scope does matter. Any twslink functions called must be defined in the local scope in which they are used. If a wrapper function is created to perform some twslink functions, those functions must be defined inside the wrapper function.

    rt
     
    #40     Aug 6, 2008