Skip to content

Commit

Permalink
replace optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ishuen committed Oct 11, 2022
1 parent 31a1b18 commit 36cc8a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/http-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,12 @@ const aggTrades = (pubCall, payload, endpoint = '/api/v3/aggTrades') =>
}),
)

// Convert the array to string to prevent unacceptable encoding
const processSymbols = payload => {
if (payload?.symbols) {
payload.symbols = `["${payload.symbols.join('"')}"]`
}
// 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 = {
Expand Down Expand Up @@ -362,7 +362,7 @@ export default opts => {
kCall('/api/v3/historicalTrades', payload),

dailyStats: payload => pubCall('/api/v3/ticker/24hr', payload),
prices: payload =>
prices: payload =>
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
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ test('[REST] individual price', async t => {
})

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

0 comments on commit 36cc8a5

Please sign in to comment.