okx-api 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
# Node.js & Typescript OKX (OKEX) API SDK
|
|
1
|
+
# Node.js & Typescript OKX (OKEX) API & WebSocket SDK
|
|
2
|
+
|
|
2
3
|
[](https://github.com/tiagosiebler/okx-api/actions/workflows/e2etest.yml) [][1] [][1] [][1] [][1] [](https://www.codefactor.io/repository/github/tiagosiebler/okx-api)
|
|
3
4
|
|
|
4
5
|
[][1]
|
|
5
6
|
|
|
6
7
|
[1]: https://www.npmjs.com/package/okx-api
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
Complete, updated & performant node.js SDK for the OKX(OKEX) APIs and WebSockets:
|
|
10
|
+
|
|
11
|
+
- Complete integration with all OKX APIs, including the v5 APIs.
|
|
10
12
|
- TypeScript support (with type declarations for most API requests & responses).
|
|
11
13
|
- Over 100 end-to-end tests making real API calls & WebSocket connections, validating any changes before they reach npm.
|
|
12
14
|
- Robust WebSocket integration
|
|
@@ -16,15 +18,18 @@ Node.js connector for the OKX APIs and WebSockets:
|
|
|
16
18
|
- Browser support (via webpack bundle - see "Browser Usage" below).
|
|
17
19
|
|
|
18
20
|
## Installation
|
|
21
|
+
|
|
19
22
|
```bash
|
|
20
23
|
npm install okx-api
|
|
21
24
|
```
|
|
22
25
|
|
|
23
26
|
## Issues & Discussion
|
|
27
|
+
|
|
24
28
|
- Issues? Check the [issues tab](https://github.com/tiagosiebler/okx-api/issues).
|
|
25
29
|
- Discuss & collaborate with other node devs? Join our [Node.js Algo Traders](https://t.me/nodetraders) engineering community on telegram.
|
|
26
30
|
|
|
27
31
|
## Related projects
|
|
32
|
+
|
|
28
33
|
- Try my connectors:
|
|
29
34
|
- [binance](https://www.npmjs.com/package/binance)
|
|
30
35
|
- [bybit-api](https://www.npmjs.com/package/bybit-api)
|
|
@@ -37,12 +42,16 @@ npm install okx-api
|
|
|
37
42
|
- [awesome-crypto-examples](https://github.com/tiagosiebler/awesome-crypto-examples)
|
|
38
43
|
|
|
39
44
|
## Documentation
|
|
45
|
+
|
|
40
46
|
Most methods accept JS objects. These can be populated using parameters specified by okx's API documentation, or check the type definition in the rest-client class methods.
|
|
47
|
+
|
|
41
48
|
- [RestClient](src/rest-client.ts).
|
|
42
49
|
- [OKX API Documentation](https://www.okx.com/docs-v5/en/#rest-api).
|
|
43
50
|
|
|
44
51
|
## Structure
|
|
52
|
+
|
|
45
53
|
This project uses typescript. Resources are stored in 3 key structures:
|
|
54
|
+
|
|
46
55
|
- [src](./src) - the whole connector written in typescript
|
|
47
56
|
- [lib](./lib) - the javascript version of the project (compiled from typescript). This should not be edited directly, as it will be overwritten with each release. This is also the version published to npm.
|
|
48
57
|
- [dist](./dist) - the packed bundle of the project for use in browser environments (manual, using webpack).
|
|
@@ -51,12 +60,15 @@ This project uses typescript. Resources are stored in 3 key structures:
|
|
|
51
60
|
---
|
|
52
61
|
|
|
53
62
|
# Usage
|
|
63
|
+
|
|
54
64
|
Create API credentials at okx
|
|
65
|
+
|
|
55
66
|
- [OKX my-api](https://www.okx.com/account/my-api)
|
|
56
67
|
|
|
57
68
|
## REST Client
|
|
58
69
|
|
|
59
70
|
### Requests & Responses
|
|
71
|
+
|
|
60
72
|
- If your IDE doesn't have IntelliSense, check the [rest-client.ts](./src/rest-client.ts) for a list of methods, params & return types.
|
|
61
73
|
- Requests follow the same ordering and format as the categories in the [API docs](https://www.okx.com/docs-v5/en/#rest-api).
|
|
62
74
|
- Responses are parsed automatically for less nesting. Error responses are thrown in full:
|
|
@@ -70,7 +82,7 @@ This connector includes a high-performance node.js & typescript websocket client
|
|
|
70
82
|
- If your IDE doesn't have IntelliSense, check the [websocket-client.ts](./src/websocket-client.ts) for a list of methods, params & return types.
|
|
71
83
|
- When subscribing to channels, only the "args" should be passed as an object or array when calling the websocket client subcribe() function: [API docs](https://www.okx.com/docs-v5/en/#websocket-api-subscribe).
|
|
72
84
|
- TypeScript recommended (but it is not required) for a richer experience:
|
|
73
|
-

|
|
85
|
+

|
|
74
86
|
- The ws client will automatically open connections as needed when subscribing to a channel.
|
|
75
87
|
- If the connection is lost for any reason, the ws client will detect this (via the connection heartbeats). It will then:
|
|
76
88
|
- Automatically teardown the dead connection.
|
|
@@ -91,17 +103,21 @@ This connector includes a high-performance node.js & typescript websocket client
|
|
|
91
103
|
- And execute with node: `node examples/ws-private.js`
|
|
92
104
|
|
|
93
105
|
### Public Events
|
|
106
|
+
|
|
94
107
|
See [examples/ws-public.ts](./examples/ws-public.ts) for a full example:
|
|
95
108
|
|
|
96
109
|

|
|
97
110
|
|
|
98
111
|
### Private Events
|
|
112
|
+
|
|
99
113
|
See [examples/ws-private.ts](./examples/ws-private.ts) for a full example:
|
|
100
114
|
|
|
101
115
|

|
|
102
116
|
|
|
103
117
|
## Browser Usage
|
|
118
|
+
|
|
104
119
|
Build a bundle using webpack:
|
|
120
|
+
|
|
105
121
|
- `npm install`
|
|
106
122
|
- `npm build`
|
|
107
123
|
- `npm pack`
|
|
@@ -111,20 +127,26 @@ The bundle can be found in `dist/`. Altough usage should be largely consistent,
|
|
|
111
127
|
---
|
|
112
128
|
|
|
113
129
|
## Contributions & Thanks
|
|
130
|
+
|
|
114
131
|
### Donations
|
|
132
|
+
|
|
115
133
|
#### tiagosiebler
|
|
134
|
+
|
|
116
135
|
Support my efforts to make algo trading accessible to all - register with my referral links:
|
|
136
|
+
|
|
117
137
|
- [Bybit](https://www.bybit.com/en-US/register?affiliate_id=9410&language=en-US&group_id=0&group_type=1)
|
|
118
138
|
- [Binance](https://www.binance.com/en/register?ref=20983262)
|
|
119
139
|
- [OKX](https://www.okx.com/join/18504944)
|
|
120
140
|
|
|
121
141
|
Or buy me a coffee using any of these:
|
|
142
|
+
|
|
122
143
|
- BTC: `1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk`
|
|
123
144
|
- ETH (ERC20): `0xd773d8e6a50758e1ada699bb6c4f98bb4abf82da`
|
|
124
145
|
|
|
125
146
|
### Contributions & Pull Requests
|
|
147
|
+
|
|
126
148
|
Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.
|
|
127
149
|
|
|
128
150
|
## Star History
|
|
129
151
|
|
|
130
|
-
[](https://star-history.com/#tiagosiebler/bybit-api&tiagosiebler/binance&tiagosiebler/orderbooks&tiagosiebler/okx-api&tiagosiebler/bitget-api&tiagosiebler/awesome-crypto-examples&tiagosiebler/ftx-api&Date)
|
|
@@ -11,7 +11,7 @@ export declare type WsPublicKlineChannel = 'candle1Y' | 'candle6M' | 'candle3M'
|
|
|
11
11
|
export declare type WsPublicMarkPriceKlineChannel = 'mark-price-candle1Y' | 'mark-price-candle6M' | 'mark-price-candle3M' | 'mark-price-candle1M' | 'mark-price-candle1W' | 'mark-price-candle1D' | 'mark-price-candle2D' | 'mark-price-candle3D' | 'mark-price-candle5D' | 'mark-price-candle12H' | 'mark-price-candle6H' | 'mark-price-candle4H' | 'mark-price-candle2H' | 'mark-price-candle1H' | 'mark-price-candle30m' | 'mark-price-candle15m' | 'mark-price-candle5m' | 'mark-price-candle3m' | 'mark-price-candle1m' | 'mark-price-candle1Yutc' | 'mark-price-candle3Mutc' | 'mark-price-candle1Mutc' | 'mark-price-candle1Wutc' | 'mark-price-candle1Dutc' | 'mark-price-candle2Dutc' | 'mark-price-candle3Dutc' | 'mark-price-candle5Dutc' | 'mark-price-candle12Hutc' | 'mark-price-candle6Hutc';
|
|
12
12
|
export declare type WsPublicIndexKlineChannel = 'index-candle1Y' | 'index-candle6M' | 'index-candle3M' | 'index-candle1M' | 'index-candle1W' | 'index-candle1D' | 'index-candle2D' | 'index-candle3D' | 'index-candle5D' | 'index-candle12H' | 'index-candle6H' | 'index-candle4H index -candle2H' | 'index-candle1H' | 'index-candle30m' | 'index-candle15m' | 'index-candle5m' | 'index-candle3m' | 'index-candle1m' | 'index-candle1Yutc' | 'index-candle3Mutc' | 'index-candle1Mutc' | 'index-candle1Wutc' | 'index-candle1Dutc' | 'index-candle2Dutc' | 'index-candle3Dutc' | 'index-candle5Dutc' | 'index-candle12Hutc' | 'index-candle6Hutc';
|
|
13
13
|
export declare type WsPublicOrderBooksChannel = 'books' | 'books5' | 'bbo-tbt' | 'books-l2-tbt' | 'books50-l2-tpt';
|
|
14
|
-
export declare type WsPublicChannel = 'instruments' | 'tickers' | 'open-interest' | WsPublicKlineChannel | WsPublicMarkPriceKlineChannel | WsPublicIndexKlineChannel | 'trades' | 'estimated-price' | 'mark-price' | 'price-limit' | WsPublicOrderBooksChannel | 'opt-summary' | 'funding-rate' | 'index-tickers' | 'status';
|
|
14
|
+
export declare type WsPublicChannel = 'instruments' | 'tickers' | 'open-interest' | WsPublicKlineChannel | WsPublicMarkPriceKlineChannel | WsPublicIndexKlineChannel | 'trades' | 'estimated-price' | 'mark-price' | 'price-limit' | WsPublicOrderBooksChannel | 'opt-summary' | 'funding-rate' | 'index-tickers' | 'status' | 'liquidation-orders';
|
|
15
15
|
export declare type WsChannel = WsPublicChannel | WsPrivateChannel;
|
|
16
16
|
export interface WsBaseRequest {
|
|
17
17
|
op: WsRequestOp;
|
|
@@ -88,7 +88,11 @@ export interface WsPublicChannelArgOptionSummary extends WsBaseRequestArg {
|
|
|
88
88
|
export interface WsPublicChannelArgStatus extends WsBaseRequestArg {
|
|
89
89
|
channel: 'status';
|
|
90
90
|
}
|
|
91
|
-
export
|
|
91
|
+
export interface WsPublicChannelArgLiquidationOrders extends WsBaseRequestArg {
|
|
92
|
+
channel: 'liquidation-orders';
|
|
93
|
+
instType: 'SWAP' | 'FUTURES';
|
|
94
|
+
}
|
|
95
|
+
export declare type WsChannelSubUnSubRequestArg = WsPrivateChannelArgTickers | WsPrivateChannelArgWithCcy | WsPrivateChannelArgWithInstFamily | WsPrivateChannelArgAlgo | WsPrivateChannelArgBalanceAndPosition | WsPrivateChannelArgGridOrders | WsPrivateChannelArgGridOther | WsPublicChannelArgInstType | WsPublicChannelArgInstId | WsPublicChannelArgInstIdOrFamily | WsPublicChannelArgOptionSummary | WsPublicChannelArgStatus | WsPublicChannelArgLiquidationOrders;
|
|
92
96
|
/**
|
|
93
97
|
*
|
|
94
98
|
* Top level requests with args
|