Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Question about News and Broad Tape ( BRFG, DJNL, BZ)
Hi,
I have activated Benzinga API free trial and successfully get the news and the articles if I request, I can get BRFG, DJNL and BZ, no issues but... 1. For some articles I get no stock ticker code in the news article. When I check the news content from TWS, I see the text without any clickable link in it but there is a small box/button at the bottom which contains ticker code. But this ticker code is not placed in the article which I receive from the API. 2. More importantly, I see some BZ hot news entries in the company specific news of a stock but they are not listed in the Broad Tape news panel. I assume Broad Tape is the news selection for all the subscribed news and should contain company specific news also but it is not. The news entry which I see in the company specific new panel is not listed in the Broad tape panel and also not sent to API. I could not find any option to exclude/include some news about company on broad tape. Anyone has an idea ?? Thanks in advance. Here the code for getting all the news.? Contract contractBRFG = new Contract();
contractBRFG.symbol("BRFG:BRFG_ALL"); //Briefing.com General Market Columns (BRFG) contractBRFG.secType("NEWS");
contractBRFG.exchange("BRFG");?
? ? ? ??
Contract contractDJNL = new Contract(); contractDJNL.symbol("DJNL:DJNL_ALL"); //Dow Jones Newsletters (DJNL)
contractDJNL.secType("NEWS");
contractDJNL.exchange("DJNL");?
? ? ? ??
Contract contractBZ = new Contract();
contractBZ.symbol("BZ:BZ_ALL"); //BroadTape All News
contractBZ.secType("NEWS");
contractBZ.exchange("BZ"); //Benzinga Pro
clientSocket.reqMktData(1000, contractBRFG, "mdoff,292", false, false, null); clientSocket.reqMktData(1001, contractDJNL, "mdoff,292", false, false, null);
clientSocket.reqMktData(1002, contractBZ, "mdoff,292", false, false, null); ?
?
?
? |
Re: NameError: name 'COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID' is not defined
The comment I just made it the post "Time conditions" applies here, too. The code snippets in the documentation are automatically extracted from source code and often need additional code to work properly. In your case, COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID is a constant that is defined in the Order class around the 10.15 API version. When you look at the complete code sample at? "samples/Python/Testbed/OrderSamples.py" in your TWS API download you will see that IBKR imports the definition as: from ibapi.order import (OrderComboLeg, Order, COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID)
´³¨¹°ù²µ±ð²Ô On Sun, Jan 1, 2023 at 11:14 AM, GreenGreen wrote:
... |
Re: Time conditions
The documentation is not outdated (at least not for ) but all code snippets are just that, snippets that are automatically extracted from source code and that need more context to work, In your case, take a look at the file "samples/Python/Testbed/OrderSamples.py" in the TWS API you have downloaded from IBKR. It contains the complete function "TimeCondition" that the snippet came from. You will see that? "isMore" is a boolean value that controls whether the condition should be active after (isMore true) the time you specify or before and at the time (isMore false). ´³¨¹°ù²µ±ð²Ô |
Child order when main position is closed
I am placing main parent order to buy IBM @ $140 and also placing two child orders stop loss @ $120 and take profit @ $160. My two child orders become active once parent order is exercised. Assume that I decide to close position @ $130.? Do I need manually close my child orders (with 'cancelOrder') or is there way to let TWS know that child orders should be cancelled once position is liquidated?
|
Time conditions
Hello Everyone ,?
I am new in this forum and I hope you will be able to help me? I am desesperatly trying to put an order with a time condition , but the documentation seems to be reaaly outdated ... first of all when? I copy what's written in there ( I write in python ) , I get an error message that I can't use the append method ... Then when I manage to write the order the attributes etc it tells me that I have to add about all (!!)? the attributes which are in the order.py file ... Then I get error messages about the isMore that I don't understand .... Could anyone help me ? Has anyone written a code with a time condition order and could give me tips ? thanks !!! |
Re: NameError: name 'COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID' is not defined
Sorry, I skipped chunk of my code thinking that it is not relevant, but now I am guessing that my error is coming from openOrder function. Here is missing part of my code:
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.ticktype import TickTypeEnum
import time
import datetime
import threading
from ibapi.contract import Contract
from ibapi.order import Order
?
?
class TestApp(EWrapper, EClient):
? ? def __init__(self):
? ? ? ? EClient.__init__(self, self)
? ? ? ? self.nextValidOrderId = None
? ? ? ??
?
? ? def nextValidId(self, orderId: int):
? ? ? ? super().nextValidId(orderId)
? ? ? ? self.nextValidOrderId = orderId
? ? ? ? print("NextValidId:", orderId)
? ? ? ??
? ? def error(self, reqId, errorCode, errorString, advancedOrderRejectJson):
? ? ? ? print("Error: ", reqId, " ", errorCode, " ", errorString, "", advancedOrderRejectJson)
? ??
?
? ? ? ??
? ? def openOrder(self, orderId, contract, order,
? ? ? ? ? ? ? ? ? ? ? ?orderState):
? ? ? ? super().openOrder(orderId, contract, order, orderState)
? ? ? ? print("OpenOrder. PermId:", order.permId, "ClientId:", order.clientId, " OrderId:", orderId,?
? ? ? ? ? ? ? ? ? ?"Account:", order.account, "Symbol:", contract.symbol, "SecType:", contract.secType,
? ? ? ? ? ? ? ? ? ?"Exchange:", contract.exchange, "Action:", order.action, "OrderType:", order.orderType,
? ? ? ? ? ? ? ? ? ?"TotalQty:", order.totalQuantity, "CashQty:", order.cashQty,?
? ? ? ? ? ? ? ? ? ?"LmtPrice:", order.lmtPrice, "AuxPrice:", order.auxPrice, "Status:", orderState.status,
? ? ? ? ? ? ? ? ? ?"MinTradeQty:", order.minTradeQty, "MinCompeteSize:", order.minCompeteSize,
? ? ? ? ? ? ? ? ? "competeAgainstBestOffset:",
? ? ? ? ? ? ? "UpToMid" if order.competeAgainstBestOffset == COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID else order.competeAgainstBestOffset,
? ? ? ? ? ? ? ? ? "MidOffsetAtWhole:", order.midOffsetAtWhole,"MidOffsetAtHalf:" ,order.midOffsetAtHalf)
? ??
? ? ? ? order.contract = contract
? ? ? ? self.permId2ord[order.permId] = order
? ??
? ??
? ? def orderStatus(self, orderId, status, filled,
? ? ? ? ? ? ? ? ? ? ? ? ?remaining, avgFillPrice, permId,
? ? ? ? ? ? ? ? ? ? ? ? ?parentId, lastFillPrice, clientId,
? ? ? ? ? ? ? ? ? ? ? ? ?whyHeld, mktCapPrice):
? ? ? ? super().orderStatus(orderId, status, filled, remaining,
? ? ? ? ? ? ? ? avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld, mktCapPrice)
? ? ? ? print("OrderStatus. Id:", orderId, "Status:", status, "Filled:", decimalMaxString(filled),
? ? ? ? ? ?"Remaining:", remaining, "AvgFillPrice:", avgFillPrice,
? ? ? ? ? ?"PermId:", permId, "ParentId:", parentId, "LastFillPrice:",
? ? ? ? ? ?lastFillPrice, "ClientId:", clientId, "WhyHeld:",
? ? ? ? ? ? ? ? ? ? whyHeld, "MktCapPrice:", mktCapPrice)
I can surely delete offending statement, but just curious what is the purpose of it? Plus I copied openOrder function directly from official documentation.? ? ??
|
NameError: name 'COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID' is not defined
I am trying to place an order (Python):
?
contract = Contract()
contract.symbol = "SPY"
contract.secType = "STK"
contract.exchange = "SMART"
contract.currency = "USD"
contract.primaryExchange = "ARCA"
?
order = Order()
order.action = 'BUY'
order.totalQuantity = 1
order.orderType = 'LMT'
order.lmtPrice = '20' app = TestApp()
app.connect("127.0.0.1", 7497, 1)
api_thread = threading.Thread(target=app.run)
api_thread.start()
time.sleep(1)
app.placeOrder(app.nextValidOrderId, contract, order) ?
And end up with the following error:? Error:? -1? ?2104? ?Market data farm connection is OK:hfarm??
Error:? -1? ?2104? ?Market data farm connection is OK:usfarm.nj??
Error:? -1? ?2104? ?Market data farm connection is OK:jfarm??
Error:? -1? ?2104? ?Market data farm connection is OK:cashfarm??
Error:? -1? ?2104? ?Market data farm connection is OK:eufarmnj??
Error:? -1? ?2104? ?Market data farm connection is OK:usfarm??
Error:? -1? ?2106? ?HMDS data farm connection is OK:euhmds??
Error:? -1? ?2106? ?HMDS data farm connection is OK:cashhmds??
Error:? -1? ?2106? ?HMDS data farm connection is OK:fundfarm??
Error:? -1? ?2106? ?HMDS data farm connection is OK:ushmds??
Error:? -1? ?2158? ?Sec-def data farm connection is OK:secdefil??
Exception in thread Thread-6 (run):
Traceback (most recent call last):
? File "/home/some_user/anaconda3/envs/env1/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
? ? self.run()
? File "/home/some_user/anaconda3/envs/env1/lib/python3.10/threading.py", line 946, in run
? ? self._target(*self._args, **self._kwargs)
? File "/home/some_user/anaconda3/envs/env1/lib/python3.10/site-packages/ibapi-10.19.1-py3.10.egg/ibapi/client.py", line 263, in run
? File "/home/some_user/anaconda3/envs/env1/lib/python3.10/site-packages/ibapi-10.19.1-py3.10.egg/ibapi/decoder.py", line 1387, in interpret
? File "/home/some_user/anaconda3/envs/env1/lib/python3.10/site-packages/ibapi-10.19.1-py3.10.egg/ibapi/decoder.py", line 219, in processOpenOrder
? File "/tmp/ipykernel_2721/690135804.py", line 37, in openOrder
NameError: name 'COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID' is not defined
Error:? 3? ?399? ?Order Message: BUY 1 SPY ARCA Warning: your order will not be placed at the exchange until 2023-01-03 09:30:00 US/Eastern?
In TWS I can see that order is placed, but I wonder what this error? 'COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID' is about.? Here are some details about TWS and API module? ibapi.__version__ =?'10.19.1' TWS =?Build 10.19.1i, Dec 13, 2022 1:57:49 PM |
Re: Paper trading account value reset
Thank you, Richard!
I went to interactivebrokers.com and logged into paper account and got the same result as you showed above (except I did not have to click human icon, there was already link settings under human icon). Then I also tried alternative approach.? - Launch TWS paper trading - Go to Account menu, then Account Management Home.? - It will bring up browser with live account,? - Log out of it and login into paper account.? - Then clicking human sign and Settings after it bring something like this. Well, this is a bit strange, but I am glad your approached worked, I am going to use it. |
Re: Paper trading account value reset
¿ªÔÆÌåÓýAttached is what I see when I click the human icon and then click ¡®Account Settings¡¯ (NOT ¡®User Settings¡¯). ? ¡®Paper Trading Account Reset¡¯ is the last item. ? If you don¡¯t see that, show us what you do see. |
Re: Paper trading account value reset
Sorry, I am still not able to see Paper Trading Account Reset.?
I logged into my paper account via browser.? I clicked on human icon in the top right corner, then I clicked Settings. It loaded page with many linked but none of them says Paper Trading Account Rest. The closest I can see is: Paper Trading Account. When I click it, it gives me username and password, option to reset password and some other option, but there is not option to reset paper account value. |
Re: Running TWS Gateway under WSL2
Thanks.
I think, `export GDK_BACKEND=x11` and subsequently calling ibgateway (or tws) solves the problem, too. Then automation via IBC should work, too. FYI: We set up the TWS/ibgateway in a LXD-Container running in the WSL2 environment. So far, we did no to run into this feature. The container is build using the ib-container-script (). Option is to forward the screen via x2go and access it from windows (and also remotely) hartmut |
Running TWS Gateway under WSL2
As many may know, Windows 10 and 11 now officially supports running Linux GUI software. I have attempted to run TWS Gateway under WSL2 Ubuntu 22.04 but it failed with a cryptic GTK error: `?gdk_x11_display_set_window_scale: assertion 'GDK_IS_X11_DISPLAY (display)' failed`. The solution is to append `GDK_BACKEND=x11` to the invocation command, i.e. `GDK_BACKEND=x11 ./ibgateway`. I am documenting it here for posterity, in case anyone else runs into the same problem.
|
Re: historical ticks (time and sales)
Thx very much for your answer. The request is fine, no problem on that side. It works perfectly for any date AFTER 2022-11-11 and it has been for more than 3 years I have been downloading these data.
Tried a lot of different things, like changing the starting time, the timezone (old way, with US/Central or their specification to use UTC) or number of ticks. I even modified my code to work reverse (ie setting end time and asking for 1000 ticks). Nothing. What I noticed as being peculiar is that for any date before 2022-11-11 I receive first a callback on historicalTicksLast() (same for BidAsk) with no ticks, and done=false. This never happens normally. Then I receive an extra callback with ticks and done=false, and then infinitely many callbacks with ticks and done=false. Usually, and this is the case now with dates after 2022-11-11, I get a callback on historicalTicksLast() with ticks and done=false (sometime done=true). Then I receive an extra callback with no ticks and done=true. This change of behaviour on a particular date is really puzzling and I was wondering if anybody is experiencing the same when asking for data for a future before 2022-11-11. |
Re: historical ticks (time and sales)
Can you submit a small code snippet that show the request you make/made and the value of each fields of the request ? without request with the params that trigger what you report, I may just suggest some trial as way to speed up a fix or workaround oddities or bugs. |
historical ticks (time and sales)
I have noticed a strange behaviour of historicalTicksLast() for dates before 2022-11-11.
For the context., to download intraday time & sales data for futures for the full day, I follow the usual way: - ask first for 00:00:00 and 1000 ticks - identify last time of data, add 1 second and send a new request with that new time for 1000 more ticks - and so on until the end of the day. This always worked like a charm, and still does. However, if I ask data (say Dec contract ES/CME) before 2022-11-11, whatever the contract I ask, I receive data backwards, from 5PM Eastern, like 16:33:34 tp 16:59:59, done is false and a second later I receive another callback, for data between 16:21:19 and 16:33:33, and so on. I do not send any request. They just keep on coming automatically. done is never TRUE. I experienced this behaviour with different API versions, and still with the most recent 10.20. This is not an issue with time zones as I take care of that and it works perfectly from 2022-11-14. First, is anybody experiencing the same behaviour? Second any idea why this is happening? Yet another undocumented new "feature"? Following the communication fiasco of both the 2 factors identification and exchange name change nothing would surprise me anymore from IB. Thanks in advance for any insight regarding this issue! |
Unadjusted historical prices.
Hi, All,
Is it possible to obtain historical daily prices that are NOT adjusted for either splits or dividends using the IBKR API? ?? This seems like it should be pretty easy, but I can't seem to find the right information in the API documentation. Suggestions on the best way to request (or calculate) unadjusted daily prices? Thanks to all for answers! ? |