Skip to content

Commit

Permalink
Merge pull request #16 from sysdef/master
Browse files Browse the repository at this point in the history
Upgrade to API Version 3
  • Loading branch information
taskula authored Jun 12, 2021
2 parents f2ab2be + 9b01442 commit 9f50e17
Showing 1 changed file with 61 additions and 57 deletions.
118 changes: 61 additions & 57 deletions lib/Binance/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ B<RETURNS>
=cut

sub ping {
return keys %{$_[0]->ua->get('/api/v1/ping')} == 0 ? 1 : 0;
return keys %{$_[0]->ua->get('/api/v3/ping')} == 0 ? 1 : 0;
}

=head2 time
Expand All @@ -170,7 +170,7 @@ B<RETURNS>
sub time {
my $self = shift;

my $time = $self->ua->get('/api/v1/time');
my $time = $self->ua->get('/api/v3/time');
return exists $time->{serverTime} ? $time->{serverTime} : 0;
}

Expand Down Expand Up @@ -240,7 +240,7 @@ B<RETURNS>
=cut

sub exchange_info {
return $_[0]->ua->get('/api/v1/ticker/exchangeInfo');
return $_[0]->ua->get('/api/v3/exchangeInfo');
}

=head2 depth
Expand All @@ -257,7 +257,7 @@ B<PARAMETERS>
=item limit
[OPTIONAL] Default 100; max 100.
[OPTIONAL] Default 100; max 5000. Valid limits: 5, 10, 20, 50, 100, 500, 1000, 5000.
=back
Expand Down Expand Up @@ -300,14 +300,14 @@ sub depth {
limit => $params{'limit'},
};

return $self->ua->get('/api/v1/depth', { query => $query } );
return $self->ua->get('/api/v3/depth', { query => $query } );
}

=head2 trades
$api->trades();
Get recent trades (up to last 500).
Get recent trades (up to last 1000).
B<PARAMETERS>
Expand All @@ -319,7 +319,7 @@ B<PARAMETERS>
=item limit
[OPTIONAL] Default 500; max 500.
[OPTIONAL] Default 500; max 1000.
=back
Expand Down Expand Up @@ -355,7 +355,7 @@ sub trades {
limit => $params{'limit'},
};

return $self->ua->get('/api/v1/trades', { query => $query } );
return $self->ua->get('/api/v3/trades', { query => $query } );
}

=head2 historical_trades
Expand All @@ -374,7 +374,7 @@ B<PARAMETERS>
=item limit
[OPTIONAL] Default 500; max 500.
[OPTIONAL] Default 500; max 1000.
=item fromId
Expand Down Expand Up @@ -415,7 +415,7 @@ sub historical_trades {
fromId => $params{'fromId'},
};

return $self->ua->get('/api/v1/historicalTrades', { query => $query } );
return $self->ua->get('/api/v3/historicalTrades', { query => $query } );
}

=head2 aggregate_trades
Expand All @@ -437,7 +437,6 @@ B<PARAMETERS>
[OPTIONAL] ID to get aggregate trades from INCLUSIVE.
=item startTime
[OPTIONAL] timestamp in ms to get aggregate trades from INCLUSIVE.
Expand All @@ -448,7 +447,7 @@ B<PARAMETERS>
=item limit
[OPTIONAL] Default 500; max 500.
[OPTIONAL] Default 500; max 1000.
=back
Expand Down Expand Up @@ -489,7 +488,7 @@ sub aggregate_trades {
limit => $params{'limit'},
};

return $self->ua->get('/api/v1/aggTrades', { query => $query } );
return $self->ua->get('/api/v3/aggTrades', { query => $query } );
}

=head2 klines
Expand All @@ -513,7 +512,7 @@ B<PARAMETERS>
=item limit
[OPTIONAL] Default 500; max 500.
[OPTIONAL] Default 500; max 1000.
=item startTime
Expand Down Expand Up @@ -574,7 +573,7 @@ sub klines {
limit => $params{'limit'},
};

return $self->ua->get('/api/v1/klines', { query => $query } );
return $self->ua->get('/api/v3/klines', { query => $query } );
}

=head2 ticker
Expand All @@ -590,6 +589,7 @@ B<PARAMETERS>
=item symbol
[OPTIONAL] Symbol, for example C<ETHBTC>.
Warning: Careful when accessing this with no symbol.
=back
Expand Down Expand Up @@ -624,7 +624,7 @@ sub ticker {
symbol => $params{'symbol'},
};

return $self->ua->get('/api/v1/ticker/24hr', { query => $query } );
return $self->ua->get('/api/v3/ticker/24hr', { query => $query } );
}

=head2 ticker_price
Expand Down Expand Up @@ -677,22 +677,35 @@ sub ticker_price {
return $self->ua->get('/api/v3/ticker/price', { query => $query } );
}

=head2 all_book_tickers
=head2 book_ticker
$api->all_book_tickers();
$api->book_ticker();
Best price/qty on the order book for all symbols.
B<PARAMETERS>
=over
=item Takes no parameters.
=item symbol
[OPTIONAL] Symbol, for example C<ETHBTC>. If not given, returns best price/qty of all
symbols.
=back
B<RETURNS>
An array of HASHrefs
A HASHref
{
"symbol": "LTCBTC",
"bidPrice": "4.00000000",
"bidQty": "431.00000000",
"askPrice": "4.00000200",
"askQty": "9.00000000"
}
OR an ARRAY of HASHrefs
[
{
Expand All @@ -713,47 +726,28 @@ B<RETURNS>
=cut

sub all_book_tickers {
return $_[0]->ua->get('/api/v1/ticker/allBookTickers');
}

=head2 book_ticker
$api->book_ticker();
Best price/qty on the order book for a symbol or symbols.
B<PARAMETERS>
=over
sub book_ticker {
my ($self, %params) = @_;

=item symbol
my $query = {
symbol => $params{'symbol'},
};

[OPTIONAL] Symbol, for example C<ETHBTC>.
return $_[0]->ua->get('/api/v3/ticker/bookTicker', { query => $query } );
}

=back
=head2 all_book_tickers
B<RETURNS>
A HASHref
$api->all_book_tickers();
{
"symbol": "LTCBTC",
"bidPrice": "4.00000000",
"bidQty": "431.00000000",
"askPrice": "4.00000200",
"askQty": "9.00000000"
}
DEPRECATED: use book_ticker instead.
=cut

sub book_ticker {
my ($self, %params) = @_;

my $query = {
symbol => $params{'symbol'},
};
sub all_book_tickers {
my $self = shift;

return $self->ua->get('/api/v1/ticker/bookTicker', { query => $query } );
return $self->book_ticker(@_);
}

=head2 order
Expand Down Expand Up @@ -1096,13 +1090,21 @@ B<PARAMETERS>
[OPTIONAL]
=item startTime
[OPTIONAL] Start time
=item endTime
[OPTIONAL] End time
=item limit
[OPTIONAL] Default 500; max 500.
[OPTIONAL] Default 500; max 1000.
=item recvWindow
[OPTIONAL]
[OPTIONAL] The value cannot be greater than 60000.
=back
Expand Down Expand Up @@ -1142,6 +1144,8 @@ sub all_orders {
my $query = {
symbol => $params{'symbol'},
orderId => $params{'orderId'},
startTime => $params{'startTime'},
endTime => $params{'endTime'},
limit => $params{'limit'},
recvWindow => $params{'recvWindow'},
};
Expand Down Expand Up @@ -1297,7 +1301,7 @@ B<RETURNS>
=cut

sub start_user_data_stream {
return $_[0]->ua->post('/api/v1/ticker/userDataStream');
return $_[0]->ua->post('/api/v3/userDataStream');
}

=head2 keep_alive_user_data_stream
Expand Down Expand Up @@ -1336,7 +1340,7 @@ sub keep_alive_user_data_stream {
my $query = {
listenKey => $params{'listenKey'},
};
return $self->ua->put('/api/v1/userDataStream', { query => $query } );
return $self->ua->put('/api/v3/userDataStream', { query => $query } );
}

=head2 delete_user_data_stream
Expand Down Expand Up @@ -1374,7 +1378,7 @@ sub delete_user_data_stream {
my $query = {
listenKey => $params{'listenKey'},
};
return $self->ua->delete('/api/v1/userDataStream', { query => $query } );
return $self->ua->delete('/api/v3/userDataStream', { query => $query } );
}

=head2 log
Expand Down

0 comments on commit 9f50e17

Please sign in to comment.