NAME
FIX::Lite - Simple FIX protocol module
VERSION
Version 0.01
SYNOPSIS
use FIX::Lite;
my $fix = FIX::Lite->new(
Host => 'somefixserver.com',
Port => 5201,
Debug => 0,
Timeout => 60
) or die "Cannot connect to server: $!";
# Then we usually need to login
$fix->logon(
SenderCompID => 'somevalue1',
TargetCompID => 'somevalue2',
TargetSubID => 'somevalue3',
Username => 'somevalue4',
Password => 'somevalue5',
Debug => 0
);
# To check the login results we can use method loggedIn()
die "Cannot logon: $!" unless $fix->loggedIn()
# After logon we can make some market request
$fix->request(
MsgType => 'MarketDataRequest',
SubscriptionRequestType => 'SNAPSHOT_PLUS_UPDATES',
MarketDepth => 1,
MDUpdateType => 'INCREMENTAL_REFRESH',
NoRelatedSym => {
Instrument => {
Symbol => [
'EUR/USD',
'GBP/CHF'
]
},
},
NoMDEntryTypes => {
MDEntryType => [
'BID',
'OFFER'
]
},
Debug => $debug
) or die "Cannot send request: $!";
# We the use lastRequest() method to get the parsed answer
if ( $fix->lastRequest('MsgType') eq "REJECT" ) {
print "Request was rejected\n";
print "Reason: ".$fix->lastRequest('SessionRejectReason')."\n";
print "RefTag: ".FIX::Lite->getTagById($fix->lastRequest('RefTagID'))."\n";
}
# And yup, we can use FIX::Lite->getTagById() method to resolve tag codes into
# human-readable values
# After sending some subscriptions we can relax and wait for the quotes
$fix->listen( \&handler,
HeartBtInt => 30,
Debug => 0
);
# Every incoming message (except heartbeats) will call some handler function,
# we need to just pass its reference as an argument. As for the hearbeats then
# module will send them every HeartBtInt seconds (default is 30)
# To explicitly close the connection we can use quit() method
$fix->quit();
# And a simple example of the handler-function:
sub handler {
my $resp = shift;
print "Received message ".$resp->{MsgType}."\n";
if ( $resp->{MsgType} eq 'W' ) {
print "Received Price ".$resp->{MDEntryPx}." for symbol ".$resp->{Symbol}."\n";
}
return 1;
}
INSTANCE METHODS
new
Open a socket to the FIX server
logon
Send the logon (35=A) message and wait for the response
heartbeat
Send the heartbeat (35=0) message and get back
request
Send the FIX request of any type and wait for the response
listen
Wait for the incoming messages. This method will return after the socket is closed. Heartbeats are sent automatically.
loggedIn
Returns true if FIX server has answered with Logon message
lastRequest
Returns hash with parsed response for the last request sent.
getTagById
Resolve tag name by its code
getMsgByType
Resolve message name by its type code
quit
Explicitly close the socket to the FIX server.
AUTHOR
Vitaly Agapov, <agapov.vitaly@gmail.com>
LICENSE AND COPYRIGHT
Copyright 2015 "Vitaly Agapov".
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.