Gathering detailed insights and metrics for okx-v5-api
Gathering detailed insights and metrics for okx-v5-api
Gathering detailed insights and metrics for okx-v5-api
Gathering detailed insights and metrics for okx-v5-api
npm install okx-v5-api
Typescript
Module System
Node Version
NPM Version
70.3
Supply Chain
98
Quality
74.9
Maintenance
100
Vulnerability
100
License
TypeScript (93.27%)
JavaScript (6.73%)
Total Downloads
1,961
Last Day
15
Last Week
138
Last Month
207
Last Year
639
MIT License
12 Commits
2 Forks
1 Watchers
1 Branches
1 Contributors
Updated on Nov 11, 2022
Minified
Minified + Gzipped
Latest Version
2.4.1
Package Id
okx-v5-api@2.4.1
Unpacked Size
43.02 kB
Size
12.30 kB
File Count
31
NPM Version
8.19.2
Node Version
18.12.0
Published on
Sep 21, 2023
Cumulative downloads
Total Downloads
Last Day
-11.8%
15
Compared to previous day
Last Week
294.3%
138
Compared to previous week
Last Month
340.4%
207
Compared to previous month
Last Year
-33.9%
639
Compared to previous year
This is a non-official OKX V5 API SDK for javascript.
npm install okx-v5-api
main.js
1import { OkxV5Api } from 'okx-v5-api' 2 3const run = async () => { 4 const okxV5Api = new OkxV5Api({ 5 apiBaseUrl: 'https://www.okx.com', 6 /* profileConfig: { <-- only needed if you will call private APIs 7 apiKey: 'XXX', 8 secretKey: 'YYY', 9 passPhrase: 'ZZZ', 10 }, */ 11 }) 12 13 const apiResult = await okxV5Api.call({ 14 method: 'GET', 15 path: '/api/v5/market/exchange-rate', 16 }) 17 18 console.log(apiResult) 19 20 const apiResult2 = await okxV5Api.call({ 21 method: 'GET', 22 path: '/api/v5/asset/currencies?ccy=BTC,ETH,USDT,USDC', 23 }) 24 25 console.log(apiResult2) 26} 27 28run()
output
ApiResult {
code: '0',
msg: '',
data: [ { usdCny: '7.244' } ],
error: null
}
...
GET method API sample
1const apiResult = ( 2 await okxV5Api.call({ 3 method: 'GET', 4 path: '/api/v5/xxx/yyy?ccy=BTC' 5 }) 6).getOrThrow()
POST method API sample
1const apiResult = ( 2 await okxV5Api.call({ 3 method: 'POST', 4 path: '/api/v5/xxx/yyy', 5 data: { 6 param: 123 7 } 8 }) 9).getOrThrow()
By default we return an ApiResult
object to represent the raw response body.
ApiResult
object's getOrThrow
method can:
1const apiResult = ( 2 await okxV5Api.call({ 3 method: 'GET', 4 path: '/api/v5/market/exchange-rate', 5 }) 6).getOrThrow() 7 8console.log(apiResult)
output
[ { usdCny: '7.244' } ]
1const apiResult = ( 2 await okxV5Api.call({ 3 method: 'POST', 4 path: '/api/v5/account/set-position-mode', 5 data: { 6 posMode: 'net_mode', 7 }, 8 }) 9).getOrThrow()
output
...\ApiResult.js:15
this.error = new ApiError_1.ApiError(code, message);
^
ApiError: 50114: Invalid Authority
at new ApiResult (.....)
at OkxV5Api.call (.....)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async run (.....\main.js:19:25) {
code: '50114',
msg: 'Invalid Authority'
}
If you need to call private APIs, you need authentication by passing the profileConfig
property when you create new OkxV5Api
instance.
1const okxV5Api = new OkxV5Api({ 2 apiBaseUrl: 'https://www.okx.com', 3 profileConfig: { 4 apiKey: 'XXX', 5 secretKey: 'YYY', 6 passPhrase: 'ZZZ', 7 }, 8})
If you need to call private APIs, you need authentication by passing the profileConfig
property when you create new OkxV5Api
instance.
1const okxV5Api = new OkxV5Api({ 2 apiBaseUrl: 'https://www.okx.com', 3 profileConfig: { 4 apiKey: 'XXX', 5 secretKey: 'YYY', 6 passPhrase: 'ZZZ', 7 simulated: true // <--- pass this param 8 }, 9})
Basically you only need to create an instance of OkxV5Api
once, and reuse it to call different APIs by the call
methods.
The call
methods return a ApiResult
object
It is thin wrapper of the V5 API's raw response result. It has the following attributes:
In addition:
ApiError
or null)It also has a method of getOrThrow
, which return the data
if success, or throw error otherwise.
just an Error wrapping V5-API's code and message.
1export class ApiError extends Error { 2 code: string 3 msg: string 4 5 constructor(code: string, msg: string) { 6 super(`${code}: ${msg}`) 7 this.code = code 8 this.msg = msg 9 this.name = 'ApiError' 10 } 11}
No vulnerabilities found.
No security vulnerabilities found.