Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,10 @@ Latest price for a symbol, not providing the symbol will return prices for all s
console.log(await client.prices())
```

| Param | Type | Required |
| ------ | ------ | -------- |
| symbol | String | false |
| Param | Type | Required |
| ------- | -------- | -------- |
| symbol | String | false |
| symbols | String[] | false |

<details>
<summary>Output</summary>
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ declare module 'binance-api-node' {
orderTest(options: NewOrderSpot): Promise<Order>
orderOco(options: NewOcoOrder): Promise<OcoOrder>
ping(): Promise<boolean>
prices(options?: { symbol?: string }): Promise<{ [index: string]: string }>
prices(options?: { symbol?: string, symbols?: string[] }): Promise<{ [index: string]: string }>
avgPrice(options?: { symbol: string }): Promise<AvgPriceResult | AvgPriceResult[]>
time(): Promise<number>
trades(options: { symbol: string; limit?: number }): Promise<TradeResult[]>
Expand Down
9 changes: 8 additions & 1 deletion src/http-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@ const aggTrades = (pubCall, payload, endpoint = '/api/v3/aggTrades') =>
}),
)

// Convert the array to string to prevent unacceptable encoding
const processSymbols = payload => {
if (payload && payload.hasOwnProperty('symbols')) {
payload.symbols = `["${payload.symbols.join('","')}"]`
}
}

export default opts => {
const endpoints = {
base: (opts && opts.httpBase) || BASE,
Expand Down Expand Up @@ -356,7 +363,7 @@ export default opts => {

dailyStats: payload => pubCall('/api/v3/ticker/24hr', payload),
prices: payload =>
pubCall('/api/v3/ticker/price', payload).then(r =>
pubCall('/api/v3/ticker/price', processSymbols(payload)).then(r =>
(Array.isArray(r) ? r : [r]).reduce((out, cur) => ((out[cur.symbol] = cur.price), out), {}),
),

Expand Down
7 changes: 7 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ test('[REST] individual price', async t => {
t.truthy(prices.ETHUSDT)
})

test('[REST] multiple prices', async t => {
const prices = await client.prices({ symbols: ['ETHUSDT', 'ETHBUSD'] })
t.truthy(prices)
t.truthy(prices.ETHUSDT)
t.truthy(prices.ETHBUSD)
})

test('[REST] avgPrice', async t => {
const res = await client.avgPrice({ symbol: 'ETHBTC' })
t.truthy(res)
Expand Down
Loading