bitcoin – Grey Panthers Savannah https://grey-panther.net Just another WordPress site Sun, 08 May 2022 11:39:11 +0000 en-US hourly 1 https://wordpress.org/?v=7.0.1 206299117 Connecting to the MtGox market data feed using Perl https://grey-panther.net/2013/05/connecting-to-the-mtgox-market-data-feed-using-perl.html https://grey-panther.net/2013/05/connecting-to-the-mtgox-market-data-feed-using-perl.html#respond Wed, 29 May 2013 14:52:00 +0000 For a recent project I needed some realistic market data for an electronic exchange. Seeing how MtGox provides free and open access to theirs (thank you!) I chose them. However none of the examples floating around the internet seemed to work, so I whipped one up using Net::Async::WebSocket::Client. Enjoy:

use IO::Async::Loop;
use Net::Async::WebSocket::Client;

my $client = Net::Async::WebSocket::Client->new(
        on_frame => sub {
                my ( $self, $frame ) = @_;
                print "n", $frame, "n";
        },
);

my $loop = IO::Async::Loop->new;
$loop->add( $client );

$client->connect(
        host => 'websocket.mtgox.com',
        service => 80,
        url => "ws://websocket.mtgox.com:80/mtgox",
        on_connected => sub {},
        on_connect_error => sub { die "Cannot connect - $_[-1]" },
        on_resolve_error => sub { die "Cannot resolve - $_[-1]" },
);

$loop->loop_forever;

(it is basically the sample program for the module, with the MtGox market data URL hardcoded).

]]>
https://grey-panther.net/2013/05/connecting-to-the-mtgox-market-data-feed-using-perl.html/feed 0 16