¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io
Date

Re: Wrong requested positions

 

¿ªÔÆÌåÓý

This group is targeted at the TWSAPI implementations provided by IBKR, so your question is really out of scope and you're quite likely not to get any other replies, but you never know ¨C there may be another IB4m user who can help.

?

It might be helpful if you explain what is wrong with the contents of the M_position matrix.

?

I suggest you also follow the 'Getting More Help' link on the IB4m GitHub repository, if you haven't already done so: that's likely to be a more targeted audience.

?

Richard King

TWSAPI Group Owner and Moderator

?

?

From: [email protected] <[email protected]> On Behalf Of domme83@...
Sent: 13 August 2021 10:01
To: [email protected]
Subject: [TWS API] Wrong requested positions

?

Hi,
I use MatLab with IB4m to get IB messages via API.
I have a problem when I request my positions via API using the following code:


clear all; close all; clc;
?
percorso = 'W:\Software\IB4m-master\IB4m-master';
?
addpath(percorso); addpath(percorso,fullfile(percorso,'docs'))
javaaddpath(fullfile(percorso,'Jar','TWS973.jar'))
?
% initialize session with TWS
session = TWS.Session.getInstance();
?
% create local buffer for historical data events 
[bufP,lhP] = TWS.initBufferForEvent({
??? TWS.Events.POSITIONS,...
??? });
?
% connect to TWS
session.eClientSocket.eConnect('127.0.0.1',7496,0); pause(1)
?
session.eClientSocket.reqPositions(); pause(0.5)
?
hde = bufP.get();
?
cell_position = collection2cell(hde.data);
?
M_position = {};
?
for i = 1:size(cell_position,1)
??? 
????M_position{i,1} = char(cell_position{i}.contract.symbol);
??? 
????M_position{i,2} = char(cell_position{i}.contract.exchange);
??? 
????M_position{i,3} = cell_position{i}.position;
??? 
end


Sometimes the M_position matrix is ??wrong even if I wait a few minutes after the execution of all the orders.

Why does this happen?

Best Regards.
Domenico.


Wrong requested positions

 

Hi,
I use MatLab with IB4m to get IB messages via API.
I have a problem when I request my positions via API using the following code:

clear all; close all; clc;

percorso = 'W:\Software\IB4m-master\IB4m-master';

addpath(percorso); addpath(percorso,fullfile(percorso,'docs'))
javaaddpath(fullfile(percorso,'Jar','TWS973.jar'))

% initialize session with TWS
session = TWS.Session.getInstance();

% create local buffer for historical data events 
[bufP,lhP] = TWS.initBufferForEvent({
    TWS.Events.POSITIONS,...
    });

% connect to TWS
session.eClientSocket.eConnect('127.0.0.1',7496,0); pause(1)

session.eClientSocket.reqPositions(); pause(0.5)

hde = bufP.get();

cell_position = collection2cell(hde.data);

M_position = {};

for i = 1:size(cell_position,1)
    
    M_position{i,1} = char(cell_position{i}.contract.symbol);
    
    M_position{i,2} = char(cell_position{i}.contract.exchange);
    
    M_position{i,3} = cell_position{i}.position;
    
end

Sometimes the M_position matrix is ??wrong even if I wait a few minutes after the execution of all the orders.

Why does this happen?

Best Regards.
Domenico.


Re: TickByTick data outage during the night?

 

Computer and TWS are both set to Chicago time. The crosshair is at 12 August 03:45. Excuse the white lines.

KH


Re: TickByTick data outage during the night?

Nick
 

I just checked and on the ES I am seeing empty (15min) bars from 4:40 to 7:00 Eastern Time inclusive.

On 8/12/2021 4:31 PM, ´³¨¹°ù²µ±ð²Ô Reinold via groups.io wrote:
So here is a new one for me. Did anyone else experience TickByTick data outage during the night?


Re: TickByTick data outage during the night?

 

Now that is interesting, Kevin. Thank you for sharing.

My TWS 981.2w just had the daily restart(we do that at 16:45 Chicago Time) and
  • It still shows the data gaps for ES, VX, YM, ZN
  • I also checked MES (was not in my favorites before) and it shows the gap
  • Gaps also show for Forex EUR.USD and EUR.AUD
But European DAX future FDXM SEP 21 is fine.

´³¨¹°ù²µ±ð²Ô


On Thu, Aug 12, 2021 at 05:06 PM, Kevin wrote:
Hello
I don't use TickByTick, but my TWS charts for ES and MES show normal bars during the time period you mention.
TWS was operating normally during this time period (early evening in Sydney).
KH


Re: TickByTick data outage during the night?

 

Hello
I don't use TickByTick, but my TWS charts for ES and MES show normal bars during the time period you mention.
TWS was operating normally during this time period (early evening in Sydney).
KH


TickByTick data outage during the night?

 

So here is a new one for me. Did anyone else experience TickByTick data outage during the night?

  • Between 03:26 and 06:26, no TickByTick values were delivered for the instruments we monitor. (Chicago Time)
  • But all other level I and level II market data did arrive timely.
  • Also, TWS charts show a gap for that time frame. See below ES, VX, YM, and ZN.

All evidence indicates that trading took place normally and, for example, "Volume" and "RtTradeVolume" market data ticks agree that just over 24,000 ESU1 contracts traded during that time frame.

I cannot find any error messages or warnings, no TWS disconnects, no Market Data Farm warnings, ...

The exact time frame was [1628756782601, 1628767570816] just shy of exactly 3hrs

  • Thursday, August 12, 2021 3:26:22.601 AM GMT-05:00 DST
  • Thursday, August 12, 2021 6:26:10.816 AM GMT-05:00 DST


Re: Forex vs stocks

 

Rob, wouldn't micro futures increase the cost of transactions by a
significant amount over trader equivalent amount of e-minis?

On Wed, Aug 11, 2021 at 10:22 PM RobDawg35 <rob.sandberg26@...> wrote:

Do micro futures, it's more fun. Although, meeting somebody at a bar and telling them you're a "forex trader" does have a nice ring to it...

On Wed, Aug 11, 2021 at 10:02 PM mark M <write2mark1@...> wrote:

I should second Corneliu and add that stocks and futures are much safer to algo trade than forex
I have no experience with forex

On Wed, Aug 11, 2021, 3:59 PM corneliu maftuleac <corneliu.maftuleac@...> wrote:

Forex market is decentralized, way more complex, sometimes random and there are a lot of brokers that literally rip users off.
It's also notoriously for being almost impossible to predict.

Stocks is way more safer instrument, just buy and hold.


Re: Forex vs stocks

Nick
 

It's worth differentiating between the cash market (what is usually called forex) and currency futures.

With the cash market each broker makes their own market so each broker is a separate market.

Currency futures trade at an exchange like stocks so everyone sees the same prices.

On 8/11/2021 6:59 PM, corneliu maftuleac wrote:
Forex market is decentralized, way more complex, sometimes random and there are a lot of brokers that literally rip users off.


Re: Forex vs stocks

 

Except cases when you exchange one currency on another,
forex trading usually have higher costs for client and more interesting to broker
(than clients trading futures or buying and holding stocks).
So brokers more interested to advertise and promote forex (and doing it in countries with loose regulation)

But broker statistics tell that 70-90% of investors loose money on Forex, so your chances here are much lower
than on stock market, probably.


Re: Forex vs stocks

 

Do micro futures, it's more fun. Although, meeting somebody at a bar and telling them you're a "forex trader" does have a nice ring to it...


On Wed, Aug 11, 2021 at 10:02 PM mark M <write2mark1@...> wrote:
I should second Corneliu and add that stocks and futures are much safer to algo trade than forex?
I have no experience with forex

On Wed, Aug 11, 2021, 3:59 PM corneliu maftuleac <corneliu.maftuleac@...> wrote:
Forex market is decentralized, way more complex, sometimes random and there are a lot of brokers that literally rip users off.
It's also notoriously for being almost impossible to predict.

Stocks is way more safer instrument, just buy and hold.


Re: Forex vs stocks

 

I should second Corneliu and add that stocks and futures are much safer to algo trade than forex?
I have no experience with forex

On Wed, Aug 11, 2021, 3:59 PM corneliu maftuleac <corneliu.maftuleac@...> wrote:
Forex market is decentralized, way more complex, sometimes random and there are a lot of brokers that literally rip users off.
It's also notoriously for being almost impossible to predict.

Stocks is way more safer instrument, just buy and hold.


Re: Excel

 

Yes. I have used Excel to develop VBA based (ActiveX API) trading system which takes data, analyses and sends orders to TWS.?

The main issues you can expect are
1. Excel will go into unresponsive state when any script is running.?
2. Parallel processing is not achievable easily

I have a system in place which trades twice in a day.?

Thanks
Pratik


Re: Forex vs stocks

corneliu maftuleac
 

Forex market is decentralized, way more complex, sometimes random and there are a lot of brokers that literally rip users off.
It's also notoriously for being almost impossible to predict.

Stocks is way more safer instrument, just buy and hold.


Re: Forex vs stocks

aussie_dan
 

I'm a relative noob when it comes to algo trading, but I've been working on a US small caps stock algo for about 8 months now.
it's not a pure algo - I need to manually select the stocks I want the algo to trade each day - but trading decisions and risk management are all automated
so far I've been able to make it very profitable in backtesting, on over 12 months worth of data, but still working on profitability IRL?

I provide this background to respond to your questions:
first of all, forex provides a focused set of pairs (instruments) to backtest an algo on, and forex is widely considered the "fairest" market and therefore ripe for technical analysis to actually work on a consistent basis. just a couple reasons why I think most algo traders focus on fx?
but to answer your second question, I do truly believe similar benefits can be obtained by an algo trading stocks. in my short time focusing on US small caps, I've identified very common patterns that occur on a regular basis that have informed my various strategies. the problem I have is addressing what I call the "edge cases", i.e. the uncommon, but still repeated patterns that occur.?

now having said all of that, I've just now turned (half) my attention to forex to try to start discovering and implementing strategies in an algo. but I know I have a long road ahead of me.


Re: grab ExecDetails before disconnecting

 

You may want to try using the execDetailsEnd callback, which tells you when TWS/Gateway has finished sending executions


Re: 700% financing charges on a self funding portfolio

 

You definitely have to pay the dividend for borrowed stocks you are short. It happened many times to me.


Re: Excel

Paul Kranz
 

Does anyone use Excel to trade with TWS API? Paul sends...


On Wed, Aug 11, 2021, 2:07 AM Mikhail Ershov <misha-ershov@...> wrote:
It's different technologies of exchanging data with Excel.


I haven't dived too much in all that technologies, DDE should be most simple (although it seems you should type formulas, too)
but most limited, you can just stream some data into your excel, but can't do trading activity through excel.
ActiveX have more opportunities, but it looks like programming scripts on VBA.


Re: 700% financing charges on a self funding portfolio

 

Yes, way off topic! :-D

Curious to see how the aforementioned conflict is resolved...?

Thanks

Am Di., 10. Aug. 2021 um 22:42?Uhr schrieb JR via <TwsApiOnGroupsIo=[email protected]>:

Fascinating but probably way off topic for our TWS API group.

Investing in general and in particular short selling come with a lot of fine print and the rules are often very different around the world. Having said that, with very little research effort you can find that Drast and G-Money are indeed correct and holding short positions does expose you (in the US) to dividend payment liabilities.
  • Just swing by the U.S Securities and Exchange Commission at
  • Or Investopia at
  • Or PocketSense at
JR


Re: An Additional Group Moderator

 

Dear ´³¨¹°ù²µ±ð²Ô,
thank you for accepting the role as moderator for this group. I hope that all members will continue to remain well-behaved and that you won't need to intervene often.