binance-api-node
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -24,3 +24,3 @@ 'use strict'; | ||
var BASE = 'https://www.binance.com/api'; | ||
var BASE = 'https://www.binance.com'; | ||
@@ -85,3 +85,3 @@ /** | ||
var method = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'GET'; | ||
return sendResult(fetch('' + BASE + path + makeQueryString(data), { | ||
return sendResult(fetch(BASE + '/api' + path + makeQueryString(data), { | ||
method: method, | ||
@@ -119,3 +119,3 @@ json: true | ||
return sendResult(fetch('' + BASE + path + (noData ? '' : makeQueryString(newData)), { | ||
return sendResult(fetch('' + BASE + (path.includes('/wapi') ? '' : '/api') + path + (noData ? '' : makeQueryString(newData)), { | ||
method: method, | ||
@@ -255,2 +255,15 @@ headers: { 'X-MBX-APIKEY': apiKey }, | ||
withdraw: function withdraw(payload) { | ||
return pCall('/wapi/v1/withdraw.html', payload, 'POST'); | ||
}, | ||
withdrawHistory: function withdrawHistory(payload) { | ||
return pCall('/wapi/v1/getWithdrawHistory.html', payload, 'POST'); | ||
}, | ||
depositHistory: function depositHistory(payload) { | ||
return pCall('/wapi/v1/getDepositHistory.html', payload, 'POST'); | ||
}, | ||
depositAddress: function depositAddress(payload) { | ||
return pCall('/wapi/v1/getChargeAddress.html', payload, 'POST'); | ||
}, | ||
getDataStream: function getDataStream() { | ||
@@ -257,0 +270,0 @@ return pCall('/v1/userDataStream', null, 'POST', true); |
@@ -6,2 +6,3 @@ 'use strict'; | ||
}); | ||
exports.keepStreamAlive = exports.userEventHandler = undefined; | ||
@@ -167,2 +168,19 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var userEventHandler = function userEventHandler(cb) { | ||
return function (msg) { | ||
var _JSON$parse4 = JSON.parse(msg), | ||
type = _JSON$parse4.e, | ||
rest = _objectWithoutProperties(_JSON$parse4, ['e']); | ||
cb(userTransforms[type] ? userTransforms[type](rest) : _extends({ type: type }, rest)); | ||
}; | ||
}; | ||
exports.userEventHandler = userEventHandler; | ||
var keepStreamAlive = exports.keepStreamAlive = function keepStreamAlive(method, listenKey) { | ||
return function () { | ||
return method({ listenKey: listenKey }); | ||
}; | ||
}; | ||
var user = function user(opts) { | ||
@@ -179,14 +197,7 @@ return function (cb) { | ||
var w = new _ws2.default(BASE + '/' + listenKey); | ||
w.on('message', function (msg) { | ||
var _JSON$parse4 = JSON.parse(msg), | ||
type = _JSON$parse4.e, | ||
rest = _objectWithoutProperties(_JSON$parse4, ['e']); | ||
w.on('message', userEventHandler(cb)); | ||
cb(userTransforms[type] ? userTransforms[type](rest) : _extends({ type: type }, rest)); | ||
}); | ||
var int = setInterval(keepStreamAlive(keepDataStream, listenKey), 42e3); | ||
keepStreamAlive(keepDataStream, listenKey)(); | ||
var int = setInterval(function () { | ||
keepDataStream({ listenKey: listenKey }); | ||
}, 42e3); | ||
return function () { | ||
@@ -193,0 +204,0 @@ clearInterval(int); |
{ | ||
"name": "binance-api-node", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A node API wrapper for Binance", | ||
@@ -5,0 +5,0 @@ "main": "dist", |
124
README.md
@@ -1,2 +0,2 @@ | ||
# binance-api-node [![Build](https://img.shields.io/travis/HyperCubeProject/binance-api-node.svg?style=flat-square)](https://travis-ci.org/HyperCubeProject/binance-api-node) [![Coverage](https://img.shields.io/coveralls/HyperCubeProject/binance-api-node.svg?style=flat-square)](https://coveralls.io/github/HyperCubeProject/binance-api-node) | ||
# binance-api-node [![Build](https://img.shields.io/travis/HyperCubeProject/binance-api-node.svg?style=flat-square)](https://travis-ci.org/HyperCubeProject/binance-api-node) [![Coverage](https://img.shields.io/coveralls/HyperCubeProject/binance-api-node.svg?style=flat-square)](https://coveralls.io/github/HyperCubeProject/binance-api-node) [![bnb](https://img.shields.io/badge/binance-winner-yellow.svg?style=flat-square)](https://github.com/binance-exchange/binance-api-node) | ||
@@ -56,5 +56,9 @@ > A complete API wrapper for the [Binance](https://binance.com) API. | ||
- [myTrades](#mytrades) | ||
- [depositHistory](#deposithistory) | ||
- [withdrawHistory](#withdrawhistory) | ||
- [widthdraw](#withdraw) | ||
- [depositAddress](#depositaddress) | ||
- [Websockets](#websockets) | ||
- [depth](#depth) | ||
- [candles](#candles) | ||
- [candles](#candles-1) | ||
- [trades](#trades) | ||
@@ -536,2 +540,118 @@ - [user](#user) | ||
#### depositHistory | ||
Get the account deposit history. | ||
```js | ||
console.log(await client.depositHistory()) | ||
``` | ||
|Param|Type|Required|Description| | ||
|--- |--- |--- |--- | | ||
|asset|String|false| | ||
|status|Number|false|0 (0: pending, 1: success)| | ||
|startTime|Number|false| | ||
|endTime|Number|false| | ||
|recvWindow|Number|false| | ||
<details> | ||
<summary>Output</summary> | ||
```js | ||
{ | ||
"depositList": [ | ||
{ | ||
"insertTime": 1508198532000, | ||
"amount": 0.04670582, | ||
"asset": "ETH", | ||
"status": 1 | ||
} | ||
], | ||
"success": true | ||
} | ||
``` | ||
</details> | ||
#### withdrawHistory | ||
Get the account withdraw history. | ||
```js | ||
console.log(await client.withdrawHistory()) | ||
``` | ||
|Param|Type|Required|Description| | ||
|--- |--- |--- |--- | | ||
|asset|String|false| | ||
|status|Number|false|0 (0: Email Sent, 1: Cancelled 2: Awaiting Approval, 3: Rejected, 4: Processing, 5: Failure, 6: Completed)| | ||
|startTime|Number|false| | ||
|endTime|Number|false| | ||
|recvWindow|Number|false| | ||
<details> | ||
<summary>Output</summary> | ||
```js | ||
{ | ||
"withdrawList": [ | ||
{ | ||
"amount": 1, | ||
"address": "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b", | ||
"asset": "ETH", | ||
"applyTime": 1508198532000 | ||
"status": 4 | ||
}, | ||
], | ||
"success": true | ||
} | ||
``` | ||
</details> | ||
#### widthdraw | ||
Triggers the withdraw process (*untested for now*). | ||
```js | ||
console.log(await client.withdraw({ | ||
asset: 'ETH', | ||
address: '0xfa97c22a03d8522988c709c24283c0918a59c795', | ||
amount: 100, | ||
})) | ||
``` | ||
|Param|Type|Required|Description| | ||
|--- |--- |--- |--- | | ||
|asset|String|true| | ||
|address|String|true| | ||
|amount|Number|true| | ||
|name|String|false|Description of the address| | ||
|recvWindow|Number|false| | ||
<details> | ||
<summary>Output</summary> | ||
```js | ||
{ | ||
"msg": "success", | ||
"success": true | ||
} | ||
``` | ||
</details> | ||
#### depositAddress | ||
**Method not ready yet** | ||
Retrieve the account deposit address for a specific coin. | ||
```js | ||
console.log(await client.depositAddress({ | ||
coin: 'NEO', | ||
sameAddress: false, | ||
})) | ||
``` | ||
### WebSockets | ||
@@ -538,0 +658,0 @@ |
@@ -6,3 +6,3 @@ import crypto from 'crypto' | ||
const BASE = 'https://www.binance.com/api' | ||
const BASE = 'https://www.binance.com' | ||
@@ -59,3 +59,3 @@ /** | ||
sendResult( | ||
fetch(`${BASE}${path}${makeQueryString(data)}`, { | ||
fetch(`${BASE}/api${path}${makeQueryString(data)}`, { | ||
method, | ||
@@ -95,7 +95,12 @@ json: true, | ||
return sendResult( | ||
fetch(`${BASE}${path}${noData ? '' : makeQueryString(newData)}`, { | ||
method, | ||
headers: { 'X-MBX-APIKEY': apiKey }, | ||
json: true, | ||
}), | ||
fetch( | ||
`${BASE}${path.includes('/wapi') ? '' : '/api'}${path}${noData | ||
? '' | ||
: makeQueryString(newData)}`, | ||
{ | ||
method, | ||
headers: { 'X-MBX-APIKEY': apiKey }, | ||
json: true, | ||
}, | ||
), | ||
) | ||
@@ -199,2 +204,7 @@ } | ||
withdraw: payload => pCall('/wapi/v1/withdraw.html', payload, 'POST'), | ||
withdrawHistory: payload => pCall('/wapi/v1/getWithdrawHistory.html', payload, 'POST'), | ||
depositHistory: payload => pCall('/wapi/v1/getDepositHistory.html', payload, 'POST'), | ||
depositAddress: payload => pCall('/wapi/v1/getChargeAddress.html', payload, 'POST'), | ||
getDataStream: () => pCall('/v1/userDataStream', null, 'POST', true), | ||
@@ -201,0 +211,0 @@ keepDataStream: payload => pCall('/v1/userDataStream', payload, 'PUT', false, true), |
@@ -135,2 +135,9 @@ import WebSocket from 'ws' | ||
export const userEventHandler = cb => msg => { | ||
const { e: type, ...rest } = JSON.parse(msg) | ||
cb(userTransforms[type] ? userTransforms[type](rest) : { type, ...rest }) | ||
} | ||
export const keepStreamAlive = (method, listenKey) => () => method({ listenKey }) | ||
const user = opts => cb => { | ||
@@ -141,10 +148,6 @@ const { getDataStream, keepDataStream, closeDataStream } = httpMethods(opts) | ||
const w = new WebSocket(`${BASE}/${listenKey}`) | ||
w.on('message', msg => { | ||
const { e: type, ...rest } = JSON.parse(msg) | ||
cb(userTransforms[type] ? userTransforms[type](rest) : { type, ...rest }) | ||
}) | ||
w.on('message', userEventHandler(cb)) | ||
const int = setInterval(() => { | ||
keepDataStream({ listenKey }) | ||
}, 42e3) | ||
const int = setInterval(keepStreamAlive(keepDataStream, listenKey), 42e3) | ||
keepStreamAlive(keepDataStream, listenKey)() | ||
@@ -151,0 +154,0 @@ return () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
205162
16
1165
783
4
7