Binance::API -- Perl implementation for Binance API
This module provides a Perl implementation for Binance API
Binance API documentation: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md.
https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md
ENUM definitions: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#enum-definitions
use Binance::API; my $api = Binance::API->new( apiKey => 'my_api_key', secretKey => 'my_secret_key', ); my $ticker = $api->ticker( symbol => 'ETHBTC' );
my $api = Binance::API->new( apiKey => 'my_api_key', secretKey => 'my_secret_key', );
Instantiates a new Binance::API object
Binance::API
PARAMETERS
[OPTIONAL] Your Binance API key.
[OPTIONAL] Your Binance API secret key.
[OPTIONAL] Number of milliseconds the request is valid for. Applies only in signed requests.
[OPTIONAL] See "new" in Binance::API::Logger
RETURNS
A Binance::API object.
$api->ping();
Test connectivity to the Rest API
RETURNS 1 if successful, otherwise 0
$api->time();
Test connectivity to the Rest API and get the current server time.
RETURNS Server (epoch) time in milliseconds
$api->exchange_info();
Current exchange trading rules and symbol information.
RETURNS A HASHref
{ "timezone": "UTC", "serverTime": 1508631584636, "rateLimits": [{ "rateLimitType": "REQUESTS", "interval": "MINUTE", "limit": 1200 }, { "rateLimitType": "ORDERS", "interval": "SECOND", "limit": 10 }, { "rateLimitType": "ORDERS", "interval": "DAY", "limit": 100000 } ], "exchangeFilters": [], "symbols": [{ "symbol": "ETHBTC", "status": "TRADING", "baseAsset": "ETH", "baseAssetPrecision": 8, "quoteAsset": "BTC", "quotePrecision": 8, "orderTypes": ["LIMIT", "MARKET"], "icebergAllowed": false, "filters": [{ "filterType": "PRICE_FILTER", "minPrice": "0.00000100", "maxPrice": "100000.00000000", "tickSize": "0.00000100" }, { "filterType": "LOT_SIZE", "minQty": "0.00100000", "maxQty": "100000.00000000", "stepSize": "0.00100000" }, { "filterType": "MIN_NOTIONAL", "minNotional": "0.00100000" }] }] }
$api->depth( symbol => 'ETHBTC' );
[REQUIRED] Symbol, for example ETHBTC.
ETHBTC
[OPTIONAL] Default 100; max 100.
{ "lastUpdateId": 1027024, "bids": [ [ "4.00000000", // PRICE "431.00000000", // QTY [] // Can be ignored ] ], "asks": [ [ "4.00000200", "12.00000000", [] ] ] }
$api->trades();
Get recent trades (up to last 500).
[OPTIONAL] Default 500; max 500.
RETURNS An ARRAYref of HASHrefs
[ { "id": 28457, "price": "4.00000100", "qty": "12.00000000", "time": 1499865549590, "isBuyerMaker": true, "isBestMatch": true } ]
$api->historical_trades();
Get older trades.
[OPTIONAL] TradeId to fetch from. Default gets most recent trades.
$api->aggregate_trades( symbol => 'ETHBTC' );
Gets compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.
[OPTIONAL] ID to get aggregate trades from INCLUSIVE.
[OPTIONAL] timestamp in ms to get aggregate trades from INCLUSIVE.
[OPTIONAL] timestamp in ms to get aggregate trades until INCLUSIVE.
[ { "a": 26129, // Aggregate tradeId "p": "0.01633102", // Price "q": "4.70443515", // Quantity "f": 27781, // First tradeId "l": 27781, // Last tradeId "T": 1498793709153, // Timestamp "m": true, // Was the buyer the maker? "M": true // Was the trade the best price match? } ]
$api->klines( symbol => 'ETHBTC', interval => '1M' );
Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
[REQUIRED] ENUM (kline intervals), for example 1m, 1h, 1d or 1M.
[OPTIONAL] timestamp in ms
RETURNS An array of ARRAYrefs
[ [ 1499040000000, // Open time "0.01634790", // Open "0.80000000", // High "0.01575800", // Low "0.01577100", // Close "148976.11427815", // Volume 1499644799999, // Close time "2434.19055334", // Quote asset volume 308, // Number of trades "1756.87402397", // Taker buy base asset volume "28.46694368", // Taker buy quote asset volume "17928899.62484339" // Can be ignored ] ]
24 hour price change statistics.
{ "priceChange": "-94.99999800", "priceChangePercent": "-95.960", "weightedAvgPrice": "0.29628482", "prevClosePrice": "0.10002000", "lastPrice": "4.00000200", "bidPrice": "4.00000000", "askPrice": "4.00000200", "openPrice": "99.00000000", "highPrice": "100.00000000", "lowPrice": "0.10000000", "volume": "8913.30000000", "openTime": 1499783499040, "closeTime": 1499869899040, "fristId": 28385, // First tradeId "lastId": 28460, // Last tradeId "count": 76 // Trade count }
$api->ticker_price();
Latest price for a symbol or symbols.
[OPTIONAL] Symbol, for example ETHBTC. If not given, returns prices of all symbols.
{ "symbol": "LTCBTC", "price": "4.00000200" } OR an ARRAY of HASHrefs [ { "symbol": "LTCBTC", "price": "4.00000200" }, { "symbol": "ETHBTC", "price": "0.07946600" } ]
$api->all_book_tickers();
Best price/qty on the order book for all symbols.
RETURNS An array of HASHrefs
[ { "symbol": "LTCBTC", "bidPrice": "4.00000000", "bidQty": "431.00000000", "askPrice": "4.00000200", "askQty": "9.00000000" }, { "symbol": "ETHBTC", "bidPrice": "0.07946700", "bidQty": "9.00000000", "askPrice": "100000.00000000", "askQty": "1000.00000000" } ]
$api->book_ticker();
Best price/qty on the order book for a symbol or symbols.
[OPTIONAL] Symbol, for example ETHBTC.
{ "symbol": "LTCBTC", "bidPrice": "4.00000000", "bidQty": "431.00000000", "askPrice": "4.00000200", "askQty": "9.00000000" }
$api->order( symbol => 'ETHBTC', side => 'BUY', type => 'LIMIT', timeInForce => 'GTC', quantity => 1 price => 0.1 );
Send in a new order.
[REQUIRED] BUY or SELL.
[REQUIRED] LIMIT or MARKET.
[REQUIRED] GTC or IOC.
[REQUIRED] Quantity (of symbols) in order.
[REQUIRED] Price (of symbol) in order.
[OPTIONAL] A unique id for the order. Automatically generated if not sent.
[OPTIONAL] Used with stop orders.
[OPTIONAL] Used with iceberg orders.
{ "symbol":"LTCBTC", "orderId": 1, "clientOrderId": "myOrder1" // Will be newClientOrderId "transactTime": 1499827319559 }
$api->order_test();
Test new order creation and signature/recvWindow long. Creates and validates a new order but does not send it into the matching engine.
RETURNS An empty HASHref
{}
$api->cancel_order();
Cancel an active order.
[OPTIONAL]
[OPTIONAL] Used to uniquely identify this cancel. Automatically generated by default.
{ "symbol": "LTCBTC", "origClientOrderId": "myOrder1", "orderId": 1, "clientOrderId": "cancelMyOrder1" }
$api->open_orders();
Get all open orders on a symbol. Careful when accessing this with no symbol.
OPTIONAL] Symbol, for example ETHBTC.
[ { "symbol": "LTCBTC", "orderId": 1, "clientOrderId": "myOrder1", "price": "0.1", "origQty": "1.0", "executedQty": "0.0", "status": "NEW", "timeInForce": "GTC", "type": "LIMIT", "side": "BUY", "stopPrice": "0.0", "icebergQty": "0.0", "time": 1499827319559, "isWorking": trueO } ]
$api->all_orders();
Get all account orders; active, canceled, or filled.
[ { "symbol": "LTCBTC", "orderId": 1, "clientOrderId": "myOrder1", "price": "0.1", "origQty": "1.0", "executedQty": "0.0", "status": "NEW", "timeInForce": "GTC", "type": "LIMIT", "side": "BUY", "stopPrice": "0.0", "icebergQty": "0.0", "time": 1499827319559, "isWorking": true } ]
$api->account();
Get current account information.
{ "makerCommission": 15, "takerCommission": 15, "buyerCommission": 0, "sellerCommission": 0, "canTrade": true, "canWithdraw": true, "canDeposit": true, "updateTime": 123456789, "balances": [ { "asset": "BTC", "free": "4723846.89208129", "locked": "0.00000000" }, { "asset": "LTC", "free": "4763368.68006011", "locked": "0.00000000" } ] }
$api->my_trades();
Get trades for a specific account and symbol.
[ { "id": 28457, "orderId": 100234, "price": "4.00000100", "qty": "12.00000000", "commission": "10.10000000", "commissionAsset": "BNB", "time": 1499865549590, "isBuyer": true, "isMaker": false, "isBestMatch": true } ]
$api->start_user_data_stream();
Start a new user data stream. The stream will close after 60 minutes unless a keepalive is sent.
{ "listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1" }
$api->keep_alive_user_data_stream();
Keepalive a user data stream to prevent a time out. User data streams will close after 60 minutes. It's recommended to send a ping about every 30 minutes.
[REQUIRED]
$api->delete_user_data_stream();
Close out a user data stream.
PARAMETERS =over
$api->log->warn("This is a warning");
An instance of Binance::API::Logger.
$api->ua->get('/binance/endpoint');
An instance of Binance::API::Request.
2 POD Errors
The following errors were encountered while parsing the POD:
Unknown directive: =limit
'=item' outside of any '=over'
To install Binance::API, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Binance::API
CPAN shell
perl -MCPAN -e shell install Binance::API
For more information on module installation, please visit the detailed CPAN module installation guide.