Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
depositHistory / withdrawHistory / withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
balthazar committed Nov 11, 2017
1 parent bfbac24 commit 3ffcfdb
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 7 deletions.
120 changes: 120 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -532,6 +536,122 @@ console.log(await client.myTrades({

</details>

#### 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

#### depth
Expand Down
24 changes: 17 additions & 7 deletions src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}),
Expand Down Expand Up @@ -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,
},
),
)
}

Expand Down Expand Up @@ -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),
Expand Down
22 changes: 22 additions & 0 deletions test/authenticated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 3ffcfdb

Please sign in to comment.