npm package: @openxapi/binance
Description: JavaScript/TypeScript client for Binance Spot API
Author: OpenXAPI
Latest version: 0.3.0

# JavaScript / TypeScript Client for Binance API

[![NPM Version](https://img.shields.io/npm/v/%40openxapi%2Fbinance)](https://www.npmjs.com/package/@openxapi/binance)

This API client was automatically generated by [OpenXAPI](https://github.com/openxapi/openxapi) using [OpenAPI Generator](https://openapi-generator.tech).

**Please do not edit the generated code manually.**

If you need to update the API client, please submit an issue or a PR to [OpenXAPI](https://github.com/openxapi/openxapi).

### Overview

This generator creates TypeScript/JavaScript client that utilizes [axios](https://github.com/axios/axios). The generated Node module can be used in the following environments:

Environment
* Node.js
* Webpack
* Browserify

Language level
* ES5 - you must have a Promises/A+ library installed
* ES6

Module system
* CommonJS
* ES6 module system

It can be used in both TypeScript and JavaScript. In TypeScript, the definition will be automatically resolved via `package.json`. ([Reference](https://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html))

### Building

To build and compile the typescript sources to javascript use:
```
npm install
npm run build
```

### Installation

navigate to the folder of your consuming project and run one of the following commands.

```
npm install @openxapi/binance --save
```

### Modules

| Product | Module | Sub Products |
|:--------:|:-------------:|-------------|
| Spot API | `spot` | ✅ [Spot Trading](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-api-information) <br> ✅ [Margin Trading](https://developers.binance.com/docs/margin_trading/Introduction) <br> ✅ [Algo Trading](https://developers.binance.com/docs/algo/Introduction) <br> ✅ [Wallet](https://developers.binance.com/docs/wallet/Introduction) <br> ✅ [Copy Trading](https://developers.binance.com/docs/copy_trading/Introduction) <br> ✅ [Convert](https://developers.binance.com/docs/convert/Introduction) <br> ✅ [Sub Account](https://developers.binance.com/docs/sub_account/Introduction) <br>✅ [Binance Link](https://developers.binance.com/docs/binance_link/change-log) <br>✅ [Futures Data](https://developers.binance.com/docs/derivatives/futures-data/general-info) <br> ✅ [Portfolio Margin Pro](https://developers.binance.com/docs/derivatives/portfolio-margin-pro/general-info) <br>✅ [Staking](https://developers.binance.com/docs/staking/Introduction) <br>✅ [Dual Investment](https://developers.binance.com/docs/dual_investment/Introduction) <br>✅ [Mining](https://developers.binance.com/docs/mining/Introduction) <br>✅ [Crypto Loan](https://developers.binance.com/docs/crypto_loan/Introduction) <br>✅ [VIP Loan](https://developers.binance.com/docs/vip_loan/Introduction) <br>✅ [C2C](https://developers.binance.com/docs/c2c/Introduction) <br>✅ [Fiat](https://developers.binance.com/docs/fiat/Introduction) <br>✅ [NFT](https://developers.binance.com/docs/nft/Introduction) <br>✅ [Gift Card](https://developers.binance.com/docs/gift_card/Introduction) <br>✅ [Rebate](https://developers.binance.com/docs/rebate/Introduction) <br>✅ [Simple Earn](https://developers.binance.com/docs/simple_earn/Introduction) <br>✅ [Binance Pay History](https://developers.binance.com/docs/pay/Introduction) |
| USD-M Futures API | `umfutures` | ✅ [USDS Margined Futures](https://developers.binance.com/docs/derivatives/usds-margined-futures/general-info) <br> ✅ [Binance Link](https://developers.binance.com/docs/binance_link/link-and-trade/futures) |
| COIN-M Futures API | `cmfutures` | ✅ [COIN Margined Futures](https://developers.binance.com/docs/derivatives/coin-margined-futures/general-info) |
| Options API | `options` | ✅ [Options](https://developers.binance.com/docs/derivatives/option/general-info) |
| Portfolio Margin API | `pmargin` | ✅ [Portfolio Margin](https://developers.binance.com/docs/derivatives/portfolio-margin/general-info) |

### Usage

```typescript
import { spot, umfutures } from '@openxapi/binance';

async function testSpot() {
  // Initialize the Binance API client
  const config = new spot.Configuration({
    auth: new spot.BinanceAuth({
        // get from env variables
        apiKey: process.env.BINANCE_API_KEY!,
        privateKeyPath: "/path/to/your/private/key", // Automatically detects RSA or Ed25519 keys
    }),
  });
  
  const apiInstance = new spot.SpotTradingApi(config);
  const resp = await apiInstance.GetAccountV3({
    timestamp: Date.now(),
  });
  console.log(resp);
  console.log("resp.data.accountType:", resp.data.accountType);
}

async function testUmFutures() {
    const config = new umfutures.Configuration({
        auth: new umfutures.BinanceAuth({
            apiKey: process.env.BINANCE_API_KEY!,
            privateKeyPath: "/path/to/your/private/key", // Automatically detects RSA or Ed25519 keys
        }),
    });

    const apiInstance = new umfutures.FuturesApi(config);
    const resp = await apiInstance.GetKlinesV1({
        symbol: 'BTCUSDT',
        interval: '1h',
    });
    console.log(resp);
}

async function main() {
    await testSpot();
    await testUmFutures();
}

main().catch(console.error);
```