1.0.4 • Published 10 months ago

node-binance-client-service v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

NodeBinanceClientService

This module is an extended extension of the popular binance-api-node library. It provides a set of additional tools and functions that simplify interaction with the Binance exchange and allow for deeper analysis of market data. The module is based on proven and reliable methods, ensuring the stability and accuracy of the results obtained.

Installation

npm i node-binance-client-service

Getting Started

To get started with this module, import it and create a client instance. API keys are optional unless you need to make authenticated requests. You can generate an API key here.

const binanceClient = new NodeBinanceClientService({
    binance_api_key: "YOUR_API_KEY",
    binance_secret_key: "YOUR_SECRET_KEY"
})

Calc functions

calcPercentChange

This JavaScript function, calcPercentChange, calculates the percentage change between an initial value (opening price) and a final value (closing price). It is commonly used in financial applications to determine the price change of an asset over a specific period.

ParameterTypeDescription
openPricenumberThe starting value, such as the opening price of a stock.
closePricenumberThe ending value, such as the closing price of a stock.
includeMinusbooleanA flag that determines whether to include a negative sign in the result if the percentage change is negative.

Usage

const percentChange = binanceClient.calcPercentChange(openPrice, closePrice, isIncludeMinus)

Return

TypeDescription
numberThe percentage change between openPrice and closePrice. The sign of the result depends on the value of the includeMinus flag and the direction of the change.

calcAllTickerDensitiesWithInputData

This JavaScript function, calcAllTickerDensitiesWithInputData, calculates the densities of bids and asks from the order book data. It filters out the bids and asks that meet a certain density threshold based on a coefficient.

ParameterTypeDescription
inputDataobjectThe input data containing the order book information.
coefficientnumberA coefficient used to determine the density threshold for filtering bids and asks.

Usage

const result = binanceClient.calcAllTickerDensitiesWithInputData(inputData, coefficient);

Return

TypeDescription
AllDensitiesAn object containing the average densities and filtered densities for both asks and bids.

calcTrend

This TypeScript function, calcTrend, calculates the trend and percentage change based on the input candle chart data. It determines whether the trend is "Up", "Down", or "Not changed" based on the opening and closing prices.

Parameters

ParameterTypeDescription
inputDataCandleChartResult[]An array of objects containing the candle chart data.

Usage

const result = calcTrend(inputData);

Result

PropertyTypeDescription
trendstringThe trend direction: "Up", "Down", or "Not changed"
percentChangenumberThe percentage change from the opening to the closing price

calcCorrelation

This TypeScript function, calcCorrelation, calculates the correlation coefficient between the closing prices of two sets of candle chart data. The correlation coefficient measures the strength and direction of the linear relationship between the two datasets.

Parameters

ParameterTypeDescription
firstTickerCandlesDataCandleDataResultAn object containing the first set of candle chart data.
secondTickerCandlesDataCandleDataResultAn object containing the second set of candle chart data.

Usage

const correlation = calcCorrelation(firstTickerCandlesData, secondTickerCandlesData);

Result

TypeDescription
numberThe correlation coefficient between the closing prices of the two ticker candle data sets. This value ranges from -1 to 1, indicating the strength and direction of the linear relationship.

calcPumpsDumps

This TypeScript function, calcPumpsDumps, identifies significant price movements (pumps and dumps) in a set of candle chart data based on a specified coefficient. It calculates the average percentage change in price and then determines which candles exceed this average change by the given coefficient.

Parameters

ParameterTypeDescription
candleDataCandleDataResultAn object containing the candle chart data, including symbol, interval, and candles data.
coefficientnumberA multiplier used to determine the threshold for significant price changes.

Usage

const result = calcPumpsDumps(candleData, coefficient);

Result

TypeDescription
PumpDumpResultAn object containing the symbol, symbol type, interval, limit, start time, end time, and arrays of candles identified as pumps and dumps.

(Async) GET functions

getAllFuturesTickers

This asynchronous TypeScript function, getAllFuturesTickers, retrieves all futures tickers from the Binance API and filters them based on their status.

Parameters

ParameterTypeDescription
symbolStatusSymbolStatusThe status of the symbols to filter by (e.g., TRADING, BREAK, etc.).

Usage

const tickers = await getAllFuturesTickers('TRADING');

Result

TypeDescription
ArrayAn array of symbols that match the specified status.

getAllSpotTickers

This asynchronous TypeScript function, getAllSpotTickers, retrieves all spot tickers from the Binance API and filters them based on their status.

Parameters

ParameterTypeDescription
symbolStatusSymbolStatusThe status of the symbols to filter by (e.g., TRADING, BREAK, etc.).

Usage

const tickers = await getAllSpotTickers('TRADING');

Result

TypeDescription
ArrayAn array of symbols that match the specified status.

getSpotTickerCandles

This asynchronous TypeScript function, getSpotTickerCandles, retrieves candle chart data for a specified spot ticker from the Binance API and formats it into a structured result.

Parameters

ParameterTypeDescription
optionsCandlesOptionsAn object containing options for retrieving the candle data, such as symbol, interval, limit, start time, and end time.

Usage

const options = {
    symbol: "BTCUSDT",
    interval: "1h",
    limit: 100,
    startTime: 1622505600000,
    endTime: 1622592000000
};
const result = await getSpotTickerCandles(options);

Result

TypeDescription
CandleDataResultAn object containing the symbol, symbol type, interval, limit, start time, end time, and an array of formatted candle data.

getFuturesTickerCandles

This asynchronous TypeScript function, getFuturesTickerCandles, retrieves candle chart data for a specified futures ticker from the Binance API and formats it into a structured result.

Parameters

ParameterTypeDescription
optionsCandlesOptionsAn object containing options for retrieving the candle data, such as symbol, interval, limit, start time, and end time.

Usage

const options = {
    symbol: "BTCUSDT",
    interval: "1h",
    limit: 100,
    startTime: 1622505600000,
    endTime: 1622592000000
};
const result = await getFuturesTickerCandles(options);

Result

TypeDescription
CandleDataResultAn object containing the symbol, symbol type, interval, limit, start time, end time, and an array of formatted candle data.

getSpotOrderBook

This asynchronous TypeScript function, getSpotOrderBook, retrieves the current price and order book for a specified spot ticker from the Binance API and formats it into a structured result.

Parameters

ParameterTypeDescription
symbolstringThe symbol for which to retrieve the order book (e.g., BTCUSDT).
orderBookLimitnumberThe limit on the number of orders to retrieve for the order book.

Usage

const orderBook = await getSpotOrderBook('BTCUSDT', 100);

Result

TypeDescription
ResultOrderBookObjectAn object containing the symbol, order book type, current price, and the order book data (asks and bids).

getFuturesOrderBook

This asynchronous TypeScript function, getFuturesOrderBook, retrieves the current price and order book for a specified futures ticker from the Binance API and formats it into a structured result.

Parameters

ParameterTypeDescription
symbolstringThe symbol for which to retrieve the order book (e.g., BTCUSDT).
orderBookLimitnumberThe limit on the number of orders to retrieve for the order book.

Usage

const orderBook = await getFuturesOrderBook('BTCUSDT', 100);

Result

TypeDescription
ResultOrderBookObjectAn object containing the symbol, order book type, current price, and the order book data (asks and bids).

getAllSpotTickerDensities

This asynchronous TypeScript function, getAllSpotTickerDensities, retrieves the order book for a specified spot ticker, calculates the density of orders, and returns the results.

Parameters

ParameterTypeDescription
symbolstringThe symbol for which to retrieve the order book (e.g., BTCUSDT).
densityCoefficientnumberA coefficient used to calculate the density of orders.
orderBookLimitnumberThe limit on the number of orders to retrieve for the order book.

Usage

const densities = await getAllSpotTickerDensities('BTCUSDT', 1.5, 100);

Result

TypeDescription
ObjectAn object containing the symbol, data type (spot), and arrays of calculated densities for asks and bids.

getAllFuturesTickerDensities

This asynchronous TypeScript function, getAllFuturesTickerDensities, retrieves the order book for a specified futures ticker, calculates the density of orders, and returns the results.

Parameters

ParameterTypeDescription
symbolstringThe symbol for which to retrieve the order book (e.g., BTCUSDT).
densityCoefficientnumberA coefficient used to calculate the density of orders.
orderBookLimitnumberThe limit on the number of orders to retrieve for the order book.

Usage

const densities = await getAllFuturesTickerDensities('BTCUSDT', 1.5, 100);

Result

TypeDescription
ObjectAn object containing the symbol, data type (futures), and arrays of calculated densities for asks and bids.

getSpotTrend

This asynchronous TypeScript function, getSpotTrend, retrieves candle chart data for a specified spot ticker from the Binance API and calculates the trend based on the retrieved data.

Parameters

ParameterTypeDescription
optionsCandlesOptionsAn object containing options for retrieving the candle data, such as symbol, interval, limit, start time, and end time.

Usage

const options = {
    symbol: "BTCUSDT",
    interval: "1h",
    limit: 100,
    startTime: 1622505600000,
    endTime: 1622592000000
};
const trend = await getSpotTrend(options);

Result

TypeDescription
TrendResultThe result of the trend calculation based on the candle data.

getFuturesTrend

This asynchronous TypeScript function, getFuturesTrend, retrieves candle chart data for a specified futures ticker from the Binance API and calculates the trend based on the retrieved data.

Parameters

ParameterTypeDescription
optionsCandlesOptionsAn object containing options for retrieving the candle data, such as symbol, interval, limit, start time, and end time.

Usage

const options = {
    symbol: "BTCUSDT",
    interval: "1h",
    limit: 100,
    startTime: 1622505600000,
    endTime: 1622592000000
};
const trend = await getFuturesTrend(options);

Result

TypeDescription
TrendResultThe result of the trend calculation based on the candle data.

getSpotCorrelation

This asynchronous TypeScript function, getSpotCorrelation, retrieves candle chart data for multiple spot tickers from the Binance API, calculates the correlation between each ticker and a specified second ticker, and returns the results.

Parameters

ParameterTypeDescription
tickersArrayOptionsCandlesOptions[]An array of options for retrieving the candle data for multiple tickers.
secondTickerOptionsCandlesOptionsOptions for retrieving the candle data for the second ticker.

Usage

const tickersArrayOptions = [
    { symbol: "BTCUSDT", interval: "1h", limit: 100, startTime: 1622505600000, endTime: 1622592000000 },
    // more options...
];
const secondTickerOptions = { symbol: "ETHUSDT", interval: "1h", limit: 100, startTime: 1622505600000, endTime: 1622592000000 };
const correlationResult = await getSpotCorrelation(tickersArrayOptions, secondTickerOptions);

Result

TypeDescription
GetCorrelationResultAn object containing the symbol of the second ticker and an array of correlation results for each ticker.

getFuturesCorrelation

This asynchronous TypeScript function, getFuturesCorrelation, retrieves candle chart data for multiple futures tickers from the Binance API, calculates the correlation between each ticker and a specified second ticker, and returns the results.

Parameters

ParameterTypeDescription
tickersArrayOptionsCandlesOptions[]An array of options for retrieving the candle data for multiple tickers.
secondTickerOptionsCandlesOptionsOptions for retrieving the candle data for the second ticker.

Usage

const tickersArrayOptions = [
    { symbol: "BTCUSDT", interval: "1h", limit: 100, startTime: 1622505600000, endTime: 1622592000000 },
    // more options...
];
const secondTickerOptions = { symbol: "ETHUSDT", interval: "1h", limit: 100, startTime: 1622505600000, endTime: 1622592000000 };
const correlationResult = await getFuturesCorrelation(tickersArrayOptions, secondTickerOptions);

Result

TypeDescription
GetCorrelationResultAn object containing the symbol of the second ticker and an array of correlation results for each ticker.

getSpotPumpsDumps

This asynchronous TypeScript function, getSpotPumpsDumps, retrieves candle chart data for a specified spot ticker from the Binance API, calculates significant price movements (pumps and dumps) based on a specified coefficient, and returns the results.

Parameters

ParameterTypeDescription
tickerOptionCandlesOptionsOptions for retrieving the candle data, such as symbol, interval, limit, start time, and end time.
coefficientnumberA multiplier used to determine the threshold for significant price changes.

Usage

const tickerOption = {
    symbol: "BTCUSDT",
    interval: "1h",
    limit: 100,
    startTime: 1622505600000,
    endTime: 1622592000000
};
const coefficient = 1.5;
const pumpsDumps = await getSpotPumpsDumps(tickerOption, coefficient);

Result

TypeDescription
PumpDumpResultAn object containing the symbol, symbol type, interval, limit, start time, end time, and arrays of candles identified as pumps and dumps.

getFuturesPumpsDumps

This asynchronous TypeScript function, getFuturesPumpsDumps, retrieves candle chart data for a specified futures ticker from the Binance API, calculates significant price movements (pumps and dumps) based on a specified coefficient, and returns the results.

Parameters

ParameterTypeDescription
tickerOptionCandlesOptionsOptions for retrieving the candle data, such as symbol, interval, limit, start time, and end time.
coefficientnumberA multiplier used to determine the threshold for significant price changes.

Usage

const tickerOption = {
    symbol: "BTCUSDT",
    interval: "1h",
    limit: 100,
    startTime: 1622505600000,
    endTime: 1622592000000
};
const coefficient = 1.5;
const pumpsDumps = await getFuturesPumpsDumps(tickerOption, coefficient);

Result

TypeDescription
PumpDumpResultAn object containing the symbol, symbol type, interval, limit, start time, end time, and arrays of candles identified as pumps and dumps.

Interfaces

FindAllTickersInterface

PropertyTypeDescription
tickerstringTicker symbol
tickSizenumberTick size of the ticker

Bid

PropertyTypeDescription
pricenumberBid price
quantitynumberBid quantity

CandleDataResult

PropertyTypeDescription
symbolstringSymbol of the asset
symbolTypeDataTypeType of the symbol (spot/futures)
intervalCandleChartInterval_LTInterval of the candle data
limitnumberLimit of the data points
startTimenumberStart time of the data
endTimenumberEnd time of the data
candlesDataCandleChartResult[]Array of candle data results

CandleChartResult

PropertyTypeDescription
openTimenumberOpening time of the candle
opennumberOpening price
highnumberHighest price
lownumberLowest price
closenumberClosing price
volumenumberVolume of the asset
closeTimenumberClosing time of the candle
quoteVolumenumberQuote volume
tradesnumberNumber of trades
baseAssetVolumenumberBase asset volume
quoteAssetVolumenumberQuote asset volume

ResultOrderBookObject

PropertyTypeDescription
symbolstringSymbol of the asset
orderBookTypeDataTypeType of the order book (spot/futures)
currentPricenumberCurrent price of the asset
orderBookOrderBookObjectOrder book data

OrderBookObject

PropertyTypeDescription
asksBid[]Array of ask bids
bidsBid[]Array of bid bids

DensityObject

PropertyTypeDescription
averageDensitynumberAverage density
densitiesBid[]Array of densities

AllDensities

PropertyTypeDescription
asksDensityObjectAsk densities
bidsDensityObjectBid densities

TrendResult

PropertyTypeDescription
trendTrendTypeTrend type
percentChangenumberPercentage change

TickerCorrelation

PropertyTypeDescription
symbolstringSymbol of the asset
correlationnumberCorrelation value

GetCorrelationResult

PropertyTypeDescription
symbolstringSymbol of the asset
correlationArrayTickerCorrelation[]Array of correlations

ApisData

PropertyTypeDescription
binanceApiKeystringBinance API key
binanceSecretKeystringBinance secret key

PumpDumpResult

PropertyTypeDescription
symbolstringSymbol of the asset
symbolTypeDataTypeType of the symbol (spot/futures)
intervalCandleChartInterval_LTInterval of the candle data
limitnumberLimit of the data points
startTimenumberStart time of the data
endTimenumberEnd time of the data
pumpsCandleChartResult[]Array of pump candle data
dumpsCandleChartResult[]Array of dump candle data

Types

DataType

ValueDescription
spotSpot market data
futuresFutures market data

SymbolStatus

ValueDescription
TRADINGTrading status
SETTLINGSettling status
PENDING_TRADINGPending trading status

TrendType

ValueDescription
UpUpward trend
DownDownward trend
Not changedNo change in trend

PumpDump

ValueDescription
PUMPPump event
DUMPDump event
1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago