diff --git a/README.md b/README.md index 83aefcf3..34d02630 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,10 @@ Following examples will use the `await` form, but that's totally up to you. - [allOrders](#allorders) - [accountInfo](#accountinfo) - [myTrades](#mytrades) + - [depositHistory](#deposithistory) + - [withdrawHistory](#withdrawhistory) + - [widthdraw](#withdraw) + - [depositAddress](#depositaddress) - [Websockets](#websockets) - [depth](#depth) - [candles](#candles-1) @@ -532,6 +536,122 @@ console.log(await client.myTrades({ +#### 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| + +
+Output + +```js +{ + "depositList": [ + { + "insertTime": 1508198532000, + "amount": 0.04670582, + "asset": "ETH", + "status": 1 + } + ], + "success": true +} +``` + +
+ +#### 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| + +
+Output + +```js +{ + "withdrawList": [ + { + "amount": 1, + "address": "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b", + "asset": "ETH", + "applyTime": 1508198532000 + "status": 4 + }, + ], + "success": true +} +``` + +
+ +#### 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| + +
+Output + +```js +{ + "msg": "success", + "success": true +} +``` + +
+ +#### 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 #### depth diff --git a/src/http.js b/src/http.js index 0e10a38f..1f0d661c 100644 --- a/src/http.js +++ b/src/http.js @@ -3,7 +3,7 @@ import zip from 'lodash.zipobject' import 'isomorphic-fetch' -const BASE = 'https://www.binance.com/api' +const BASE = 'https://www.binance.com' /** * Build query string for uri encoded url based on json object @@ -55,7 +55,7 @@ const checkParams = (name, payload, requires = []) => { */ const publicCall = (path, data, method = 'GET') => sendResult( - fetch(`${BASE}${path}${makeQueryString(data)}`, { + fetch(`${BASE}/api${path}${makeQueryString(data)}`, { method, json: true, }), @@ -90,11 +90,16 @@ const privateCall = ({ apiKey, apiSecret }) => ( const newData = noExtra ? data : { ...data, timestamp, signature } 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, + }, + ), ) } @@ -193,6 +198,11 @@ export default opts => { accountInfo: payload => pCall('/v3/account', payload), myTrades: payload => pCall('/v3/myTrades', payload), + 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), keepDataStream: payload => pCall('/v1/userDataStream', payload, 'PUT', false, true), closeDataStream: payload => pCall('/v1/userDataStream', payload, 'DELETE', false, true), diff --git a/test/authenticated.js b/test/authenticated.js index 2f13a481..d31a3cec 100644 --- a/test/authenticated.js +++ b/test/authenticated.js @@ -87,6 +87,28 @@ test.serial('[REST] accountInfo', async t => { t.truthy(account.balances.length) }) +test.serial('[REST] depositHistory', async t => { + const history = await client.depositHistory() + t.true(history.success) + t.truthy(history.depositList.length) +}) + +test.serial('[REST] withdrawHistory', async t => { + const history = await client.withdrawHistory() + t.true(history.success) + t.truthy(history.withdrawList.length) +}) + +// test.only('[REST] depositAddress', async t => { +// const out = await client.depositAddress({ +// coin: 'NEO', +// sameAddress: false, +// }) + +// console.log(out) +// t.true(out) +// }) + test.serial('[REST] myTrades', async t => { const trades = await client.myTrades({ symbol: 'ENGETH' }) t.true(Array.isArray(trades))