Home  Search  Register  Login  Recent Posts

Information on DTN's Industries:
DTN Oil & Gas | DTN Trading | DTN Agriculture | DTN Weather
Follow DTNMarkets on Twitter
DTN.IQ/IQFeed on Twitter
DTN News and Analysis on Twitter
»Forums Index »Archive (2017 and earlier) »IQFeed Developer Support »Open source IQFeed C# Socket Client now available supporting protocol 5.2
Author Topic: Open source IQFeed C# Socket Client now available supporting protocol 5.2 (9 messages, Page 1 of 1)

mathpaquette
-Interested User-
Posts: 22
Joined: May 18, 2018


Posted: May 18, 2018 06:41 AM          Msg. 1 of 9
Hello everyone,

I've developed and released to the open source community with the aim to be the more efficient, a C# IQFeed socket client. Have a look at the project. I'll develop all the features needed to support all the IQFeed functionalities.

https://github.com/mathpaquette/IQFeed.CSharpApiClient

Your feedbacks are welcome!
Mathieu

data_collector
-Interested User-
Posts: 6
Joined: Aug 9, 2018


Posted: Aug 9, 2018 09:59 AM          Msg. 2 of 9
Hi Mathieu,

Really appreciate your work. As a C# noob, I have a question:

In your historical example, you conclude with making a request and assigning it to ticksMessages. How can I view this in a data table format? I tried just viewing it via Console.WriteLine but it just seems to show the var like below:

System.Collections.Generic.List`1[IQFeed.CSharpApiClient.Lookup.Historical.Messages.TickMessage]


Thank you,
T

mathpaquette
-Interested User-
Posts: 22
Joined: May 18, 2018


Posted: Aug 9, 2018 04:45 PM          Msg. 3 of 9
Hi T,

Well, if you wish to see the result as a data table, I suggest you to use the Raw facade, i.e. lookupClient.Historical.Raw.ReqHistoryTickDatapointsAsync method and then open up the return filename in Excel as a CSV file.

The reason you it in that format its because I didnt override the ToString in the TickMessage class.

Please dont forget to star the project on github and you can also ask question over there!

Thank you,
Mathieu

AK786
-Interested User-
Posts: 21
Joined: Jul 17, 2018


Posted: Aug 9, 2018 05:30 PM          Msg. 4 of 9
data_collector, here is something i did to parse out the code from Matt P. I am storing Flat Files - you can write all teh data to a C# datatable object.

His code is awesome and has saved me 50+ hours - higher performance than the IQFeed examples IMO.

Also if there is bug, he serves us by fixing it in just a few hours if you send him an email


var tickData = await lookupClient.Historical.ReqHistoryTickTimeframeAsync(symbol, requestStartDate, requestEndDate, null, null, null, DataDirection.Oldest);

CreateTaskStoreTickMessages(symbol, tickData);



void CreateTaskStoreTickMessages(string symbol, IEnumerable<TickMessage> tickMessages)
{

Task.Factory.StartNew(() => StoreTickMessages(symbol, tickMessages, TickDirectory));
}

List<double> tickMessagesStoreRunTime = new List<double>();
object tickMessagesStoreLockObject = new object();
static string TickFileHeader = "Timestamp,Last,LastSize,TotalVolume,Bid,Ask,TickId,BasisForLast,TradeMarketCenter,TradeConditions";
void StoreTickMessages(string symbol, IEnumerable<TickMessage> tickMessages, string baseTickDirectory)
{
DateTime storeTickMessagesStartTime = DateTime.Now;

// All the Tick Data gets stored into "Date" Created Files By Symbol Name
List<TickMessage> tickMessagesCurrentDate = new List<TickMessage>();

DateTime previousDate = DateTime.MaxValue;
List<DateTime> datesProcessing = new List<DateTime>();

foreach (TickMessage message in tickMessages)
{
DateTime dateTime = message.Timestamp;
DateTime date = message.Timestamp.Date;

// New Date in Tick Messages
if (!datesProcessing.Contains(date))
{
datesProcessing.Add(date);

// Record Previous Date for the First Time
if (previousDate == DateTime.MaxValue)
{
previousDate = date;
}
else // Store the Previous Dates Data once New TimeStamp is triggered
{
StoreTickMessagesByDate(baseTickDirectory, previousDate, symbol, tickMessagesCurrentDate);

// Reset Data Structures
tickMessagesCurrentDate = new List<TickMessage>();

previousDate = date;
}
}

tickMessagesCurrentDate.Add(message);
}

// Store Data from Last Date
StoreTickMessagesByDate(baseTickDirectory, previousDate, symbol, tickMessagesCurrentDate);

TimeSpan storeTickMessagesRunTime = DateTime.Now.Subtract(storeTickMessagesStartTime);
double runTimeSeconds = Math.Round(storeTickMessagesRunTime.TotalSeconds, 4);
double avgRunTimeSeconds = 0;

lock (tickMessagesStoreLockObject)
{
tickMessagesStoreRunTime.Add(runTimeSeconds);

avgRunTimeSeconds = Math.Round(GetAverage(tickMessagesStoreRunTime), 2);
}

logger.Trace("StoreTickMessages: " + " Symbol: " + symbol + " Run Secs: " + runTimeSeconds + " Avg Run Secs: " + avgRunTimeSeconds);
}



void StoreTickMessagesByDate(string TickDirectory, DateTime date, string symbol, List<TickMessage> tickMessages)
{
string TickDirectoryDate = TickDirectory + date.ToString(SystemInfrastructure.DateFormat) + "\\";

// Create Date Directory only once
if (false == Directory.Exists(TickDirectoryDate))
{
Directory.CreateDirectory(TickDirectoryDate);
}

string symbolFileName = TickDirectoryDate + symbol + ".csv";

using (StreamWriter sw = new StreamWriter(symbolFileName))
{
sw.WriteLine(TickFileHeader);

foreach (TickMessage tickMessage in tickMessages)
{
string timeStamp = tickMessage.Timestamp.ToString(IQFeed.CSharpApiClient.Lookup.Historical.Messages.TickMessage.TickDateTimeFormat);
double Last = Math.Round(tickMessage.Last, 4);
int LastSize = tickMessage.LastSize;
long TotalVolume = tickMessage.TotalVolume;
double Bid = Math.Round(tickMessage.Bid, 2);
double Ask = Math.Round(tickMessage.Ask, 2);
long TickId = tickMessage.TickId;
char BasisForLast = tickMessage.BasisForLast;
int TradeMarketCenter = tickMessage.TradeMarketCenter;
string TradeConditions = tickMessage.TradeConditions;

string tickMessageCSV = TickMessageCSV(timeStamp, Last, LastSize, TotalVolume, Bid, Ask, TickId, BasisForLast, TradeMarketCenter, TradeConditions);

sw.WriteLine(tickMessageCSV);
}
}
}

AK786

data_collector
-Interested User-
Posts: 6
Joined: Aug 9, 2018


Posted: Aug 10, 2018 04:10 PM          Msg. 5 of 9
Haven't gotten around to playing around your code more but getting around to it now.

Thank you both and agree that it's been a huge help!

data_collector
-Interested User-
Posts: 6
Joined: Aug 9, 2018


Posted: Aug 14, 2018 09:14 PM          Msg. 6 of 9
AK786, I'm going through your code -- do you have def to the TickMessageCSV() function you use at the end, just before sw.WriteLine?

Sorry, I'm completely new to C# so taking a while for me to understand all of Mathieu's and your code but thank you for your help.

AK786
-Interested User-
Posts: 21
Joined: Jul 17, 2018


Posted: Aug 14, 2018 09:52 PM          Msg. 7 of 9
string TickMessageCSV(string timeStamp, double last, int lastSize, long totalVolume, double bid, double ask, long tickId, char basisForLast, int tradeMarketCenter, string tradeConditions)
{
StringBuilder sb = new StringBuilder(1000);

sb.Append(timeStamp).Append(",");
sb.Append(last).Append(",");
sb.Append(lastSize).Append(",");
sb.Append(totalVolume).Append(",");
sb.Append(bid).Append(",");
sb.Append(ask).Append(",");
sb.Append(tickId).Append(",");
sb.Append(basisForLast).Append(",");
sb.Append(tradeMarketCenter).Append(",");
sb.Append(tradeConditions).Append(",");

return sb.ToString();
}

I will post all my code here soon. I am in the process of Writing my Data Collection and storage handlers.

AK786

mathpaquette
-Interested User-
Posts: 22
Joined: May 18, 2018


Posted: Aug 15, 2018 06:24 AM          Msg. 8 of 9
Guys, dont hesitate to open an issue on GitHub rather than posting on this site.... I think its more related to the project itself.

Will always happy to help you out with that.
Mathieu

data_collector
-Interested User-
Posts: 6
Joined: Aug 9, 2018


Posted: Aug 15, 2018 08:21 AM          Msg. 9 of 9
@AK, THANK YOU!

Mathieur, will post if I come across more questions. Thank you.
 

 

Time: Fri March 28, 2025 1:44 AM CFBB v1.2.0 11 ms.
© AderSoftware 2002-2003