Join the 80,000 other DTN customers who enjoy the fastest, most reliable data available. There is no better value than DTN!

(Move your cursor to this area to pause scrolling)




"I will tell others who want to go into trading that DTN ProphetX is an invaluable tool, I don't think anyone can trade without it..." - Comment from Luther
"This is an excellent value, the system is generous (allowing for 500 stocks) and stable (and really is tick-by-tick), and the support is fantastic." - Comment from Shirin via Email
"I'm very glad I switched to IQFeed. It's working perfectly with no lag, even during fast market conditions." - Comment from Andy via Email
"Interactive Brokers tick data was inconsistent, so I have switched to using DTN exclusively. It is great to no longer have to worry about my datafeed all day long." - Comment from Philippe
"Previously I was using *******. IQFeed is WAY more economical, and for my charting needs is just as good, if not better." - Comment from Public Forum Post
"You are much better than lawyers or the phone company because you answer the phone when I call! I just love your customer service." - Comment from Isreal
"I'm satisfied with IQFeed. It's the most reliable and fastest quote feed I have ever used. Although I'm a resident in China, it's still very fast!" - Comment from Xiaofei
"Just a quick one to say I'm very impressed so far :) The documentation for developers is excellent and I've quickly managed to get an app written to do historical downloads. The system is very robust and pretty quick considering the extent of data that's available. The support guys have been very helpful too, in combination with the forums it's been plain sailing so far!" - Comment from Adam
"Boy, probably spent a thousand hours trying to get ******* API to work right. And now two hours to have something running with IQFeed. Hmmm, guess I was pretty stupid to fight rather than switch all this time. And have gotten more customer service from you guys already than total from them… in five years." - Comment from Jim
"I am very pleased with the DTNIQ system for quotes and news." - Comment from Larry
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 »IQFeed .NET C# sockets example using IQ32.dll
Author Topic: IQFeed .NET C# sockets example using IQ32.dll (5 messages, Page 1 of 1)

Dennis
-Interested User-
Posts: 19
Joined: Oct 8, 2004


Posted: Oct 26, 2004 05:36 PM          Msg. 1 of 5
This may be of interest to some:

///////////////////////////////////////////////////////////////////////////////////
// console_stream.cs, version 1.0, copyright 2004
// IQFeed .NET C# sockets example using IQ32.dll
//
// contributed to the IQFeed Developer Support Forum
// by Dennis Sanders (forum username: Dennis)
// email: dennissanders@intsvcs.com
///////////////////////////////////////////////////////////////////////////////////

using System;
using System.Threading;
using System.Net.Sockets;
using System.Runtime.InteropServices;

public delegate void Callback(int x, int y);

class IQFeed_NETSocket_Example
{
[DllImport("IQ32.dll")]
public static extern void SetCallbackFunction(Callback SetGoodToGo);
[DllImport("IQ32.dll")]
public static extern int RegisterClientApp(IntPtr hClient, string szProductName,
string szProductKey, string szProductVersion);
[DllImport("IQ32.dll")]
public static extern void RemoveClientApp(IntPtr hClient);

public static bool GoodToGo = false;

public static void SetGoodToGo(int x, int y)
{
GoodToGo = (x==0 && y==0);

if (x==1 && y==1)
{
Console.WriteLine("IQFeed delivered close message");
RemoveClientApp(IntPtr.Zero);
}
}

public static void Main()
{
Callback IQFeed_CallBack = new Callback(IQFeed_NETSocket_Example.SetGoodToGo);
SetCallbackFunction(IQFeed_CallBack);

RegisterClientApp(IntPtr.Zero, "IQFEED_DEMO", "1.0", "1.0");

while (!GoodToGo)
Thread.Sleep(100);

try
{
String server = "127.0.0.1";
Int32 port = 5009;
TcpClient client = new TcpClient(server, port);

NetworkStream stream = client.GetStream();

String message = "S,KEY\r\n";
Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);
stream.Write(data, 0, data.Length);

message = "wMSFT\r\n";
message += "wIBM\r\n";
data = System.Text.Encoding.ASCII.GetBytes(message);
stream.Write(data, 0, data.Length);

data = new Byte[5120];

for(int x=0; x<20; x++)
{
String responseData = String.Empty;
Int32 bytes = stream.Read(data, 0, data.Length);
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
Console.Write(responseData);
}

client.Close();
}

catch (ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException: {0}", e);
}

catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
}

RemoveClientApp(IntPtr.Zero);

Console.Write("\nPress Enter to continue...");
Console.Read();

GC.KeepAlive(IQFeed_CallBack);
}
}

//////////////////////////////////////////////////////////////////////////////////////
// end - console_stream.cs
//////////////////////////////////////////////////////////////////////////////////////


Please post or email any questions, comments or improvements.

Regards,
Dennis Sanders
dennissanders@intsvcs.com

Dennis
-Interested User-
Posts: 19
Joined: Oct 8, 2004


Posted: Oct 26, 2004 06:56 PM          Msg. 2 of 5
To build and run console_stream.cs from Visual Studio.NET:

Create a new Visual C# "Empty Project" in Visual Studio.NET
- In VS.NET go to File->New->Project->Visual C# Projects->Empty Project.
- Type in "console_stream" as the project name and select a location for the project folder.
- Accept the remaining defaults and click OK.
Add a new Code File to the Project
- In the Solution explorer (use View if you don't see it), right click "console_stream" (the project name).
- Select Add->Add New Item->Code File.
- Name the Code File console_stream.cs, click Open.
Copy and paste the posted code to the editing space for console_stream.cs.
- (...All indents will be magically restored, thank God!...)
Add System.dll to the References in your project.
- Right click References (below the project name in the Solution Explorer).
- Select Add Reference, then scroll down the selections under the .NET tab.
- Double-click System.dll, it should appear in Selected Components, then click OK.
(System.dll will be added as System under References.
Now Build the Solution
- Change Active Configuration if desired.(the default is Debug, but Release works as well)
- Then select Build->Build Solution

The project should build with 0 failed, 0 skipped (and no warnings).
- Any build errors can most likely be resolved by adjusting your path or other environment variables.

You will need a path to IQ32.dll (C:\Program Files\DTN\IQFeed on my computer) in order to successfully run the program.

To run console_stream.exe from Visual Studio press F5. Or, to run the .exe from Windows; exit Visual Studio and hunt down the console_stream.exe in you newly created project folder. When you find it...double click it.

If you have any questions or problems, please post or email.

Regards,
Dennis Sanders
dennissanders@intsvcs.com

Dennis
-Interested User-
Posts: 19
Joined: Oct 8, 2004


Posted: Oct 26, 2004 10:23 PM          Msg. 3 of 5
To build and run console_stream.cs from Windows:

Create and name a new folder in a location of your choice.
Open the new folder in a window on your desktop.
Create a new C# Code File in the new folder using the posted code example.
- Open notepad (or a text editor of your choice), copy and paste the posted code to it.
- Using the brackets in the code as a guide, manually replace the indentions that were scrubbed in the forum post.
- Save the contents of notepad to your folder as console_stream.cs
Create a new compile.bat file using notepad.
- Select File->New from the notepad menu.
- Type "csc console_stream.cs" (do not include the quote marks).
- Save (File->Save As) the contents of notepad to your folder as build.bat

You should have two files in your folder; console_stream.cs and build.bat

Create the executable file console_stream.exe
- Double click build.bat

A new file, console_stream.exe should appear in the folder (if not, check the possible reasons below).
Double click console_stream.exe to run the new example.

Possible reasons console_stream.exe was not created or will not run.
- .NET Framework and/or .NET SDK are not installed on your computer (these are free from Microsoft).
- Your path does not include the directory (folder) that contains the .NET build command csc.exe
- Your path does not include the IQFeed directory (C:\Program Files\DTN\IQFeed on my computer).

Executing the build and/or run operations at the Windows Command Prompt will help you diagnose most problems.
Feel free to post your ideas/questions/problems to this thread, or send an email.

Regards,
Dennis Sanders
dennissanders@intsvcs.com

frankzhou
-Interested User-
Posts: 15
Joined: Oct 6, 2004


Posted: Oct 27, 2004 03:36 PM          Msg. 4 of 5
good,do you have a example for history data?
thanks

Dennis
-Interested User-
Posts: 19
Joined: Oct 8, 2004


Posted: Oct 27, 2004 07:10 PM          Msg. 5 of 5
frankzhou,

I am attempting to create a .NET C# version of the VC++ History Example. However, with my current work load, it may be a bit delayed. When I have something useful (in whole or in part), I will post it to the developer forum.

Regards,
Dennis
 

 

Time: Sun May 19, 2024 10:11 AM CFBB v1.2.0 10 ms.
© AderSoftware 2002-2003