Gathering detailed insights and metrics for okx-api-new
Gathering detailed insights and metrics for okx-api-new
Gathering detailed insights and metrics for okx-api-new
Gathering detailed insights and metrics for okx-api-new
Node.js SDK for the OKX APIs and WebSockets, with TypeScript & browser support, integration tests, beautification & more.
npm install okx-api-new
Typescript
Module System
Node Version
NPM Version
58.5
Supply Chain
68.5
Quality
72.5
Maintenance
100
Vulnerability
98.9
License
TypeScript (98.08%)
JavaScript (1.92%)
Total Downloads
1,223
Last Day
1
Last Week
2
Last Month
20
Last Year
741
MIT License
1 Stars
161 Commits
1 Forks
1 Branches
1 Contributors
Updated on Nov 06, 2024
Minified
Minified + Gzipped
Latest Version
0.0.6
Package Id
okx-api-new@0.0.6
Unpacked Size
250.29 kB
Size
55.36 kB
File Count
124
NPM Version
10.5.0
Node Version
20.12.2
Published on
May 31, 2024
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
0%
2
Compared to previous week
Last Month
-35.5%
20
Compared to previous month
Last Year
444.9%
741
Compared to previous year
3
6
5
[][1]
Node.js连接器,用于OKX APIs和WebSockets:
1npm install okx-api-new
大多数方法接受JS对象。这些可以使用okx的API文档中指定的参数进行填充,或者检查rest-client类方法中的类型定义。
Support my efforts to make algo trading accessible to all - register with my referral links:
For more ways to give thanks & support my efforts, visit Contributions & Thanks!
该项目使用TypeScript,资源存储在三个关键结构中。
基本使用实例
1 2// 实例一 3import { RestClient, OrderRequest } from 'okx-api-new'; 4const API_KEY = "生成的key" 5const API_SECRET = "生成的密钥" 6const API_PASS = "密码" 7 8const client = new RestClient({ 9 apiKey: API_KEY, 10 apiSecret: API_SECRET, 11 apiPass: API_PASS, 12}); 13 14async function main() { 15 const args = { 16 instId: "TRX-USDT-SWAP", 17 } 18 // 获取资金费率 19 const info = await client.getFundingRateHistory(args) 20 console.log(JSON.stringify(info)); 21} 22 23main() 24
1// 实例二 2import { RestClient, OrderRequest, WebsocketClient } from 'okx-api-new'; 3const API_KEY = "生成的key" 4const API_SECRET = "生成的密钥" 5const API_PASS = "密码" 6 7const client = new RestClient({ 8 apiKey: API_KEY, 9 apiSecret: API_SECRET, 10 apiPass: API_PASS, 11}); 12/* 13 * 如果需要测试的相关配置,看WebsocketClient可选项 14 * 1. 收到打开ws, 会先执行new WebsocketClient() 打印一段信息 15 * 2. 第二步 wsClient.on('open', 16 * 3. 第三步 wsClient.on('response', 17 * 4. 第四步 wsClient.on('update' 18 * 19 * 20 */ 21 22// 私有频道 23// const wsClient = new WebsocketClient( 24// { 25// accounts: [ 26// { 27// apiKey: API_KEY, 28// apiSecret: API_SECRET, 29// apiPass: API_PASS, 30// }, 31// ], 32// }, 33// ); 34 35// 共有频道 36const wsClient = new WebsocketClient({}); 37 38 39wsClient.on('update', (data) => { 40 console.log(new Date(), " 接受到的消息: ", JSON.stringify(data)); 41}); 42wsClient.on('open', (data) => { 43 console.log('ws connection opened open:', data.wsKey); 44}); 45 46wsClient.on('response', (data) => { 47 console.log('ws response received: ', JSON.stringify(data, null, 2)); 48}); 49// 尝试自动重连接 50wsClient.on('reconnect', ({ wsKey }) => { 51 console.log('ws automatically reconnecting.... ', wsKey); 52}); 53// 自动重连成功 54wsClient.on('reconnected', (data) => { 55 console.log('ws has reconnected ', data?.wsKey); 56}); 57// 报错 58wsClient.on('error', (data) => { 59 console.error('ws exception: ', data); 60}); 61 62 63// ====>>> 订阅 资金费率 64wsClient.subscribe({ 65 channel: "funding-rate", 66 instId: "BTC-USDT-SWAP" 67});
1HTTP 200 and "code" in the response body === "0"
如果返回非正常,请看APIResponse
此连接器包括用于 OKX 公共和私有 websockets 的高性能 node.js 和 typescript websocket 客户端。
ts-node examples/ws-private.ts
import { ... } from 'okx-api'
to const { ... } = require('okx-api');
ws-private.js
node examples/ws-private.js
See examples/ws-public.ts for a full example:
See examples/ws-private.ts for a full example:
This is the "modern" way, allowing the package to be directly imported into frontend projects with full typescript support.
1npm install crypto-browserify stream-browserify
tsconfig.json
1{ 2 "compilerOptions": { 3 "paths": { 4 "crypto": [ 5 "./node_modules/crypto-browserify" 6 ], 7 "stream": [ 8 "./node_modules/stream-browserify" 9 ] 10}
1(window as any).global = window;
This is the "old" way of using this package on webpages. This will build a minified js bundle that can be pulled in using a script tag on a website.
Build a bundle using webpack:
npm install
npm build
npm pack
The bundle can be found in dist/
. Altough usage should be largely consistent, smaller differences will exist. Documentation is still TODO.
No vulnerabilities found.
No security vulnerabilities found.