Skip to content

Commit b01a876

Browse files
authored
Merge pull request #922 from ccxt/ts-support
chore: full refactor towards class-based await/async + TS + ESM
2 parents f3e16da + af2e35a commit b01a876

28 files changed

Lines changed: 17745 additions & 11367 deletions

.eslintrc.json

Lines changed: 0 additions & 61 deletions
This file was deleted.

.github/workflows/js.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,21 @@ jobs:
2323
cache: 'npm'
2424
- name: Install npm dependencies
2525
run: npm i --include=dev
26-
- name: Static Tests
26+
- name: Lint
27+
run: npm run lint
28+
- name: Build
29+
run: npm run build
30+
- name: Static Tests (TS ESM)
31+
run: npm run ts-test-static
32+
- name: Static Tests (JS CJS)
2733
run: npm run static-test
28-
- name: Live Tests
29-
run: npm run test
34+
- name: Live Tests (TS ESM)
35+
run: npm run ts-test-live
36+
- name: Ws Live Tests (spot)
37+
run: npm run ws-tests-spot
38+
- name: Ws Live Tests (futures)
39+
run: npm run ws-tests-futures
40+
- name: CJS test
41+
run: npm run test-cjs
42+
- name: Package test
43+
run: npm run package-test

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
ehthumbs.db
3737
Thumbs.db
3838

39+
dist/
40+
3941
# Secrets #
4042
###########
4143
.secret

.mocharc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://json.schemastore.org/mocharc.json",
3+
"require": "tsx"
4+
}

.npmignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Initally ignore all files
2+
*
3+
4+
# Files to include
5+
!package.json
6+
!package-lock.json
7+
!LICENSE.txt
8+
!README.md
9+
10+
# Folders to include
11+
!src/**/*
12+
!dist/**/*
13+

README.md

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ color=blueviolet 🔵q
1717

1818

1919

20-
21-
22-
2320
# Node Binance API
2421

2522
[![telegram](https://patrolavia.github.io/telegram-badge/chat.png)](https://t.me/nodebinanceapi) [![Yearly Downloads](https://img.shields.io/npm/dy/node-binance-api.svg)](https://www.npmjs.com/package/node-binance-api) [![jaggedsoft on X](https://img.shields.io/twitter/follow/jaggedsoft.svg?style=social)](https://x.com/jaggedsoft)
@@ -44,7 +41,7 @@ This project is designed to help you make your own projects that interact with t
4441
#### Installation
4542

4643
```
47-
npm install -s node-binance-api
44+
npm install node-binance-api
4845
```
4946
[![NPM](https://nodei.co/npm/node-binance-api.png?compact=true)](https://npmjs.org/package/node-binance-api)
5047
<!-- [![npm install node-binance-api](https://nodei.co/npm/node-binance-api.png?mini=true)](https://npmjs.org/package/node-binance-api) -->
@@ -56,6 +53,28 @@ https://t.me/nodebinanceapi
5653

5754
**This project is powered by** <a href="https://github.com/ccxt/ccxt"><img src="https://avatars.githubusercontent.com/u/31901609" width=4% height=4%></a>
5855

56+
Actively maintained, typed, and safe SDK for the Binance REST APIs and Websockets. Supports ESM and CJS out of the box.
57+
58+
### Features
59+
- Spot, Margin, Futures and Delivery API
60+
- Portfolio Margin API *\*soon*\*
61+
- Testnet support
62+
- Proxy support (REST and WS)
63+
- Customizable HTTP headers
64+
- Customizable request parameters
65+
- RSA/ECDSA support *\*soon*\*
66+
- Websocket handling with automatic reconnection
67+
- RecvWindow and automatic timestamps generation
68+
- Ability to call any endpoint, even if not supported directly by the library
69+
- Overridable hostnames (.us, .jp, etc)
70+
- Verbose mode to debug http requests/responses
71+
72+
### Upgrading to v1.0.0+
73+
74+
The library was fully refactored to use modern and typed JavaScript/Typescript version, using the built-in await/async syntax and unifying some methods' signatures. Some important changes include the removal of callbacks as parameters of REST methods, adaptation of signatures to directly receive some important request values (symbol, orderId, ...), etc.
75+
76+
**We highly advise you to update from 0.0.X but minor adjustments might be needed.**
77+
5978

6079
#### Getting started (ESM)
6180
```javascript
@@ -70,7 +89,7 @@ async function run() {
7089
#### Getting started (CJS)
7190
```javascript
7291
const Binance = require('node-binance-api');
73-
const binance = new Binance().options({
92+
const binance = new Binance({
7493
APIKEY: '<key>',
7594
APISECRET: '<secret>',
7695
test: true, // if you want to use the sandbox/testnet
@@ -96,12 +115,12 @@ console.info( await binance.futuresBalance() );
96115

97116
#### Futures Limit Buy
98117
```js
99-
console.info( await binance.futuresBuy( 'BTCUSDT', 0.1, 8222 ) );
118+
console.info( await binance.futuresBuy( 'LIMIT', 'BTCUSDT', 0.1, 8222 ) );
100119
```
101120

102121
#### Futures Limit Sell
103122
```js
104-
console.info( await binance.futuresSell( 'BTCUSDT', 0.5, 11111 ) );
123+
console.info( await binance.futuresSell( 'LIMIT', 'BTCUSDT', 0.5, 11111 ) );
105124
```
106125

107126
#### Futures Market Buy
@@ -197,20 +216,55 @@ console.info( await binance.futuresHistoricalTrades( "XMRUSDT" ) );
197216
console.info( await binance.futuresLeverageBracket( "LINKUSDT" ) );
198217
console.info( await binance.futuresIncome() );
199218
console.info( await binance.futuresCancelAll( "BTCUSDT" ) );
200-
console.info( await binance.futuresCancel( "BTCUSDT", {orderId: "1025137386"} ) );
219+
console.info( await binance.futuresCancel( "BTCUSDT", "1025137386" ) );
201220
console.info( await binance.futuresCountdownCancelAll( "BTCUSDT", 45000 ) );
202-
console.info( await binance.futuresOrderStatus( "BTCUSDT", {orderId: "1025137386"} ) );
221+
console.info( await binance.futuresOrderStatus( "BTCUSDT", "1025137386") );
203222
console.info( await binance.futuresOpenOrders() );
204223
console.info( await binance.futuresOpenOrders( "BTCUSDT" ) );
205224
console.info( await binance.futuresAllOrders() );
206225
console.info( await binance.futuresAllOrders( "BTCUSDT" ) );
207226
console.info( await binance.futuresUserTrades( "BTCUSDT" ) );
208227
console.info( await binance.futuresGetDataStream() );
209228
console.info( await binance.futuresPositionMarginHistory( "TRXUSDT" ) );
210-
console.info( await binance.promiseRequest( 'v1/time' ) );
229+
console.info( await binance.futuresPublicRequest( 'v1/time' ) );
230+
console.info( await binance.spotPublicRequest( 'v1/time')); // call any method by providing the path
231+
console.info( await binance.privateFuturesRequest('v3/account')); // custom futures private call
211232
// Batch orders, remaining WebSocket streams, and better documentation will be come later
212233
```
213234

235+
### Proxy support
236+
237+
In some specific cases using a proxy is required, for example:
238+
- Exchange is not available in your location
239+
- You need to make a large amount of requests without getting blocked
240+
- ...
241+
242+
This package supports the following proxy types, `httpsProxy`, `proxyUrl` and `socksProxy`
243+
244+
#### httpsProxy
245+
246+
To set a real http(s) proxy for your scripts, you need to have an access to a remote http or https proxy, so calls will be made directly to the target exchange, tunneled through your proxy server:
247+
248+
```Js
249+
client.httpsProxy = 'http://1.2.3.4:8080/';
250+
```
251+
252+
#### proxyUrl
253+
254+
This property prepends an url to API requests. It might be useful for simple redirection or bypassing CORS browser restriction.
255+
256+
```Js
257+
client.proxyUrl = 'YOUR_PROXY_URL';
258+
```
259+
260+
#### socksProxy
261+
262+
Tou can also use socks proxy with the following format:
263+
264+
```Js
265+
client.socksProxy = 'socks5://1.2.3.4:8080/';
266+
```
267+
214268
#### Futures Historical Bulk Data Download API
215269

216270
##### Get Download ID
@@ -296,6 +350,8 @@ binance.futuresTerminate( 'btcusdt@kline_4h' );
296350
console.log( binance.futuresSubscriptions() );
297351
```
298352

353+
354+
299355
# Delivery API (Futures w/Expiration Date)
300356
```
301357
deliveryBuy

0 commit comments

Comments
 (0)