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: Simple programs
BeeJay (GMX)
Hi
toggle quoted message
Show quoted text
Me too I still use Delphi. Do you know the TIABSocket VCL? Before I found this VCL, I wrote my own socket client for the TWS. Must be about 14 years ago. Cause lack of time I switched to TIABSocket VCL. If you dont want to use TIABSocket, I can look for my code and send it to you. Was written for D5 and later for D6. Beejay Hi |
||||||||||||||||||||||||||||||||||||||||
Re: Simple programs
Hi
Nice stuff... For now I'm trying with rwk to fix Delphi 6... but it's not looking good. :( For the moment I don't need that much speed. And your solution with XML look great. I gonna take a look at your suggestion. Bye the way, is it possible to send direclty to IB an order via socket? Thank you very much. Thanks you all S |
||||||||||||||||||||||||||||||||||||||||
Re: Simple programs
uberquant
There's an project on github that does (almost) all of this, implemented in C++ and uses XML to return values.It can work either cygwin under Windows (note Powershell has a nice XML parser) or linux. I found it a great resource to help me figure out what I wanted to do with the API and still use it for certain batch tasks (e.g. download historical data and as a secondary monitor of important account values)
It could be good as a solution to what you're looking for or as a nice example of good practice. It sounds like what you're doing isn't super sensitive to timing, but you're mre looking for something to help you, so you can set transmit=0 and then dispatch the orders via TWS by hand (when you make sure it's not making 100 of the same order or applying a crazy order size) Submit some order would look like this (can substitute different order types and then specifiy auxiliary prices or limit prices as appropriate) : <?xml version="1.0"?> <TWSXML> <request type="place_order"> <query orderId="501"> <contract symbol="IBKR" secType="STK" expiry="" currency="USD" exchange="SMART"/> <order action="SELL" totalQuantity="500" orderType="MKT" transmit="0"/> </query> </request> <request type="place_order"> <query orderId="502"> <contract symbol="AMZN" secType="STK" expiry="" currency="USD" exchange="SMART"/> <order action="BUY" totalQuantity="300" orderType="MKT" transmit="0"/> </query> </request> <request type="place_order"> <query orderId="503"> <contract symbol="IBM" secType="STK" expiry="" currency="USD" exchange="SMART"/> <order action="SELL" totalQuantity="900" orderType="MKT" transmit="0"/> </query> </request> </TWSXML> You can wait for the return value in an XML and then parse it. Don't forget to watch for pacing if you are inputting dozens of orders at a time. Also don't forget the orderID must be in strictly increasing order across time. To get account values and positions there's a snapshot ability. In powershell for example Function TWSDO ($port) { ? ? ? $poo=& ?C:\utils\twsdo.exe -h localhost -p $port --get-account? ? ? ? Return $poo } ? ? ? ? ?$res=TWSDO($arr[$i]) ? ? ? ? ?$x=[xml]$res[0..($res.Length-2)] ? ? ? ? ?$acct = ($x.TWSXML.request.response.AccVal | ? {$_.key -eq "AccountCode"}).val ? ? ? ? ?$nlvxx = $x.TWSXML.request.response.AccVal | ? {$_.key -eq "NetLiquidation" -and $_.accountName -eq $acct}? ? ? ? ? ?$nlv=$nlvxx.val -as [double] ? ? ? ? ?$imronxx = $x.TWSXML.request.response.AccVal | ? {$_.key -eq "FullInitMarginReq" -and $_.accountName -eq $acct} ? ? ? ? ?$imron=$imronxx.val -as [double] To get historical data you can make a request as like this <?xml version="1.0"?> <TWSXML> ? <request type="historical_data"> ? ? <query endDateTime="20160101 23:59:59 GMT" durationStr="6 D" barSizeSetting="1 min" whatToShow="ASK" useRTH="1" formatDate="1"> ? ? ? <reqContract conId="43645865" symbol="IBKR" secType="STK" exchange="SMART"?primaryExchange="NASDAQ" currency="USD" localSymbol="IBKR" tradingClass="NMS"/> ? ? </query> ? </request> </TWSXML> It won't do for getting the current price, but that is relatively easy to put together, I think this fellow's tutorial swill get you that quicly enough? ? |
||||||||||||||||||||||||||||||||||||||||
Re: API thinks it's "connected" before I granted the incoming connection request
rholowczak
Best bet is to add your localhost ip address to "Trusted connections" and/or the IP address of the host where your application is running. I outlined how to do this in my tutorial on downloading, installing and setting up the IB Gateway and IB API on Linux. (But generally, same concept applies to Windows as well).
|
||||||||||||||||||||||||||||||||||||||||
Re: API thinks it's "connected" before I granted the incoming connection request
I think most of us are bypassing the "Accept
incoming connection request" dialog by specifying a trusted
connection.? That is done on the TWS by clicking ,
, and <127.0.0.1> in Trusted IP
Addresses for local loop.
toggle quoted message
Show quoted text
[rwk] At 11:42 AM 1/4/2016, you wrote: I don't have an answer to your question but I have an alternative approach. |
||||||||||||||||||||||||||||||||||||||||
Re: API thinks it's "connected" before I granted the incoming connection request
Jason, I guess this happens due to the fact that 3-way tcp connection is established prior to "Accept incoming connection attempt?" pop up, moreover on top of that it seems one can sniff the server's version along with server's (running TWS) time before getting accepted! this is what java demo prints to std output before getting accepted: (quote) Server Version:76 TWS Time at connection:20160104 13:34:20 EST (end of quote) I'm not sure if any requests can be processed (if any) before you're accepted, I guess none. And then you have only so many seconds to click "yes" or "no" before TWS will brake established tcp-connection. (no time/desire to play with it now) Of cause it is a very lame security model. Imho if remote IP is not on "allowed" list they should never even be able to get SYN-ACK on initial connection attempt but TWS could notify us about the fact that someone from that IP at that time tried to knock the door. Less strict would be to behave similar as they do now, but never let any info to the client before formally accepted (or found in "allowed IPs" list), but in this case someone might DDoS your production TWS. Cheers, Dmitry On Mon, Jan 4, 2016 at 11:00 AM, jasonl534@... [TWSAPI] <TWSAPI@...> wrote:
--
§ã §é.§Ô§Ý.§å§Ó., §¥§Ú§Þ§Ñ §º. |
||||||||||||||||||||||||||||||||||||||||
Re: API thinks it's "connected" before I granted the incoming connection request
Nick
I don't have an answer to your question but I have an alternative approach.
toggle quoted message
Show quoted text
You always get a NextValidId event after you successfully connect so some people will just do nothing until they get NextValidId and then assume they are connected and continue with starting up the program. On 1/4/2016 11:00 AM, jasonl534@... [TWSAPI] wrote:
I don't understand why or how the API can think it's connected before I've granted the request. |
||||||||||||||||||||||||||||||||||||||||
API thinks it's "connected" before I granted the incoming connection request
Hi,
I'm playing around with the API and I have the following in my code (taken from
? although it's failing in exactly the same way that my own code was failing before it):?// Create a new EClientSocket object ??????????? client = new EClientSocket (this); ??????? // Connect to the TWS or IB Gateway application ??????? // Leave null for localhost ??????? // Port Number (should match TWS/IB Gateway configuration ??????? client.eConnect (null, 7496, 0); ??????? // Pause here for connection to complete ??????? try ??????? { ??????????? // Thread.sleep (1000); ??????????? while (! (client.isConnected())); ??????? } ??????? catch (Exception e) ??????? { ??????? } ??????? System.out.println("***CONNECTED***"); the last line - "CONNECTED" is being reached BEFORE I have responded to the "Accept incoming connection request" dialog box in TWS. So, in a nutshell, the code thinks it's "connected" even though I haven't granted the connection request in TWS. The program then continues to do stuff by fails with an EOFException because it's not actually connected. I don't understand why or how the API can think it's connected before I've granted the request. Can anybody help me with this? Thanks. Jason |
||||||||||||||||||||||||||||||||||||||||
Re: Simple programs
I'm still using Delphi, but I thought I was the
last one in the whole world.? :-)? Contact me off-list if you
want Delphi tips.? rwk2095-at-gmail-dot-com
toggle quoted message
Show quoted text
[rwk] At 05:05 PM 1/3/2016, you wrote: I have no experience except Delphi. Then learn python, c++ or java and IDE Eclipse and understand API, is a big piece at a time... |
||||||||||||||||||||||||||||||||||||||||
Simple programs
Happy new year everyone.
I'm a newbie here and in a lot of things: I have no experience except Delphi. Then learn python, c++ or java and IDE Eclipse and understand API, is a big piece at a time... Anyone would be please to help me how to write 4 codes (server) regardless (java or c++ prefered) the language available in Eclipse doing that : 1 - Read a file with the order writen inside (example : Action =sell (buy or cancel or modify) Stock='IBM',share=100, LimitPrice=140.0000) and send it to IB ; 2 - Write a file with all the messages received form IB (example : Sell IBM 100 @ $140.0000 filled (accepted or rejected or modified) ); 4 - Write a file with the account value and assets; 5 - Read a file with a live or historical data request to IB and write on a new file. Thanks in advance |
||||||||||||||||||||||||||||||||||||||||
Re: orderReference missing in flex reports
James Smith
On 01/01/2016 10:53 AM, James Smith james.smith@... [TWSAPI]
wrote: I set order reference through the API. It is visible in the JClient inOn 01/01/2016 12:50 PM, lcrouzet42@... [TWSAPI] wrote:
Thanks for response, but I asked for something different. I do have Order reference column in a flex report, but with empty values. I have found only one similar post. As I understand IB clears some data including order reference for Flex Reports at midnight. From Davqe drosen@... "I am using the OrderReference field to store values for the strategies. I have created a Flex Report for Trade Confirms that I run at the end of each day to download the Trades with the Order Reference field populated. (apparently they haven't found a way to keep that field for more than a day). But, if I have trades after 5:30pm on Day 1, they are part of the report that gets run at the end of Day 2 (basically doing it as session days as opposed to calendar days). This is the behavior I would expect and want. Except, the orders placed on the previous calendar day (but part of the current session day) don't maintain the Order Reference information in the Flex Reports. I verified this with IB Support. It appears for some reason they reset that value around midnight in some portion of their system that is read for Flex Reports, though it is kept in the Trade Log I see in TWS from previous days. I like the Flex Report because I can easily automate without having to create a new application to extract information via the API. Anyone have insight into how they are tracking the information they wouldn't mind sharing?" |
||||||||||||||||||||||||||||||||||||||||
orderReference missing in flex reports
James Smith
I set order reference through the API. It is visible in the JClient in
Portfolio in Order Ref. column. It is also visible in Trade Log in the column Order Ref. But it is missing in Flex Reports. The column Order Reference is empty for Level of Detail set to Orders, or filled with "--" for Level of Detail set to Execution. How to overcome this? |
||||||||||||||||||||||||||||||||||||||||
Re: Looking for an EXCEL DDE API Interactive Brokers GURU
...and I know there are others, but these guys really have their game down, they're very reasonably priced, AND, if options are your thing,? they give you some wonderful 3d graphics, too.....
? |
||||||||||||||||||||||||||||||||||||||||
Re: Looking for an EXCEL DDE API Interactive Brokers GURU
"to build a simple Excel spreadsheet that pulls live data from IB"...
I built a TWS quote monitor page utilizing the fields I wished to use in an OpenOffice Calc spreadsheet, and periodically export that data to a .CSV file, for copy/paste into OO_Calc. My "project" -- much as you have described -- is to develop a Java application to print an .XML file in real time, to which OO_Calc can be (easily!!) attached. (I got some very compassionate offers of assistance, but what I thought was a "time-out" to put a little more polish on the spreadsheet ended up to be a real scrub-up/"next level" sort of campaign, with which I'm *only now,* just about, done....!!! Woot! "Phew!") You could do about the same thing (spreadsheet-with-RTdata-front-end), by running your .CSV-eating spreadsheet through this guy's
? or even his
? He gets good reviews (for software and for service) on the IB website and on EliteTrader.com, and (I think) is a regular TWSAPI reader, so he may have responded to you offlist.But first, I would go with the "Hey! Hit IB's DDE webinar, first!" advice, if you hadn't already. If you *wish* to deal with DDE, it really is a pretty trivial matter for Excel. FWIW, though, I would *not* go with DDE, as its use was limited, and therefore its lifespan will be, too. Not where I'd want to be, when the lights go out. |
||||||||||||||||||||||||||||||||||||||||
Re: Looking for an EXCEL DDE API Interactive Brokers GURU
Go to the Education portion of the main IB website and download their 1-hour seminar on using the Excel DDE API.?It's free, costs one hour of your life, and has a lot of info for starting out.?It's under Education > Previously Recorded > API tab.?Following link *may* work.? If you want more than that, feel free to drop me a line.? Happy New Year, everyone! --Joe |
to navigate to use esc to dismiss