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
"I just wanted to let u know that your data feed/service is by far the best!!! Your unfiltered tick data is excellent for reading order flow and none of your competitors delivers this quality of data!" - Comment from Peter via Email
"If someone needs the best quality data and backfill beyond what their broker provides at a rate that is the best in the industry, I highly recommend IQFeed." - Comment from Josh via Public Forum
"I just wanted to say how happy I am with your service. I was able to download the API docs last week and I was able to replicate Interactive Brokers historical bar queries and realtime bar queries over the weekend. That was about one of the fastest integrations that I've ever done and it works perfectly!!!!" - Comment from Jason via Email
"I would just like to say that IQFeed version 4 is running very well and I am very happy with its performance. I would also like to extend a big thanks for the fast and efficient help that I always receive. My questions and concerns are always addressed promptly. Way to go!" - Comment from Josh in CO.
"I like you guys better than *******...much more stable and a whole lot fewer issues." - Comment from Philip
"Everything is working amazing now. I'm already impressed with the true-tick feed of IQFeed and it's ability to support my 480 symbol layout." - Comment from Tyler via Email
"I've been using IQFeed 4 in a multi-threaded situation for the last week or two on 2600 symbols or so with 100 simultaneous daily charts, and I have had 100% responsiveness." - Comment from Scott
"With HUGE volume on AAPL and RIMM for 2 days, everyone in a trading room was whining about freezes, crashes and lag with *******, RealTick, TS and Cyber. InvestorRT with IQFeed was rock solid. I mean SOLID!" - Comment from Public IRC Chat
"DTN feed was the only feed that consistently matched Bloomberg feed for BID/ASK data verification work these past years......DTN feed is a must for my supply & demand based trading using Cumulative Delta" - Comment from Public Forum Post
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 »Erlang - Getting started with sockets - newbie quick hack
Author Topic: Erlang - Getting started with sockets - newbie quick hack (2 messages, Page 1 of 1)

klarsen
-Interested User-
Posts: 3
Joined: Jun 15, 2006


Posted: Jun 23, 2010 12:58 AM          Msg. 1 of 2
Hi Guys,

i'm trying to learn erlang :-) since it seems like Erlang loves small messages like quotes - and loves IP/Sockets. But i'm a TOTAL newbie into erlang - and took me a while to get feed up and get data out.

So I thought I would share - and would love if anyone else in the same boat would share too.

So here is a short code that 1. starts IQFeed, 2. Connects to Socket, 3 Retrieves a packet or two from port 5009 and outputs them to the console.

:code!!
%%%file_comment
-module(iqfeed_start).


-export([start/0,client/1]).

start() ->
open_port({spawn,"IQConnect.exe -product IQFEED_DEMO -version 1.0.0.0"}, []),
timer:sleep(1000). %open IQfeed and then wait for login etc


client(PortNo) ->
start(), %calls the start of IQConnect - remove this
{ok,Sock} = gen_tcp:connect("localhost", PortNo,[binary, {active,false}]), %open a socket connection
io:format("Connected to sock:~p ~n",[Sock]),
%%%gen_tcp:send(Sock,Message),
{ok,A}=gen_tcp:recv(Sock, 0), %receive what is waiting for us like "S,KEY etc"
io:format("~p ~n", [A]), % print it to console
gen_tcp:send(Sock,"wMSFT\r\n"), %ask for a Microsoft quote
io:format("command sent~n"),
Bx = gen_tcp:recv(Sock,0), %receive packet
io:format("~p ~n", [Bx]),
io:format("waiting for next server packet~n"),
C = gen_tcp:recv(Sock,0), %get next packet - if market not active this will show the 1 minute timer
io:format("~p ~n", [C]), % print it.
gen_tcp:close(Sock). %actually closes IQFeed - make it a comment for tests!


you start it by compiling the iqfeed_start.erl "c(iqfeed_start) from Erlang console. Then you can call it by writing "iqfeed_start:client(5009)." [enter] - where 5009 is the port number.

My todo list: Find a way to detect if IQFeed is already running (like fire a socket connect request)
Edited by klarsen on Jun 23, 2010 at 01:00 AM

JoshSN
-Interested User-
Posts: 29
Joined: Apr 8, 2010


Posted: Jun 25, 2010 07:42 AM          Msg. 2 of 2
Here's how it can be done in Perl.

#!/usr/bin/perl

use POE qw(Component::Client::TCPMulti);

system("/path/to/IQFeed/iqconnect.exe -product DEMO -version 1.1 &");
sleep 15;

my ($level1,$feed);

POE::Component::Client::TCPMulti->new(
InputEvent => sub {
print "From server: $_[ARG0]\n";
},
SuccessEvent => sub {
if ($_[ARG2] == 5009) {
$level1 = $_[ARG4];
$_[KERNEL]->yield(send => $level1, "wGOOG\r\n");
} elsif ($_[ARG2] == 9100) {
$feed = $_[ARG4];
$_[KERNEL]->yield(send => $feed, "HTD,MO1018U19,3\r\n");
}
},
inline_states => {
_start => sub {
$_[KERNEL]->yield(connect => '127.0.0.1', $_) for (5009, 9100);
},
}
);
 

 

Time: Fri May 3, 2024 4:10 PM CFBB v1.2.0 11 ms.
© AderSoftware 2002-2003