okx-api 2.0.4 → 2.0.5

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.
Files changed (2) hide show
  1. package/README.md +42 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -104,6 +104,48 @@ Create API credentials at okx
104
104
  - If the response looks successful (HTTP 200 and "code" in the response body === "0"), only the `data` property is directly (without the `code`, `data` & `msg` properties).
105
105
  - If the response looks like an error (HTTP error OR the "code" property in the response does not equal "0"), the full response is thrown (including `code` and `msg` properties). See the interface for [APIResponse<T>](./src/types/rest/shared.ts).
106
106
 
107
+ ### Example
108
+
109
+ ```ts
110
+ import { RestClient } from 'okx-api';
111
+
112
+ const client = new RestClient({
113
+ apiKey: 'apiKeyHere',
114
+ apiSecret: 'apiSecretHere',
115
+ apiPass: 'apiPassHere',
116
+ });
117
+
118
+ // Submit a buy and sell market order
119
+ (async () => {
120
+ try {
121
+ const allBalances = await client.getBalance();
122
+ console.log('All balances: ', allBalances);
123
+
124
+ const buyResult = await client.submitOrder({
125
+ instId: 'BTC-USDT',
126
+ ordType: 'market',
127
+ side: 'buy',
128
+ sz: '0.1',
129
+ tdMode: 'cash',
130
+ tgtCcy: 'base_ccy',
131
+ });
132
+ console.log('buy order result: ', buyResult);
133
+
134
+ const sellResult = await client.submitOrder({
135
+ instId: 'BTC-USDT',
136
+ ordType: 'market',
137
+ side: 'sell',
138
+ sz: '0.1',
139
+ tdMode: 'cash',
140
+ tgtCcy: 'base_ccy',
141
+ });
142
+ console.log('Sell order result: ', sellResult);
143
+ } catch (e) {
144
+ console.error('request failed: ', e);
145
+ }
146
+ })();
147
+ ```
148
+
107
149
  ## Websocket Client
108
150
 
109
151
  This connector includes a high-performance node.js & typescript websocket client for the OKX public & private websockets.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "okx-api",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Complete & robust Node.js SDK for OKX's REST APIs and WebSockets, with TypeScript & end-to-end tests",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",