Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Is it possible to place order at 15:59 or 16:00 and get a fill?
I am currently using this code to do my trades as bracket orders. I need my trades to exit by the end of the day. Is it possible to place a limit or market order at 15:59 or 16:00 and have it continue trading after market hours to get the fill using this? def BracketOrder(self, parentOrderId:int, openinglimitPrice:float, quantity:Decimal, trailingPercent:float, timeswitch:str, adaptive_type:str):
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Error when requesting 20 years of price data for specific ticker [CHTR]
Interesting! |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Level2 data falls behind actual market
Look to me like the Highest Bid and Lowest Ask. They are unrealized transaction. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Level2 data falls behind actual market
Current market price meaning the top of the limit order book - what Updatemktdepth would display as the ¡°0¡± position. On Wed, Aug 9, 2023 at 5:08 PM Gordon Eldest via <hymagik=[email protected]> wrote:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Error when requesting 20 years of price data for specific ticker [CHTR]
Thank you for the tips - I will try tomorrow morning with the ISLAND exchange settings (before opening the chart I mentioned above) to check if it acquires the data without a glitch. I can't use "TRADES"? because it brings the price?unadjusted for dividends. See the detta for PCAR (a company that pays dividends):
What is quite scary is how different the prices are from another source (FactSet) - see below. But I will address this later: The price for ISLAND and SMART (using "ADJUSTED_LAST") is similar (a little scary that it isn't the same, but close enough) for CHTR: I will post back here re: data acquisition before trying the workaround (once you do it, the code works during the whole day). Thank you again, Danilo |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Level2 data falls behind actual market
"show" ? as in a "SELECT in a tool like MySQL WorkBench" ? because L2 run so fast that extremely unlikely you can catch it "visually" |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Error when requesting 20 years of price data for specific ticker [CHTR]
The TWS API Guide suggests for retrieval:
toggle quoted message
Show quoted text
For licensing reasons, IBKR has to be much more stringent when they provide you market data in machine readable form via the API than when they display charts within TWS. So I am not surprised that, for charting, TWS may receive more data than what you have subscribed to for and that you can retrieve unsubscribed but locally cached data after pulling up the chart in TWS. Hope this helps, ´³¨¹°ù²µ±ð²Ô PS. Going forward, please do not post large chunks of code. TWS API is language independent and discussions are more meaningful for the entire group when we focus on API behavior, not the implementation in one language. Chances are you get more and better responses that way, too. On Wed, Aug 9, 2023 at 01:46 PM, Rational-IM wrote:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: g++ command for including the proper libraries
I concur with Jurgen |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: g++ command for including the proper libraries
I am not following your logic here. TWS API is a language independent request/response message protocol that serializes requests made by your client into messages that are sent through a network socket socket to TWS/IBGW and de-serializes any response messages. IBKR provides implementations of this protocol for several programming languages, including C++. So there are no derivatives and I have no idea what you think we are all settling for. All IBKR client facing software (TWS, IBGW, the Client Portal API gateway) is implemented in Java. In V10 of TWS/IBGW and TWS API, the data type for various size/quantity fields was changed from double to a more stable Decimal type. Java, and many other languages, have a built-in Decimal datatype, but C++ does not. IBKR opted to base the C++ TWS API adapter implementation of Decimal on the "Intel? Decimal Floating-Point Math Library", as you probably have read in the . The TWS API release ships with various binary versions of that library, but not all versions for all environments. As your error log suggests, your g++ environment is not happy with the ones it finds. So you have to locate or compile a compatible version yourselves, or use a compile environment that is happy with one of the provided versions. If you search for C++ in our archives, you will find several posts that talk about where you can find a suitable binary version or which open-source version you can use to make your own library.. ´³¨¹°ù²µ±ð²Ô On Wed, Aug 9, 2023 at 01:31 PM, <blydon12@...> wrote: I've had no problems using g++ on windows for C++. I am just trying to see if anyone else has tried doing this successfully rather than using TwsApiL0 because I imagine the API was written in C++ to be used directly regardless of compiler or system. Otherwise, what are they doing over at Interactive Brokers? It doesn't make sense to me that I have to use some derivation of the API, and it is strange that everyone on here seems to be settling for that. With that being said, do you have any advice on how to link directly to the TWS API via g++ on windows? Any technical advice would be appreciated. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Error when requesting 20 years of price data for specific ticker [CHTR]
I have a strange issue when requesting data for a specific ticker: CHTR (for?Charter Communications Inc. - Class A). Below you can see a printout of my console, showing that price data for other test tickers is correctly retrieved. However, when reaching CHTR, it stops and says I don't have access to a database that can provide the data: Danilo #%% DATA REQUEST EXAMPLES
?
# VARIOUS EXAMPLES OF DATA REQUEST FROM INTERACTIVE BROKERS
?
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.common import TickerId
?
from threading import Thread
import time
?
import pandas
import sys
?
class IBapi(EWrapper, EClient):
?
? ? def __init__(self):
? ? ? ? EClient.__init__(self, self)
? ? ? ? self.data = []
? ? ? ? self.data_sent = -1 # used to check if full data requested returned
?
? ? def error(self, reqId:TickerId, errorCode:int, errorString:str, advancedOrderRejectJson = ""):
? ? ? ? ?if advancedOrderRejectJson:
? ? ? ? ? ? ?print("\nError. Id:", reqId, "\nCode:", errorCode, "\nMsg:", errorString, "\nAdvancedOrderRejectJson:", advancedOrderRejectJson)
? ? ? ? ?else:
? ? ? ? ? ? ?print("\nError. Id:", reqId, "\nCode:", errorCode, "\nMsg:", errorString)
?
? ? def historicalData(self, reqId, bar):
? ? ? ? self.data.append([bar.date, bar.close])
?
? ? def historicalDataEnd(self, reqId, start, end):
? ? ? ? self.data_sent = reqId
?
def run_loop():
? ? app.run()
?
app = IBapi()
app.connect('127.0.0.1', 7496, 0)
?
#Start the socket in a thread
api_thread = Thread(target=run_loop, daemon=True)
api_thread.start()
time.sleep(0.5) #Sleep interval to allow time for connection to server
?
?
# HISTORICAL DATA TEST OF DATABASES vs. API
?
# AAP (NYSE) and CHTR (Nasdaq):
# Had to sign-up for "NYSE (Network A/CTA) Billed by Broker" @ $45/month and "NASDAQ (Network C/UTP)" @ $25/month
# Didn't work with "NYSE American, BATS, ARCA, IEX, and Regional Exchanges (Network B)" @ $25/month
# "Worked" with "Cboe One" @ $5/month but data is inconsistent (e.g. multiple days with same price)
# The "NYSE American, BATS, ARCA, IEX, and Regional Exchanges (Network B)" was better to show streaming prices on TWS (with the Cboe One, live data disapears when using a Basket trade)
?
# Volvo worked with "Nordic Equity" @ 36 EUR/month
# Didn't work with "Turquoise ECNs and Gettex Europe" @ 9.5 GBP/month
# But didn't work with "European (BATS/Chi-X)" @ 31.5 GBP/month
?
# Nestle worked with "European (BATS/Chi-X) Equities" @ GBP 31.50/Month;?
# "SIX Swill Exchange" @ 32.5 CHF/Month partialy worked (would cause an error for 20 years of data request)
# "Tuquoise ECNs and Gettex" didn't work (same for Volvo - see above)
# Noticed that when using "SMART" for exchange getting different figures for Neste (vs. EOD and Yahoo Finance)
# Tried specific exchanges: AQXECH - no permission; BATECH: matched other databases; CHIXCH: permission but a few figures still wrong
# EBS - no permission; TRQXCH: no permission
?
contracts = {'NYSE listed 1':? ?['AAP',? ? 'SMART',? 'USD'],
? ? ? ? ? ? ?'NYSE listed 2':? ?['AGCO',? ?'SMART',? 'USD'],
? ? ? ? ? ? ?'Nasdaq listed 1': ['CHRW',? ?'SMART',? 'USD'],
? ? ? ? ? ? ?'Nasdaq listed 2': ['CSX',? ? 'SMART',? 'USD'],
? ? ? ? ? ? ?'Nasdaq listed 3': ['CHTR',? ?'SMART',? 'USD'],
? ? ? ? ? ? ?'Index':? ? ? ? ? ?['SPY',? ? 'SMART',? 'USD'],
? ? ? ? ? ? ?'Nestle':? ? ? ? ? ['NESN',? ?'BATECH', 'CHF'],
? ? ? ? ? ? ?'Volvo':? ? ? ? ? ?['VOLV.B', 'SFB',? ? 'SEK']}
?
#Create contract object
con = Contract()
con.secType = 'STK'
?
# short-term data
for c in contracts:
? ? con.symbol = contracts[c][0]
? ? con.exchange = contracts[c][1]
? ? con.currency = contracts[c][2]
?
? ? #Request Market Data
? ? reqId = 100
? ? app.data = []
? ? app.data_sent = -1
? ? app.reqHistoricalData(reqId, con, '', '2 W', '1 day', 'ADJUSTED_LAST', 1, 1, False, [])
? ? while app.data_sent != reqId:
? ? ? ? try:
? ? ? ? ? ? time.sleep(0.1)
? ? ? ? except:
? ? ? ? ? ? print("\nError while reading security "+contracts[c][0]+"\n")
? ? ? ? ? ? app.disconnect()
? ? ? ? ? ? sys.exit(1) # will exit code either due to an true error or if CTRL+C pressed
?
? ? # Work with "data" from IB API
? ? df = pandas.DataFrame(app.data, columns=['DateTime', 'Adj. Close'])
? ? df['DateTime'] = pandas.to_datetime(df['DateTime'], format='%Y%m%d')
? ? print('\n2 Weeks of price data for {}:\n'.format(con.symbol))
? ? print(df)
?
?
# long-term data
for c in contracts:
? ? con.symbol = contracts[c][0]
? ? con.exchange = contracts[c][1]
? ? con.currency = contracts[c][2]
?
? ? #Request Market Data
? ? reqId = 100
? ? app.data = []
? ? app.data_sent = -1
? ? app.reqHistoricalData(reqId, con, '', '20 Y', '1 day', 'ADJUSTED_LAST', 1, 1, False, [])
? ? while app.data_sent != reqId:
? ? ? ? try:
? ? ? ? ? ? time.sleep(0.1)
? ? ? ? except:
? ? ? ? ? ? print("\nError while reading security "+contracts[c][0]+"\n")
? ? ? ? ? ? app.disconnect()
? ? ? ? ? ? sys.exit(1) # will exit code either due to an true error or if CTRL+C pressed
?
? ? # Work with "data" from IB API
? ? df = pandas.DataFrame(app.data, columns=['DateTime', 'Adj. Close'])
? ? df['DateTime'] = pandas.to_datetime(df['DateTime'], format='%Y%m%d')
? ? print('\n20 years of price data for {}:\n'.format(con.symbol))
? ? print(df)
?
app.disconnect()
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: g++ command for including the proper libraries
On Wed, Aug 9, 2023 at 06:31 PM, blydon12@... wrote:
Sorry, I haven't used Windows since the early 2000s. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: g++ command for including the proper libraries
I've had no problems using g++ on windows for C++. I am just trying to see if anyone else has tried doing this successfully rather than using TwsApiL0 because I imagine the API was written in C++ to be used directly regardless of compiler or system. Otherwise, what are they doing over at Interactive Brokers? It doesn't make sense to me that I have to use some derivation of the API, and it is strange that everyone on here seems to be settling for that. With that being said, do you have any advice on how to link directly to the TWS API via g++ on windows? Any technical advice would be appreciated.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: g++ command for including the proper libraries
On Wed, Aug 9, 2023 at 04:32 PM, blydon12@... wrote:
You don't want a fuss but decided against using the de facto standard compiler for your platform? That sounds awfully silly to me... may I suggest you brace for some impact or, perhaps use the MSFT tools. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
g++ command for including the proper libraries
I have been trying to use the TWS API directly. I am not looking to use any wrapper that someone has created on GitHub in C++. Can someone direct me to a link on what g++ command to use to include the proper libraries?
Any help is appreciated. Here is my current batch file I have been running unsuccessfully. I get the same thing when trying the -m32 or -m64 flag. I also, have tried linking to TwsSocketClient.dll in the same fashion instead of biddll.dll via the directory "C:\IB_TWS\api\source\CppClient\client\Release" and/or "C:\IB_TWS\api\source\CppClient\lib" for TwsClientSocket.lib and get the same results. The docs say use TwsClientSocket.dll, but my way of doing that does not work. I am on windows here. set twsFull=C:\IB_TWS\api\source\CppClient\client
set twsLib=C:\IB_TWS\api\source\CppClient\client\lib
set twsBid=biddll
set headers=C:\Users\blydo\Repos\Cpp\IBMachLearn\headers
set src=C:\Users\blydo\Repos\Cpp\IBMachLearn\src
set exes=C:\Users\blydo\Repos\Cpp\IBMachLearn\exe
g++ -o %exes%\main.exe %src%\main.cpp -I%headers% -I%twsFull% -I%twsLib% -L%twsLib% -l%twsBid%
Output: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\IB_TWS\api\source\CppClient\client\lib/biddll.lib when searching for -lbiddll C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\IB_TWS\api\source\CppClient\client\lib/biddll.dll when searching for -lbiddll C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\IB_TWS\api\source\CppClient\client\lib/biddll.lib when searching for -lbiddll C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\IB_TWS\api\source\CppClient\client\lib/biddll.dll when searching for -lbiddll C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\IB_TWS\api\source\CppClient\client\lib\biddll.lib when searching for -lbiddll C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lbiddll: No such file or directory C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\IB_TWS\api\source\CppClient\client\lib/biddll.lib when searching for -lbiddll C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\IB_TWS\api\source\CppClient\client\lib/biddll.dll when searching for -lbiddll collect2.exe: error: ld returned 1 exit status |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: getting overnight trading bid/ask via api
Let the group know what you find. Not an area we are active in, but would be interesting to know.
toggle quoted message
Show quoted text
Also, keep in mind that the IBEOS/OVERNIGHT exchange supports only a tiny fraction of order types that regular exchanges allow. Specifically, "Market Orders" are not supported:
On Mon, Aug 7, 2023 at 02:17 PM, <TrumX@...> wrote:
Thanks a lot, I will test it! ?? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: getting overnight trading bid/ask via api
It is "Regular Trading Hours" just not for all exchanges. As the article you pointed to indicates, you need to select the exchange "IBEOS". Apparently an exchange name of "OVERNIGHT" works as well. tickByTickBidAsk should therefore provide data during the overnight session as long as the Contract object for the subscription call specifies one of those two exchanges. I say should since I have not tried that yet. But that is how market data selection works.
toggle quoted message
Show quoted text
From the ContractDetails object for AAA: "exchange" : "IBEOS",
"tradingHours" : "20230806:2000-20230807:0350;20230807:2000-20230808:0350;20230808:2000-20230809:0350;20230809:2000-20230810:0350;20230810:2000-20230811:0350"
"exchange" : "OVERNIGHT",
"tradingHours" : "20230806:2000-20230807:0350;20230807:2000-20230808:0350;20230808:2000-20230809:0350;20230809:2000-20230810:0350;20230810:2000-20230811:0350"
´³¨¹°ù²µ±ð²Ô On Mon, Aug 7, 2023 at 01:11 PM, <TrumX@...> wrote:
|