#!/usr/bin/perl use warnings; use strict; use IO::Async::Loop; use Net::Async::WebSocket::Client; use JSON::XS qw( decode_json encode_json ); use Data::Dumper; my $client = Net::Async::WebSocket::Client->new( on_text_frame => sub { my ( $self, $json ) = @_; my $data = decode_json $json; # this is how we detect a heartbeat #return if $data->{type} eq 'heartbeat'; print Dumper $data; }, ); my $loop = IO::Async::Loop->new; $loop->add( $client ); $client->connect( url => "wss://ws-feed.gdax.com", )->then( sub { $client->send_text_frame( encode_json { type => "subscribe", product_ids => [ "ETH-USD", ], channels => [ 'heartbeat', ] } ); } )->get; $loop->run;