Example: cmd: -d:ssl -d:nimDisableCertificateValidation -r:off
import src/binance let client: Binance = newBinance("YOUR_BINANCE_API_KEY", "YOUR_BINANCE_API_SECRET") let preparedEndpoint: string = client.ping() echo client.getContent(preparedEndpoint)
Types
AggregateTrades = enum AGG_BEST_MATCH = 77, AGG_TIME = 84, AGG_ID = 97, AGG_FIRST_TRADE_ID = 102, AGG_LAST_TRADE_ID = 108, AGG_BUYER_MAKES = 109, AGG_PRICE = 112, AGG_QUANTITY = 113
- For accessing the data returned by Client.aggregate_trades().
AssetTransfer = enum SPOT_TO_FIAT = "MAIN_C2C", SPOT_TO_USDT_FUTURE = "MAIN_UMFUTURE", SPOT_TO_COIN_FUTURE = "MAIN_CMFUTURE", SPOT_TO_MARGIN_CROSS = "MAIN_MARGIN", SPOT_TO_MINING = "MAIN_MINING", FIAT_TO_SPOT = "C2C_MAIN", FIAT_TO_USDT_FUTURE = "C2C_UMFUTURE", FIAT_TO_MINING = "C2C_MINING", USDT_FUTURE_TO_SPOT = "UMFUTURE_MAIN", USDT_FUTURE_TO_FIAT = "UMFUTURE_C2C", USDT_FUTURE_TO_MARGIN_CROSS = "UMFUTURE_MARGIN", COIN_FUTURE_TO_SPOT = "CMFUTURE_MAIN", MARGIN_CROSS_TO_SPOT = "MARGIN_MAIN", MARGIN_CROSS_TO_USDT_FUTURE = "MARGIN_UMFUTURE", MINING_TO_SPOT = "MINING_MAIN", MINING_TO_USDT_FUTURE = "MINING_UMFUTURE", MINING_TO_FIAT = "MINING_C2C"
- New asset transfer API Enum.
Binance = object apiKey*, apiSecret*: string ## Get API Key and API Secret at https://www.binance.com/en/my/settings/api-management recvWindow*: 5000 .. 60000 ## "Tolerance" for requests timeouts, Binance is very strict about "Timestamp" diff. client: HttpClient
- Binance API Client.
ContractType = enum PERPETUAL = "perpetual", CURRENT_QUARTER = "current_quarter", NEXT_QUARTER = "next_quarter"
FutureOrderType = enum FUTURE_ORDER_TYPE_LIMIT = "LIMIT", FUTURE_ORDER_TYPE_MARKET = "MARKET", FUTURE_ORDER_TYPE_STOP = "STOP", FUTURE_ORDER_TYPE_STOP_MARKET = "STOP_MARKET", FUTURE_ORDER_TYPE_TAKE_PROFIT = "TAKE_PROFIT", FUTURE_ORDER_TYPE_TAKE_PROFIT_MARKET = "TAKE_PROFIT_MARKET", FUTURE_ORDER_TYPE_LIMIT_MAKER = "LIMIT_MAKER"
FuturesType = enum USD_M = 1, COIN_M = 2
HistoricalKlinesType = enum SPOT = 1, FUTURES = 2
Interval = enum KLINE_INTERVAL_1MINUTE = "1m", KLINE_INTERVAL_3MINUTE = "3m", KLINE_INTERVAL_5MINUTE = "5m", KLINE_INTERVAL_15MINUTE = "15m", KLINE_INTERVAL_30MINUTE = "30m", KLINE_INTERVAL_1HOUR = "1h", KLINE_INTERVAL_2HOUR = "2h", KLINE_INTERVAL_4HOUR = "4h", KLINE_INTERVAL_6HOUR = "6h", KLINE_INTERVAL_8HOUR = "8h", KLINE_INTERVAL_12HOUR = "12h", KLINE_INTERVAL_1DAY = "1d", KLINE_INTERVAL_3DAY = "3d", KLINE_INTERVAL_1WEEK = "1w", KLINE_INTERVAL_1MONTH = "1M"
OrderStatus = enum ORDER_STATUS_NEW = "NEW", ORDER_STATUS_PARTIALLY_FILLED = "PARTIALLY_FILLED", ORDER_STATUS_FILLED = "FILLED", ORDER_STATUS_CANCELED = "CANCELED", ORDER_STATUS_PENDING_CANCEL = "PENDING_CANCEL", ORDER_STATUS_REJECTED = "REJECTED", ORDER_STATUS_EXPIRED = "EXPIRED"
OrderType = enum ORDER_TYPE_LIMIT = "LIMIT", ORDER_TYPE_MARKET = "MARKET", ORDER_TYPE_STOP_LOSS = "STOP_LOSS", ORDER_TYPE_STOP_LOSS_LIMIT = "STOP_LOSS_LIMIT", ORDER_TYPE_TAKE_PROFIT = "TAKE_PROFIT", ORDER_TYPE_TAKE_PROFIT_LIMIT = "TAKE_PROFIT_LIMIT", ORDER_TYPE_LIMIT_MAKER = "LIMIT_MAKER"
ResponseType = enum ORDER_RESP_TYPE_ACK = "ACK", ORDER_RESP_TYPE_RESULT = "RESULT", ORDER_RESP_TYPE_FULL = "FULL"
Side = enum SIDE_BUY = "BUY", SIDE_SELL = "SELL"
TimeInForce = enum TIME_IN_FORCE_GTC = "GTC", TIME_IN_FORCE_IOC = "IOC", TIME_IN_FORCE_FOK = "FOK", TIME_IN_FORCE_GTX = "GTX"
WebSocketDepth = enum WEBSOCKET_DEPTH_5 = "5", WEBSOCKET_DEPTH_10 = "10", WEBSOCKET_DEPTH_20 = "20"
Consts
binanceAPIUrl = "https://testnet.binance.vision"
Procs
proc accountData(self: Binance): string {....raises: [], tags: [TimeEffect].}
proc aggrTrades(self: Binance; symbol: string): string {....raises: [], tags: [].}
- Aggregated Trades list.
proc aggrTrades(self: Binance; symbol: string; fromId, startTime, endTime: Positive; limit: 1 .. 500 = 500): string {. ...raises: [], tags: [].}
- Aggregated Trades list.
proc aggrTrades(self: Binance; symbol: string; fromId: Positive; limit: 1 .. 500 = 500): string {....raises: [], tags: [].}
- Aggregated Trades list.
proc allOrderList(self: Binance): string {....raises: [], tags: [TimeEffect].}
proc exchangeInfo(self: Binance): string {....raises: [], tags: [].}
- Exchange information, info about Binance.
proc getOrder(self: Binance; symbol: string; orderId = 1.Positive; origClientOrderId = 1.Positive): string {....raises: [], tags: [TimeEffect].}
proc klines(self: Binance; symbol: string; interval: Interval; startTime, endTime: Positive; limit: 1 .. 500 = 500): string {. ...raises: [], tags: [].}
- Klines data, AKA Candlestick data.
proc klines(self: Binance; symbol: string; interval: Interval; limit: 1 .. 500 = 500): string {....raises: [], tags: [].}
- Klines data, AKA Candlestick data.
proc newBinance(apiKey, apiSecret: string): Binance {....raises: [KeyError], tags: [].}
- Constructor for Binance client.
proc olderTrades(self: Binance; symbol: string; limit: 1 .. 500 = 500): string {. ...raises: [], tags: [].}
- Old historical Trades.
proc olderTrades(self: Binance; symbol: string; limit: 1 .. 500 = 500; fromId: Positive): string {....raises: [], tags: [].}
- Old historical Trades.
proc openOrderList(self: Binance): string {....raises: [], tags: [TimeEffect].}
proc orderBook(self: Binance; symbol: string; limit: 5 .. 1000 = 100): string {. ...raises: [], tags: [].}
- Order book depth.
proc orderBookTicker(self: Binance): string {....raises: [], tags: [].}
- Symbol order book.
proc orderBookTicker(self: Binance; symbol: string): string {....raises: [], tags: [].}
- Symbol order book.
proc orderList(self: Binance; orderListId = 1.Positive): string {....raises: [], tags: [TimeEffect].}
proc orderTest(self: Binance; side: Side; tipe: OrderType; newOrderRespType: ResponseType; timeInForce, newClientOrderId, symbol: string; quantity, price: float): string {....raises: [], tags: [TimeEffect].}
proc ping(self: Binance): string {....raises: [], tags: [].}
- Test connectivity to Binance, just a ping.
proc postOrder(self: Binance; side: Side; tipe: OrderType; timeInForce, symbol: string; quantity, price: float): string {. ...raises: [], tags: [TimeEffect].}
proc rateLimitOrder(self: Binance): string {....raises: [], tags: [TimeEffect].}
proc recentTrades(self: Binance; symbol: string; limit: 1 .. 500 = 500): string {. ...raises: [], tags: [].}
- Get a list of recent Trades.
proc request(self: Binance; endpoint: string; httpMethod: HttpMethod = HttpGet): string {....raises: [ IOError, OSError, ValueError, HttpRequestError, Exception, LibraryError, SslError, TimeoutError, ProtocolError, KeyError], tags: [ReadIOEffect, RootEffect, WriteIOEffect, TimeEffect].}
proc ticker24h(self: Binance): string {....raises: [], tags: [].}
- Price changes in the last 24 hours.
proc ticker24h(self: Binance; symbol: string): string {....raises: [], tags: [].}
- Price changes in the last 24 hours.
proc tickerPrice(self: Binance): string {....raises: [], tags: [].}
- Symbol price.
proc tickerPrice(self: Binance; symbol: string): string {....raises: [], tags: [].}
- Symbol price.
proc userDataStream(self: Binance): string {....raises: [], tags: [].}
-
Start a new user data stream.
- POST to Open a new user data stream.
- DELETE to Delete an existing user data stream. Auto-closes at 60 minutes idle.
- GET to Keep Alive an existing user data stream.
Templates
template getContent(self: Binance; url: string): string