Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: Yikes smart exchange is not smart
Yes I see how you can loose a lot on SELL on low liquidity stocks. especially pre-market as some guys set fishing lines with 0.01$ bid, just in case somebody else made a mistake at time no 'normal' "ask" exist. Anyway was more a suggestion of ramp-up on learning way to learn more elaborated method to control order. ? |
Re: Yikes smart exchange is not smart
Thanks for the reply, I think.
I didn't put all the info on the order, no I don't need limit price. This was premarket and I do agree that the liquidity was an issue. But the bigger issue was my misunderstanding how SMART works. I've done hundreds of orders just fine, but this exposed a nasty little issue I figured someone else should be aware. But I am probably the only person doing small cap. |
Re: Yikes smart exchange is not smart
Why did you use LMT ? (shouldn't you specify a order.lmtPrice ?)
|
Re: How do you send a d-quote order via the API?
开云体育The first article you referenced implies that you just have to send a MKT order using NYSEFLOOR as the exchange. But you first have to contact IB support to get your TWS configured to recognise NYSEFLOOR. ? Is that what you did? If so, what happened? If not, what did you do and why? ? ? ? From: [email protected] <[email protected]> On Behalf Of JZcgQR2N
Sent: 13 December 2022 05:28 To: [email protected] Subject: [TWS API] How do you send a d-quote order via the API? ? From what I understand, you can send a MOC order later than what is otherwised allowed (15:50ET) via a d-quote order. How do you send one via the API? I cannot find it anywhere in the official IB API documentation. |
Yikes smart exchange is not smart
I was mistakenly under the impression that if I create a SMART sell order that it would fill at the best price
Contract contract = new Contract();
contract.symbol(symbol);
contract.exchange("SMART"); Order order = new Order();
order.clientId(clientId);
order.orderType("LMT");
order.action("SELL");
?
but today in fact it did not find me the best price.
Now part was due to some lazy programming on my part. I received a quote of a bad, low price, and didn't double check it. Regardless of that issue, I really thought that IB would fill my order at a reasonable price.? In fact though it took my order and sold it, at a large loss, and at a price whereby my price was the only one like it for that minute of trading. Fortunately I am still using small share sizes while testing. So does this mean that I cannot trust SMART, and I have to go find the exchange each time? I tried to use some other smart options, but apparently they are only available in the TWS client, and are not valid for the API. |
How do you send a d-quote order via the API?
From what I understand, you can send a MOC order later than what is otherwised allowed (15:50ET) via a d-quote order. How do you send one via the API? I cannot find it anywhere in the official IB API documentation.
They say if you can do it via TWS then you should be able to do it via the TWS API too, right?? |
Re: Adding timezone to request
I found I get the best results if I move away from the ambiguous three letter codes, like IB recently did, and use one of the following time zone specifications:
Everything else is likely to raise a warning. |
java - conid for a synthetic contract?
I would like to define a synthetic call (stock + put combo), and use the synthetic call as a benchmark in "PEG BENCH" order.
The method??referenceContractId requires a contract id. The method?reqContractDetails?responds with an error? 'BAG' isn't supported for contract data request. Please enter a valid security typeAny suggestions as to an approach or work-around? Thanks! |
Re: Adding timezone to request
There appears to be poor consistency in the handling of time zones.
For order GTD field, I used both "EST" and "America/New_York"?successfully. For reqExecutions I used the "EST" value for time zone and it returned: 10314 Time: The date, time, or time-zone entered is invalid. The correct format is yyyymmdd hh:mm:ss xx/xxxx where yyyymmdd and xx/xxxx are optional. E.g.: 20031126 15:59:00 US/Eastern? Note that there is a space between the date and time, and between the time and time-zone.? If no date is specified, current date is assumed. If no time-zone is specified, local time-zone is assumed(deprecated).? You can also provide yyyymmddd-hh:mm:ss time is in UTC. Note that there is a dash between the date and time in UTC notation. Using "America/New_York" was successful. Timezones should be uniform across requests. |
Locked
Re: Like to create my own stripped down API using current C# sockets version
I asked for any questions relating to this sample to be sent directly to me, not to the Group. So I'm locking this topic to prevent further posts. Feel free to email me though. Max, I will respond to your query when I get a chance. The short answer is that when you open the program and you already have outstanding orders with TWS, the API immediately sends OrderStatus callbacks and the program doesn't currently handle them properly (it's only a sample so not extensively tested). It should be pretty trivial to fix, and I'll give you some hints when I reply properly. I will also fix it myself at some point soon, but it's a good 'exercise for the reader'... |
Locked
Re: Like to create my own stripped down API using current C# sockets version
Richard,? Thanks much for posting this sample code.? You may call it simple but for a 70 yo trying to get my head around .NET it looks pretty sophisticated.??
I'm running Visual Studio 2022 Community Edition, the latest available, trying to get back into this form of coding. When I run the .exe file it loads.? When I hit the "Connect" button I get a dialog showing that it has thrown an unhandled exception and then gives me the chance see Details or .ignore it and continue: ? ? Simple TWS API Demo ? ? Unhandled exception has occurred in your application.? If you click ? ? Continue, the application will ignore this error and attempt to continue.? If ? ? you click Quit, the application will close immediately. ? ? The given key was not present in the dictionary. If I click details it shows this: See the end of this message for details on invoking?
just-in-time (JIT) debugging instead of this dialog box.
?
**** Exception Text ****
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
? ?at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
? ?at SimpleTWSAPIDemo.MainForm.showOrderValue(Int32 orderId, String columnName, String value) in C:\Trading\SimpleTWSAPIDemo\MainForm.vb:line 574
? ?at SimpleTWSAPIDemo.MainForm.orderStatus(Int32 id, String status, Decimal filled, Decimal remaining, Double avgFillPrice, Int32 permId, Int32 parentId, Double lastFillPrice, Int32 clientId, String whyHeld) in C:\Trading\SimpleTWSAPIDemo\MainForm.vb:line 322
? ?at SimpleTWSAPIDemo.ApiEventSource._Closure$__11-0._Lambda$__0() in C:\Trading\SimpleTWSAPIDemo\ApiEventSource.vb:line 64
? ?at SimpleTWSAPIDemo.ApiEventSource._Closure$__11-0._Lambda$__R9(Object a0)
?
?
**** Loaded Assemblies ****
mscorlib
? ? Assembly Version: 4.0.0.0
? ? Win32 Version: 4.8.9037.0 built by: NET481REL1
? ? CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
SimpleTWSAPIDemo
? ? Assembly Version: 1.0.0.0
? ? Win32 Version: 1.0.0.0
? ? CodeBase: file:///C:/Trading/SimpleTWSAPIDemo/bin/Debug/SimpleTWSAPIDemo.exe
----------------------------------------
Microsoft.VisualBasic
? ? Assembly Version: 10.0.0.0
? ? Win32 Version: 14.8.9037.0 built by: NET481REL1
? ? CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
? ? Assembly Version: 4.0.0.0
? ? Win32 Version: 4.8.9037.0 built by: NET481REL1
? ? CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
? ? Assembly Version: 4.0.0.0
? ? Win32 Version: 4.8.9037.0 built by: NET481REL1
? ? CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Windows.Forms
? ? Assembly Version: 4.0.0.0
? ? Win32 Version: 4.8.9037.0 built by: NET481REL1
? ? CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
? ? Assembly Version: 4.0.0.0
? ? Win32 Version: 4.8.9037.0 built by: NET481REL1
? ? CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
? ? Assembly Version: 4.0.0.0
? ? Win32 Version: 4.8.9037.0 built by: NET481REL1
? ? CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
? ? Assembly Version: 4.0.0.0
? ? Win32 Version: 4.8.9037.0 built by: NET481REL1
? ? CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Accessibility
? ? Assembly Version: 4.0.0.0
? ? Win32 Version: 4.8.9037.0 built by: NET481REL1
? ? CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Runtime.Remoting
? ? Assembly Version: 4.0.0.0
? ? Win32 Version: 4.8.9037.0 built by: NET481REL1
? ? CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
CSharpAPI
? ? Assembly Version: 10.19.1.0
? ? Win32 Version: 10.19.01.0
? ? CodeBase: file:///C:/Trading/SimpleTWSAPIDemo/bin/Debug/CSharpAPI.DLL
----------------------------------------
If instead I hit the Ignore button, it will connect to my TWS session. When I load the Solution into VS 2022 and attempt to run it in debug mode the form comes up and when I click the Connect button I get an "Exception Unhandled" dialog. ?
? ? ?System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'
?
? ? ? Inner Exception
? ? ? KeyNotFoundException: The given key was not present in the dictionary.
?
? ? ? This exception was originally thrown at this call stack:
? ? ? ? ? System.Collections.Generic.Dictionary<TKey, TValue>.this[TKey].get(TKey) in dictionary.cs
? ? ? ? ? SimpleTWSAPIDemo.MainForm.showOrderValue(Integer, String, String) in MainForm.vb
? ? ? ? ? SimpleTWSAPIDemo.MainForm.orderStatus(Integer, String, Decimal, Decimal, Double, Integer, Integer, Double, Integer, String) in MainForm.vb
? ? ? ? ?SimpleTWSAPIDemo.ApiEventSource.<closure>.<lambda0>() in ApiEventSource.vb
?
This dialog is overlaid on the?"Source Not Found" tab which says "delegate.cs not found".? If I click the hotlink labeled "Browse and find delegate.cs..." the browse dialog shows: "Original location: f:\dd\ndp\clr\src\BCL\system\delegate.cs" Any clues or pointers will be much appreciated. Thanks,? Max...?? |
Locked
Re: Like to create my own stripped down API using current C# sockets version
开云体育Yes of course you can still use the old pre-.Net ActiveX implementations. In fact the oldest one I have is from 2003, and that still works too. ? But the API has moved on a long way since 970. ? It makes much more sense to move to a current API version: yes there may be a bit of a hit in terms of learning curve and understanding what’s going on, but once over that it’s pretty straightforward. And using the CSharp API is actually no more difficult than using the (current) ActiveX API. ? ? ? From: [email protected] <[email protected]> On Behalf Of thedude_c via groups.io
Sent: 10 December 2022 01:55 To: [email protected] Subject: Re: [TWS API] Like to create my own stripped down API using current C# sockets version ? 2017 VB.net + old API works? fine. Don't know about VB.net 2019 or 2022 |
Locked
Re: Like to create my own stripped down API using current C# sockets version
Appreciate your help.? I will spend a few days trying to digest what you have sent me, and then I suspect I will ask a few really stupid
questions before I really understand.? I do hope to gain a better understanding of the APIs as they have kicked me in the teeth a number of times over the years, when suddenly out of nowhere, things stop working for no apparent reason. Miles |
Locked
Re: Like to create my own stripped down API using current C# sockets version
2017 VB.net + old API works? fine. Don't know about VB.net 2019 or 2022
https://youtu.be/meyBmhhI-44 |
Locked
Re: Like to create my own stripped down API using current C# sockets version
开云体育I’ve updated the two projects, zipped them separately, and you can get them from here: ? ? Remember to unblock the downloaded .zips before trying to extract them to avoid annoying messages. ? The projects have been compiled with Visual Studio 2019 Community Edition, but should also be fine with 2017 and 2022 versions. ? You can run them directly from the bin folders – everything you need is included. Note that they both use the same client id by default, so if you want to run them both at the same time you’ll need to change the client id for one of them (which you can do on the main form before? hitting the connect button). ? Note these are simple programs, not in any way polished products, intended only to help familiarise with using the ActiveX and CSharp APIs. Most of the code is identical between the two programs, the differences being in the plumbing needed to access the API. In this respect, the ActiveX API version is simpler and more like using the original ActiveX API provided up to API 8.69 (or thereabouts – can’t remember exactly without checking). So API events come via event handlers the same as any other ActiveX or Windows Forms control. ? The CSharp API version has to do a bit of extra work, because the API callbacks are invoked initially on a separate thread calling functions in the ApiEventSource wrapper class,and then passed through to the main thread using a synchronisation context, so that all the code that handles the callbacks runs on the main thread and avoids multithreading concerns. You’ll probably need to study this code a little to get a handle on it: it’s really quite straightforward when you grasp the principles. It really is advantageous to use the CSharp API rather than the ActiveX if you can get to grips with this approach. ? The programs have a very na?ve design: they make no attempt to do desirable things like encapsulating all access to API functions in a library which can be reused between multiple client programs. They don’t do any sort of UI separation of concerns like Model-View-Controller and its derivatives. They don’t use any of the modern VB language constructs (such as Async..Await), apart from use of lambdas in the ApiEventSource class. This keeps the code as simple to follow as possible. ? They operate with TWS API v10.19. You won’t actually need to install this because the libraries produced by compiling the APIs are included in the projects’ bin folder. I prefer to use the API libraries rather than including the API project code with the program project in a single solution, but you can certainly do that if you prefer and is what IB seems to prefer in its sample programs. ? Ok, I think that will do for now, but if you (or anyone else) need further assistance or questions answered it might be best to email me direct as this is arguably rather out-of-scope for this group. ? Richard ? ? From: [email protected] <[email protected]> On Behalf Of mmussel2000 via groups.io
Sent: 08 December 2022 21:35 To: [email protected] Subject: Re: [TWS API] Like to create my own stripped down API using current C# sockets version ? Thank you!!..? Yes, I would like to see both examples.? I have been working on my trading program for close to 20 years, and |