Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents a single Binance API client.

Hierarchy

  • BinanceApiClient

Index

Constructors

constructor

  • Initializes a new Binance API client.

    Parameters

    • Optional apiKey: string

      The personal account API key.

    • Optional apiSecret: string

      The personal account API secret.

    Returns BinanceApiClient

Properties

Static Private API_KEY

API_KEY: string

Static Private API_SECRET

API_SECRET: string

Static Private DEFAULT_WS_TIMEOUT

DEFAULT_WS_TIMEOUT: number = 60000

Static Private WS_BASE_URL

WS_BASE_URL: string = "wss://stream.binance.com:9443/ws/"

Methods

cancelOrder

  • cancelOrder(symbol: string, id?: number, oldClientId?: string, newClientId?: string, timeout?: number): Promise<CanceledOrderData>
  • Interface to the "DELETE v3/order" Binance's API operation. Cancels a previously placed order.

    Parameters

    • symbol: string

      The market on which the order was originally placed.

    • Optional id: number

      The wanted order ID.

    • Optional oldClientId: string

      The pre-cancel client given order ID (its description).

    • Optional newClientId: string

      The post-cancel order ID (automatically generated if not passed).

    • Optional timeout: number

      The request validity maximum time frame (defaults to 5000 ms).

    Returns Promise<CanceledOrderData>

    The just-canceled order data.

closeUserStream

  • closeUserStream(streamId: string): Promise<void>
  • Interface to the "DELETE v1/userDataStream" Binance's API operation. Closes out a user data stream.

    Parameters

    • streamId: string

      A string representing the stream's ID (returned by openUserStream).

    Returns Promise<void>

getAccountData

  • getAccountData(timeout?: number): Promise<AccountData>
  • Interface to the "GET v3/account" Binance's API operation. Get current account information.

    Parameters

    • Optional timeout: number

      The request validity maximum time frame (defaults to 5000 ms).

    Returns Promise<AccountData>

    The current account information.

getCandlesticks

  • Interface to the "GET v1/klines" Binance's API operation. Get candlestick bars for the specified symbol, respecting all the other given constraints. Candlesticks are uniquely identified by their opening time.

    Parameters

    • symbol: string

      The symbol for which we want to retrieve the candlesticks.

    • interval: CandlestickInterval

      The interval which the requested candlesticks refer to.

    • Optional limit: number

      The maximum number of candlesticks returned.

    • Optional startTime: number

      The time from which the candlesticks are returned.

    • Optional endTime: number

      The time until which the candlesticks are returned.

    Returns Promise<Candlestick[]>

    A candlesticks array respecting the given constraints.

getExchangeInfo

getLastDayTickerStatistics

  • Interface to the "GET v1/ticker/24hr" Binance's API operation. Get last 24 hours price change statistics.

    Parameters

    • symbol: string

      The symbol for which we want to retrieve the last day ticker statistics.

    Returns Promise<TickerStatistics>

    The last 24-hour ticker statistics.

getLatestPrices

  • Interface to the "GET v1/ticker/allPrices" Binance's API operation. Get the latest price for all symbols.

    Returns Promise<LatestPrice[]>

    A latest prices array for all the symbols.

getOpenOrders

  • getOpenOrders(market?: string, timeout?: number): Promise<Order[]>
  • Interface to the "GET v3/openOrders" Binance's API operation.

    Parameters

    • Optional market: string

      The symbol for which we want to retrieve the open orders (if any).

    • Optional timeout: number

      The request validity maximum time frame (defaults to 5000 ms).

    Returns Promise<Order[]>

    An array representing all of the account's open orders.

getOrder

  • getOrder(symbol: string, id?: number, clientId?: string, timeout?: number): Promise<Order>
  • Interface to the "GET v3/order" Binance's API operation. Gets a placed order detail given some constraints.

    Parameters

    • symbol: string

      The market on which the order was originally placed.

    • Optional id: number

      The wanted order ID.

    • Optional clientId: string

      The wanted client given order ID (its description).

    • Optional timeout: number

      The request validity maximum time frame (defaults to 5000 ms).

    Returns Promise<Order>

    The placed order detail respecting the given constraints.

getOrderBook

  • getOrderBook(symbol: string, limit?: number): Promise<OrderBook>
  • Interface to the "GET v1/depth" Binance's API operation.

    Parameters

    • symbol: string

      The symbol for which we want to retrieve the order book.

    • Optional limit: number

      The maximum number of orders in the returned order book.

    Returns Promise<OrderBook>

    The order book respecting the given constraints.

getOrders

  • getOrders(symbol: string, id?: number, limit?: number, timeout?: number): Promise<Order[]>
  • Interface to the "GET v3/allOrders" Binance's API operation. Get all account orders (active, canceled, or filled).

    Parameters

    • symbol: string

      The symbol for which we want to retrieve the orders.

    • Optional id: number

      The order ID from which we want to retrieve the orders (if set, the API will retrieve the orders with an ID greater or equal to the one specified, otherwise the most recent orders).

    • Optional limit: number

      The maximum number of returned orders.

    • Optional timeout: number

      The request validity maximum time frame (defaults to 5000 ms).

    Returns Promise<Order[]>

    An array representing all of the account's orders in every state.

getServerTime

  • getServerTime(): Promise<Date>
  • Interface to the "GET v1/time" Binance's API operation.

    Returns Promise<Date>

    The Binance's server time.

getTickers

  • getTickers(): Promise<Ticker[]>
  • Interface to the "GET v1/ticker/allBookTickers" Binance's API operation. Get the best price/quantity in the order book for all symbols.

    Returns Promise<Ticker[]>

    The best price/quantity in the order book for all symbols.

getTrades

  • getTrades(symbol: string, limit?: number, fromId?: number, timeout?: number): Promise<Trade[]>
  • Interface to the "GET v3/myTrades" Binance's API operation. Get trades for a specific account and symbol.

    Parameters

    • symbol: string

      The market on which the trades were originally executed.

    • Optional limit: number

      The maximum number of returned trades.

    • Optional fromId: number

      The trade's ID to start fetching from. If not given, the API will retrieve the most recent trades first.

    • Optional timeout: number

      The request validity maximum time frame (defaults to 5000 ms).

    Returns Promise<Trade[]>

    The account's trade list respecting the given constraints.

keepAliveUserStream

  • keepAliveUserStream(streamId: string): Promise<void>
  • Interface to the "PUT v1/userDataStream" Binance's API operation. Pings a user data stream in order to prevent a time out.

    Parameters

    • streamId: string

      A string representing the stream's ID (returned by openUserStream).

    Returns Promise<void>

Private makeRequest

  • Utility method that sets up and sends a request to the Binance's API, handling the authentication through the API key and API secret parameters possibly given when instantiating the client itself.

    Parameters

    • httpMethod: HttpMethod

      The HTTP method through which the specified API is accessed.

    • apiVersion: ApiVersion

      The API version at which the wanted resource can be accessed.

    • accessedResource: string

      The Binance's API resource that we would like to access.

    • requiredAuthentication: AuthenticationMethod

      The authentication type required in order to access the specified resource.

    • Rest ...parameters: [string, any][]

      The parameters which the accessed resource may use in order to give us the expected result.

    Returns Promise<any>

    Either the promise of the Binance's API JSON response, or the JSON response if using the await construct.

monitorCandlesticks

  • monitorCandlesticks(symbol: string, interval: CandlestickInterval, onUpdate: function, connectionTimeout?: number, onLostConnection?: function): Promise<void>
  • Initializes a web socket data stream that gives us information about Kline/candlestick updates. Stream keepalive is performed through keepAliveUserStream following the rules described here

    Parameters

    • symbol: string

      The symbol of which we want to get the candlestick updates.

    • interval: CandlestickInterval

      The interval to which the requested candlestick updates refer to.

    • onUpdate: function

      A function to be called when a new update is received.

    • Optional connectionTimeout: number

      Timeout based on which the web socket connection is considered to be broken based on a heartbeat monitor.

    • Optional onLostConnection: function

      A callback to be invoked when the web socket connection is detected as broken.

        • (): any
        • Returns any

    Returns Promise<void>

monitorOrderBook

  • monitorOrderBook(symbol: string, onUpdate: function, connectionTimeout: number, onLostConnection: function): void
  • Initializes a web socket data stream that gives us information about a single symbol's order book updates. Stream keepalive is performed through keepAliveUserStream following the rules described here

    Parameters

    • symbol: string

      The symbol of which we want to get the order book updates.

    • onUpdate: function

      A function to be called when a new update is received.

    • connectionTimeout: number

      Timeout based on which the web socket connection is considered to be broken based on a heartbeat monitor.

    • onLostConnection: function

      A callback to be invoked when the web socket connection is detected as broken.

        • (): any
        • Returns any

    Returns void

monitorTrades

  • monitorTrades(symbol: string, onUpdate: function, connectionTimeout: number, onLostConnection: function): void
  • Initializes a web socket data stream that gives us information about trade updates. Stream keepalive is performed through keepAliveUserStream following the rules described here

    Parameters

    • symbol: string

      The symbol of which we want to get the trade updates.

    • onUpdate: function

      A function to be called when a new update is received.

    • connectionTimeout: number

      Timeout based on which the web socket connection is considered to be broken based on a heartbeat monitor.

    • onLostConnection: function

      A callback to be invoked when the web socket connection is detected as broken.

        • (): any
        • Returns any

    Returns void

monitorUser

  • monitorUser(listenKey: string, onUpdate: function, connectionTimeout: number, onLostConnection: function): void
  • Initializes a web socket data stream that gives us information about the personal account updates. Stream keepalive is performed through keepAliveUserStream following the rules described here

    Parameters

    • listenKey: string

      The listen key returned when a user data stream gets initialized by openUserStream.

    • onUpdate: function

      A function to be called when a new update is received.

    • connectionTimeout: number

      Timeout based on which the web socket connection is considered to be broken based on a heartbeat monitor.

    • onLostConnection: function

      A callback to be invoked when the web socket connection is detected as broken.

        • (): any
        • Returns any

    Returns void

openUserStream

  • openUserStream(): Promise<string>
  • Interface to the "POST v1/userDataStream" Binance's API operation. Initializes a new data stream.

    Returns Promise<string>

    A listen key to be passed as a parameter when starting a new data stream.

ping

  • ping(): Promise<void>

placeOrder

  • Interface to the "POST v3/order" Binance's API operation. Places a new order respecting the given constraints.

    Parameters

    • symbol: string

      The market on which the order is to be placed.

    • side: OrderSide

      Whether the order is a buy or sell.

    • type: OrderType

      Whether the order is at limit or market.

    • timeInForce: TimeInForce

      Whether the time in force should be GTC or IOC.

    • quantity: number

      The quantity of assets that is to be moved.

    • price: number

      The price at which the order should be filled.

    • Optional clientOrderId: string

      A unique ID associated with the order (automatically generated if not sent).

    • Optional stopPrice: number

      The price at which a stop order should be filled.

    • Optional icebergQuantity: number

      Only used with iceberg orders.

    • Optional responseType: ResponseType

      Set the response JSON. ACK, RESULT, or FULL; default: RESULT.

    Returns Promise<OrderAcknowledgement | OrderResult | OrderFull>

    The just-placed order data.

Private setupAuthentication

  • Utility method setting up the request in order to handle Binance's various authentication methods.

    Parameters

    • httpMethod: HttpMethod

      The HTTP method used to access the wanted resource (mainly used for error logging purposes).

    • apiUrl: URL

      The URL at which the wanted resource can be accessed.

    • authenticationMethod: AuthenticationMethod

      The authentication method through which the wanted resource can be accessed through the specified URL.

    Returns any

testOrder

  • testOrder(symbol: string, side: OrderSide, type: OrderType, timeInForce: TimeInForce, quantity: number, price: number, clientId?: string, stopPrice?: number, icebergQuantity?: number, timeout?: number): Promise<void>
  • Interface to the "POST v3/order/test" Binance's API operation. Places a new test order respecting the given constraints.

    Parameters

    • symbol: string

      The market on which the order is to be placed.

    • side: OrderSide

      Whether the order is a buy or sell.

    • type: OrderType

      Whether the order is at limit or market.

    • timeInForce: TimeInForce

      Whether the time in force should be GTC or IOC.

    • quantity: number

      The quantity of assets that is to be moved.

    • price: number

      The price at which the order should be filled.

    • Optional clientId: string

      A unique ID associated with the order. (automatically generated if not sent).

    • Optional stopPrice: number

      The price at which a stop order should be filled.

    • Optional icebergQuantity: number

      Only used with iceberg orders.

    • Optional timeout: number

      The request validity maximum time frame (defaults to 5000 ms).

    Returns Promise<void>

Generated using TypeDoc