Keyboard Shortcuts
ctrl + shift + ? :
Show all keyboard shortcuts
ctrl + g :
Navigate to a group
ctrl + shift + f :
Find
ctrl + / :
Quick actions
esc to dismiss
Likes
- Twsapi
- Messages
Search
Re: Newbie Help on Code !!
marinindextrader
But the questions remains...How do you flag an OCA group when sending
to/through the TWS? There is no param that defines the group. Only on the reqOpenOrder is their any refrence in my documentation as to OCA? I would agree that it should be there and is of value. But where is it defined on an upstream order send? Scott --- In twsapi@y..., "grozzie2" <grozzie2@y...> wrote: positionBut I would ask you why would you want to send an OCA order?write is protected both ways. The failing here, is on partial fills.Use the example of a long position. Say you have a target, it getspairs, one oca group of target and stop for each contract you hold.That's where the TWS inability to report open orders can be an issue, ifyou have 100 pending, and suddenly you see a 'duplicate order' error,it takes a LOT of figureing to figure it all out. |
Re: Newbie Help on Code !!
But I would ask you why would you want to send an OCA order?write routines that are far more complex and robust than the simple One The reason is simple. To protect oneself from the event of an isp failure, you place target exit and stop exit, join them as an oca group. Then, should your program become disconnected, your position is protected both ways. The failing here, is on partial fills. Use the example of a long position. Say you have a target, it gets partially filled, now you have a half position, and the price pulls back to the stop. The stop order will fill, the oca logic will cancel the leftover on the target, and there you sit, short at your stop. If you are trading futures, solution sounds simple. Fire off pairs, one oca group of target and stop for each contract you hold. That's where the TWS inability to report open orders can be an issue, if you have 100 pending, and suddenly you see a 'duplicate order' error, it takes a LOT of figureing to figure it all out. |
Re: ReqOpenOrders and next order id
bee_jay_61
No. You can call reqOpenOrders only once. Than you will got all open
toggle quoted message
Show quoted text
orders. And I think this is ok. I do the following in my Delphi program: I have a List (TList object) which can stores all order data and some additional information (ex. my internal order status, order id). At the startup of my program and after connected to the TWS, this List will be cleared and ReqOpenOrdeed is called. If there are open orders, than the data of all open orders are added to the List in OnOpenOrder event. When I call PlaceOrder than the event OnOrderPlaced is fired if there were no problems with sending the data to the TWS. In OnOrderPlaced I add the order data of the placed order to the List. Of course I could do this before calling PlaceOrder but if there are problems than I have to delete the data. OnOrderPlaced? The ActiveX does not give me the functionality I want so I have rewritten the ActiveX. As I am a Delphi programmer I put all properties, methods and events from the ActiveX into a VCL and than extended the VCL with every function I need like OnOrderPlaced, OnOrderFilled, OnConnectionOpened, OnOrderSubmitted etc. When OnOrderCancelled, OnOrderSubmitted or something like this is fired than I will search for the order id the my List and update the order data and my internal order status. If there are any problems with the connection to the TWS and I have to close the TWS than my program waits until the TWS is restarted. My program will notify when the TWS restarts. Than it searches the Login-Window and logs in automaticly. Than it waits until the Login- Process window disappears and tries to connect to the TWS automaticly. I can activate and deactivate this re-autoconnect feature in my programs option dialog window. After successfully connected the OnConnectionOpend event is fired. There I clear the List and call ReqOpenOrders. This will fire the OnOpenOrders event, where the List will be filled with all open orders. And so on. This works really fine for me. Another think often read: problems with the order id and how to find out the id for the next order or what?s the best way to calculate the order id. That?s what I do: Normally, my program starts the TWS. I only start the TWS manually if there a problems. Before my program starts the TWS I set the entry "DDEId" to 1. You will find this entry in the USER.INI in the folder "C:\IB TWS\<your crypted username>\" - if your path is C:\IB TWS\ ;-) The first time the OnNextValidId event is fired I allways receive 2. But I never use this value. I just use the window API function GetTickCount. I never had this error message with "doublicate error id" or something like this. The GetTickCount function retrieves the number of milliseconds that have elapsed since Windows was started. But be carefull: the time will wrap around to zero if Windows is run continuously for 49.7 days ;-) The only problem I had for a while was how to find out the folder- name where the file USER.INI is saved. If there is only one user which uses your program than you can take the folder name (with the crypted user name) into your program or INI file. But if there are more users and you don?t know the crypted users name it is a bit difficult to find the desired folder name. In my programs options dialog you can specify the user name and I have written a routine to crypt the user name exactly the way the TWS does. So I can find easyly the users USER.INI. If somebody is interessed in this routine you can mail me. Hope you could understand MY english ;-) --- In twsapi@y..., "grozzie2" <grozzie2@y...> wrote:
Build 769 or 770 for that.Have you got reqOpenOrders to work on demand rather |
Re: Newbie Help on Code !!
larrysy.geo
Just uploaded my project to the files section. This is what I'm
trying to duplicate with the API - after an entry, I place a limit target exit and a stop exit as an OCA order. Having a preset target and stop saves time in entering the numbers and orders, specially during fast market conditions. The program is based on the PlaceOrder code in the files section (Thank to Scott) - and it does what I want to do except for the OCA part. Having an order sent as OCA to the TWS platform has an advantage - it will guard against any sudden lost in internet connection - at least your order is already in compared to waiting for the API to determine whether to cancel or not. Anybody wants to tackle the OCA part? Thanks, Larry --- In twsapi@y..., "marinindextrader" <marinindextrader@y...> wrote: I dont believe you can.order. write routines that are far more complex and robust than the simple Onethe programmer. The Methods that trigger the Events in TWS sometimesto reqOpenOrders.was MKTsending a null value to TWS. tinkeringorder. sendprogramwiththe 1_Project_PlaceOrder.zip in the files section. The <marinindextrader@y...>outLMT orders, then I'll be on my way to finish my project. andwrote:888.00When using literal declaration [not advised] you must usedefaultand0.0 work -modifiedthe original code to the following line but it wont TWSreports the limit price as 0. What's wrong? |
Re: Newbie Help on Code !!
marinindextrader
I dont believe you can.
You can snag the information sort of through reqOpenOrder method triggering the openOrder2 Event...Which would feed you back the ocaGroup in the openOrder2 Sub...But those would be OCA's placed using the TWS platform... Maybe I am wrong but I dont think you can send TWS Generic OCA order. But I would ask you why would you want to send an OCA order? Ostensibly the premise one takes when using the API is you can write routines that are far more complex and robust than the simple One Cancels All tag. As others have pointed out. Order management is largely left to the programmer. The Methods that trigger the Events in TWS sometimes feedback faulty and eroneous information. Particularily in regard to reqOpenOrders. Scott --- In twsapi@y..., "larrysy.geo" <larrysy@m...> wrote: The fix worked !!wrote: programYou are correct. outsends out MKT orders - if somebody can modify the code to send888.00LMT orders, then I'll be on my way to finish my project.wrote: |
Re: Newbie Help on Code !!
larrysy.geo
The fix worked !!
My next question is can you send in an order as part of an OCA group ? And, how do you do it? Thanks, Larry --- In twsapi@y..., "marinindextrader" <marinindextrader@y...> wrote: You are correct.out 888.00LMT orders, then I'll be on my way to finish my project.wrote: defaultand0.0 section.theliteral to a Double type and should display 888# and 0#. ITWSmodifiedwant to place a limit order instead of a market order andthe original code to the following line but it wont work - reports the limit price as 0. What's wrong? |
Re: Newbie Help on Code !!
marinindextrader
You are correct.
I am sorry for the confusion. The variable in the TWS1 call was "price" not "lmtPrice", and was sending a null value to TWS. I changed the file and uploaded it correctley. I left it as a MKT order. Your code should look like this. Call PlaceNewOrder("BUY", 1, "ES", "FUT", "200209", 0, "", "GLOBEX", "", "LMT", 850#, 0#) Call Tws1.placeOrder(newID, action, quantity, symbol, secType, expiry, strike, right, exchange, _ curency, orderType, lmtPrice, auxPrice) Thanks for pointing out the flaw. Scott --- In twsapi@y..., "larrysy.geo" <larrysy@m...> wrote: Hi Scott,with the 1_Project_PlaceOrder.zip in the files section. Thewrote: IWhen using literal declaration [not advised] you must use 888.00and0.0the modifiedwant to place a limit order instead of a market order andthe original code to the following line but it wont work - TWS |
Re: Remote TWS tip
Ah! There were two problems. First, my updater thought I was running
toggle quoted message
Show quoted text
the latest version, but it was actually 667, which did not accept remote connections. Second, the Java socket client has not been updated to allow one to create remote connections. It seems to work if you comment out the code that checks that you have not set the host and take out where it hardwires the host to 127.0.0.1. --- In twsapi@y..., bee_jay_61 <no_reply@y...> wrote:
Are you sure tunneling is needed? |
Re: Newbie Help on Code !!
larrysy.geo
Hi Scott,
Thanks for the quick reply, but it didnt work. I was tinkering with the 1_Project_PlaceOrder.zip in the files section. The PlaceNewOrder is a subroutine in that program. The demo program sends out MKT orders - if somebody can modify the code to send out LMT orders, then I'll be on my way to finish my project. Thanks, Larry --- In twsapi@y..., "marinindextrader" <marinindextrader@y...> wrote: When using literal declaration [not advised] you must use 888.00and 0.0the literal to a Double type and should display 888# and 0#.modified the original code to the following line but it wont work - TWS |
Re: ReqOpenOrders
marinindextrader
This explains why the TWS platform itself gets corrupted in terms of
showing orders and what not. Try opening concurrent instance of TWS on two seperate platforms. Placing a trade on one does not update the other. Log off on then on with the one that didn't place the order and things get really screwy sometimes. Scott --- In twsapi@y..., Nick <nickrbox@o...> wrote: onlyHave you got reqOpenOrders to work on demand ratherSo far in my travels with the socket interface to IB, ReqOpenOrders reports the orders that were open when you connect to TWS. Afterthat the OrderStatus message tells you about fills, etc.you on startup and compare that with the OrderStatus messages you getlater on. orders that existed before your program started (as opposed to allcurrently open orders). |
ReqOpenOrders
Nick
Have you got reqOpenOrders to work on demand ratherSo far in my travels with the socket interface to IB, ReqOpenOrders only reports the orders that were open when you connect to TWS. After that the OrderStatus message tells you about fills, etc. I think the idea is that you keep track of what ReqOpenOrders gives you on startup and compare that with the OrderStatus messages you get later on. It appears that they intend that you keep track of your own orders. ReqOpenOrders is a poorly named function to find out about orders that existed before your program started (as opposed to all currently open orders). - Nick |
Re: Newbie Help on Code !!
marinindextrader
When using literal declaration [not advised] you must use 888.00 and
toggle quoted message
Show quoted text
0.0 As your type in these literal values...your IDE will then default the literal to a Double type and should display 888# and 0#. Further their is no PlaceNewOrder method... But there is a placeOrder method...check that too Let me know if this works Scott --- In twsapi@y..., "larrysy.geo" <larrysy@m...> wrote:
Hi, |
Re: twsapi: Asset US format information
Nick
OK but answer this...The TAL website contains the full API docs. The RealTick charting program uses the same API so everything you want to do is possible. You need to read the docs and decide if TAL is for you. You can also email their tech support with specific questions. |
Newbie Help on Code !!
larrysy.geo
Hi,
I'm a newbie tinkering with the VB codes on the file section. I want to place a limit order instead of a market order and modified the original code to the following line but it wont work - TWS reports the limit price as 0. What's wrong? Call PlaceNewOrder("BUY", 1, "ES", "FUT", "200209", 0, "", "GLOBEX", "", "LMT", 888, 0) Thanks, Larry BTW, I'll post my finished program if it works. |
twsapi: Re: Remote TWS tip
bee_jay_61
i think he is talking about running the TWS on another PC, notconnecting your client to existing one on the original PC. I would like to know more as I used tunneling but on the secondaryPC not the original one. That?s what I do: TWS run?s on PC ONE in my network. And I can connect to the TWS from PC TWO or PC THREE. I will try to connect me to the TWS on my PC ONE from another PC not connected to my network over the Internet. I don?t need that but I will check it out. |
Re: twsapi: Re: Remote TWS tip
David
¿ªÔÆÌåÓý?
i think he is talking about running the TWS on another PC, not
connecting your client to existing one on the original PC.
I would like to know more as I used tunneling but on the
secondary PC not the original one.
?
BTW, trying to sort out data and compare to some other
data.
Does anyone know a free source of ES Globex 24 hours, 1minute
interval.???
?I've been trying Qcharts but it is very unreliable. I
just need to get the data every a few hours.
Anyone??
Thanks
David
|
Re: Remote TWS tip
bee_jay_61
Are you sure tunneling is needed?
I can easyly connect to the TWS from any machine in my network. Just call TWS.Connect with the IP of the computer where TWS is running. Example: TWS.connect('192.168.0.1', 7496); Like written in the docu: host - host name or IP address of the machine where TWS is running. Leave blank to connect to the local host. But I think you need at least Build 769 or 770 for that. PlaceOrder, CancelOrders. Everything works. --- In twsapi@y..., "kgeis" <kgeis@y...> wrote: I was a bit annoyed by the fact that TWS does not accept incomingon a separate Linux machine.Linux box, and I tunnelled port 7496 back to my desktop machine. This |
to navigate to use esc to dismiss