API Support Forum
OEC API > API Support > Real Time capturing data
Author Topic: Real Time capturing data
(8 messages, Page 1 of 1)
Moderators: VPfau
CBarabucci
Posts: 4
Joined: Mar 24, 2021

CB

Posted: Mar 25, 2021 @ 08:17 AM             Msg. 1 of 8
Hi, I've developed a Real Time capturing data software.
After Connection, Symbol Lookup and Contract choose, I subscribe the PriceChanged Event:

Client.Subscriptions.Price.PriceChanged += OnPriceChanged;

and in the:

private void OnPriceChanged(IGFClient client, PriceChangedEventArgs e)
{
StringBuilder data = new StringBuilder(e.Price.LastDateTime.ToLocalTime().ToString(), 30);
data.Append(";");
data.Append(e.Contract.PriceToString(e.Price.LastPrice));
data.Append(";");
data.Append(e.Price.LastVol);

lista.Add(data.ToString());
}


I add in a list named lista, my interesting data.

The program working fine, the data are correct more or less, if I check the captured data from my software, with the downloaded data from the GAIN Trader archive, some few data are missing, wich other are duplicated.

Naturally I check the same values of the same contract in the same interval of time, and they correspond for about 90%.

Are there possible to capture real time data with api, without differences, with the Gain Trader archive?
Thanks for answer.

CB
Edited by CBarabucci on Mar 25, 2021 08:30 AM
Edited by CBarabucci on Mar 25, 2021 03:52 PM
JSmith5611
Posts: 187
Joined:


Posted: May 03, 2021 @ 02:47 PM             Msg. 2 of 8
What archive are you comparing to?
Jason Smith
CBarabucci
Posts: 4
Joined: Mar 24, 2021

CB

Posted: May 03, 2021 @ 05:13 PM             Msg. 3 of 8
In the GAIN Trader Developer software, I set the contract of my interest NQM21
In Select period I chose: Tick
Indicator1: NQM21 History
Indicator2: Vol(NQM21) Volume
in the Data/ShowTable I can see the History and Volume, and with the right click a can save the archive in .csv file

I discovered that the LastPrice and the LastVol are not the same things of History and Volume, and my software working fine.
The problem is that I don't want LastPrice and LastVol, but I want closed price (History) and Volume.

Is it possible? How can I do this?

Thanks in advance to Jason and to anybody can help me
Edited by CBarabucci on May 03, 2021 05:26 PM
JSmith5611
Posts: 187
Joined:


Posted: May 04, 2021 @ 07:45 AM             Msg. 4 of 8
If you want to compare to tick history, you should be using a tick subscription instead of a price subscription:

Client.Subscriptions.Ticks.TicksReceived += ....

Tick subscriptions provide every price change, and therefore have considerably more data, so you have a much lower limit of how many can be running at once.
Jason Smith
CBarabucci
Posts: 4
Joined: Mar 24, 2021

CB

Posted: May 04, 2021 @ 12:43 PM             Msg. 5 of 8
Great, I've readed Ticks documentation.

I tried to read every 10 seconds with timer, the last 90seconds Ticks, I don't need more data, I need small updates, but every seconds.


private void timer1_Tick(object sender, EventArgs e)
{
// Request ticks for the last 90 seconds
gfClient.Subscriptions.Ticks.Subscribe(contratto.ID, gfClient.Subscriptions.Ticks.Duration.Create(DateTime.UtcNow.AddSeconds(-90), DateTime.UtcNow));

}


and when the data are received, I load there in lista:


private void GFClient_OnTicksReceived(IGFClient client, GF.Api.Subscriptions.Ticks.TicksReceivedEventArgs e)
{

lista.Clear();

foreach (var tick in e.Ticks)
{
DateTime data = tick.Timestamp.ToLocalTime();
StringBuilder record = new StringBuilder(data.Year.ToString());
record.Append("/");
record.Append(data.Month.ToString("00"));
record.Append("/");
record.Append(data.Day.ToString("00"));
record.Append(" ");
record.Append(data.ToLongTimeString());
record.Append(";");
record.Append(tick.Price.ToString("0.00").Replace(",","."));
record.Append(";");
record.Append(tick.Volume);

lista.Add(record.ToString());
// ....
//....
}
}


But in lista for 29 seconds, I receive every time the same Ticks, and after 30 seconds the Ticks are update with the new Ticks, now the list are perfect, bat the update is too slow every 30 second...

Are there something wrong in my code?
Could I receive the possible 20 Ticks per second every 1 or 2 seconds?
The GAIN Trader Developer 4.0, it do.

Thanks a lot
Edited by CBarabucci on May 04, 2021 01:23 PM
JSmith5611
Posts: 187
Joined:


Posted: May 06, 2021 @ 11:36 AM             Msg. 6 of 8
What I think you need is to change your tick subscription from one-time to continuous.

var sub = gfClient.Subscriptions.Ticks.Duration.Create(DateTime.UtcNow.AddSeconds(-90))

this will request all the ticks starting 90 seconds ago, and continue recieving new ones as they are generated by the exchange until you manually end the subscription by doing sub.Unsubscribe()
Jason Smith
CBarabucci
Posts: 4
Joined: Mar 24, 2021

CB

Posted: May 06, 2021 @ 02:03 PM             Msg. 7 of 8
Yesss, understood....
My new code for start Subscribction:

private void butTicksEnabled_Click(object sender, EventArgs e)
{
// Request ticks for the last 1 sec
gfClient.Subscriptions.Ticks.TicksReceived += GFClient_OnTicksReceived;
gfClient.Subscriptions.Ticks.Subscribe(contratto.ID, Client.Subscriptions.Ticks.Duration.Create(DateTime.UtcNow.AddSeconds(-1)));
}


and the code when received data:

private void GFClient_OnTicksReceived(IGFClient client, GF.Api.Subscriptions.Ticks.TicksReceivedEventArgs e)
{
lista.Clear();
foreach (var tick in e.Ticks)
{
DateTime data = tick.Timestamp.ToLocalTime();
StringBuilder record = new StringBuilder(data.Year.ToString());
record.Append("/");
record.Append(data.Month.ToString("00"));
record.Append("/");
record.Append(data.Day.ToString("00"));
record.Append(" ");
record.Append(data.ToLongTimeString());
record.Append(";");
record.Append(tick.Price.ToString("0.00").Replace(",","."));
record.Append(";");
record.Append(tick.Volume);
lista.Add(record.ToString());
}
System.IO.File.AppendAllLines("G:\\nql\\tiks.txt", lista);
}


For stopping reading I used:

private void butTicksDisabled_Click(object sender, EventArgs e)
{
gfClient.Subscriptions.Ticks.TicksReceived -= GFClient_OnTicksReceived;
}


I don't know if there is another way for stop it, perhaps the property .Unsubscribe() is supported...

But the more important thing is that now working fine, my data are perfect and I don't need Timer, because every second I receive data, thanks you very much!!!
JSmith5611
Posts: 187
Joined:


Posted: May 06, 2021 @ 02:26 PM             Msg. 8 of 8
the line gfClient.Subscriptions.Ticks.Subscribe(contratto.ID, Client.Subscriptions.Ticks.Duration.Create(DateTime.UtcNow.AddSeconds(-1)));

returns a subscription object that you use to unsubscribe.
Jason Smith