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
Search
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. |
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, |
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 |
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 |
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? |
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: |
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? |
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. |
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. |
marinindextrader
There should be a method to trigger an event that simply reports the
equivilent of the transaction screen one gets when they tag the transactions icon on the TWS. They should just pass us an array we can compare to the array we use to manage the trades. Then one could repair the problem if any. It should also contain the order id's you assigned, and the final entries should be any pending orders. 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. |
--- In twsapi@y..., "marinindextrader" <marinindextrader@y...> wrote:
But the questions remains...How do you flag an OCA group whensending to/through the TWS?is their any refrence in my documentation as to OCA?The oca group is one of the strings within the order structure/object. I dont know about the ActiveX thing, but at the lower level, within the order structures is a string for the oca group name. Just fill it in before you place the order. FWIW, i've given up completely on all the ib supplied code, and now have my own stuff deal directly with the sockets. On the c++ wrappers they provided, the oca group is one of the CString objects within the order itself, so I would expect it's a property of the activeX version. By re-writing everything, i've narrowed down the problems to one single outstanding problem, for which there is no cure short of fixing tradeworkstation. I'ts on the 'nextid' stuff. Using the last one given to you from the nextid callback is NOT safe, remember this, that same number has been given to ALL programs talking to tws. The safe way, is to request a block, then wait, and see that the next one it says, is that far beyond the block you requested. Now you know, the block is yours, and wont be used elsewhere. The problem is, if 2 clients request at the same time, there's no way to tell, which client got which block, at least that's how it'll work with way the original c++ wrappers were built, so i'm assuming the logic inside the ActiveX is just as broken. We've redone that logic as best we can, and it 'appears' to be safe so far, but only time will tell. |
skunktrader2001
--- In twsapi@y..., "marinindextrader" <marinindextrader@y...> wrote:
But the questions remains...How do you flag an OCA group whensending to/through the TWS?is their any refrence in my documentation as to OCA?public class Order { .. .. // extended order fields public String tif; public String ocaGroup; public String account; } If multiple orders are submitted each containing the same string "trade1", or "12dfe" or whatever, then the first order to fill will automaically cancel all the others. You can place both a profit taking order and a stop loss order and execution of the first will automatically cancel the other. |
to navigate to use esc to dismiss