Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pixtron/binance-rate-limit
node.js rate limit tracker for binance. Let's you verify that you won't hit a rate limit before you send your api request.
https://github.com/pixtron/binance-rate-limit
api binance nodejs rate-limit
Last synced: 6 days ago
JSON representation
node.js rate limit tracker for binance. Let's you verify that you won't hit a rate limit before you send your api request.
- Host: GitHub
- URL: https://github.com/pixtron/binance-rate-limit
- Owner: pixtron
- License: mit
- Created: 2022-01-08T14:41:38.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-01-29T19:26:52.000Z (about 3 years ago)
- Last Synced: 2025-01-03T13:38:59.133Z (about 1 month ago)
- Topics: api, binance, nodejs, rate-limit
- Language: TypeScript
- Homepage:
- Size: 169 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# @pxtrn/binance-rate-limit
node.js rate limit tracker for binance. Let's you verify that you won't hit
a rate limit before you send your api request.## Installation
`npm install --save @pxtrn/binance-rate-limit`
## Usage
Also see the full [axios example](examples/axios.ts)
```ts
import { createSpotLimiter, IRequest, IResponse } from '@pxtrn/binance-rate-limit';const request = async (req: IRequest): Promise => {
// dispatch request with your preferred request library
}const req: IRequest = {
method: 'GET',
endpoint: '/api/v3/exchangeInfo',
params: {symbol: 'BTCUSDT'},
uid: 'xxx' // binance accountId or hashed apiKey if accountId is not available
};const limiter = createSpotLimiter();
const retryIn = limiter.mayDispatchRequest(req);if (retryIn === 0) {
// if retryIn === 0 dispatch the request immediately.
const response = await request(req);const { statusCode, headers } = response;
const res: IResponse = {statusCode, headers};// update counters, make sure to call this as well if you got
// a response with a status code other then 2xx or any error during request
limiter.completeRequest(res, req);
} else {
// if retryIn > 0 throw and reschedule call
throw new Error(`Rate limit exceeded retry in ${retryIn}`);
}
```