You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -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 =newRestClient({
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 =awaitclient.getBalance();
122
+
console.log('All balances: ', allBalances);
123
+
124
+
const buyResult =awaitclient.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 =awaitclient.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.
0 commit comments