Skip to content

Commit ce3b5b8

Browse files
committed
feat: add multiple examples for REST and WebSocket API usage, including demo trading, private trading, and public API calls
1 parent 238025b commit ce3b5b8

File tree

12 files changed

+31
-23
lines changed

12 files changed

+31
-23
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RestClient, WebsocketClient } from '../src/index';
1+
import { RestClient, WebsocketClient } from '../../src/index.js';
22

33
// or
44
// import { RestClient} from 'okx-api';
@@ -55,7 +55,7 @@ demoWsClient.on('reconnect', ({ wsKey }) => {
5555
demoWsClient.on('reconnected', (data) => {
5656
console.log('ws has reconnected ', data?.wsKey);
5757
});
58-
demoWsClient.on('error', (data) => {
58+
demoWsClient.on('exception', (data) => {
5959
console.error('ws exception: ', data);
6060
});
6161

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RestClient, WebsocketClient } from '../src/index';
1+
import { RestClient, WebsocketClient } from '../../src/index.js';
22

33
// or
44
// import { RestClient } from 'okx-api';
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
2-
import { RestClient } from '../src/index.js';
3-
import { OrderRequest } from '../src/types/rest/request/trade.js';
2+
import { RestClient } from '../../src/index.js';
3+
import { OrderRequest } from '../../src/types/rest/request/trade.js';
44

55
// or
66
// import { SpotClient } from 'okx-api';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RestClient } from '../src/index';
1+
import { RestClient } from '../../src/index.js';
22

33
// or
44
// import { RestClient } from 'okx-api';

examples/ws-api-client.ts renamed to examples/Websocket/WS-API/ws-api-client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DefaultLogger, WebsocketAPIClient } from '../src';
1+
import { DefaultLogger, WebsocketAPIClient } from '../../../src/index.js';
22

33
// or use the module installed via `npm install okx-api`:
44
// import { WebsocketClient, DefaultLogger } from 'okx-api';
@@ -55,9 +55,9 @@ import { DefaultLogger, WebsocketAPIClient } from '../src';
5555
accounts: [
5656
// For private topics, include one or more accounts in an array. Otherwise only public topics will work
5757
{
58-
apiKey: API_KEY,
59-
apiSecret: API_SECRET,
60-
apiPass: API_PASSPHRASE,
58+
apiKey: API_KEY || '',
59+
apiSecret: API_SECRET || '',
60+
apiPass: API_PASSPHRASE || '',
6161
},
6262
],
6363
},

examples/ws-api-trade-raw.ts renamed to examples/Websocket/WS-API/ws-api-trade-raw.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// If you cloned the repo and are using typescript, you can import from src directly:
2-
import { DefaultLogger, WebsocketClient, WS_KEY_MAP } from '../src';
2+
import {
3+
DefaultLogger,
4+
WebsocketClient,
5+
WS_KEY_MAP,
6+
} from '../../../src/index.js';
37

48
// or use the module installed via `npm install okx-api`:
59
// import { WebsocketClient, DefaultLogger } from 'okx-api';
@@ -26,9 +30,9 @@ import { DefaultLogger, WebsocketClient, WS_KEY_MAP } from '../src';
2630
accounts: [
2731
// For private topics, include one or more accounts in an array. Otherwise only public topics will work
2832
{
29-
apiKey: API_KEY,
30-
apiSecret: API_SECRET,
31-
apiPass: API_PASSPHRASE,
33+
apiKey: API_KEY || '',
34+
apiSecret: API_SECRET || '',
35+
apiPass: API_PASSPHRASE || '',
3236
},
3337
],
3438
},

examples/ws-private-handle-auth-fail.ts renamed to examples/Websocket/ws-private-handle-auth-fail.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// If you cloned the repo and are using typescript, you can import from src directly:
2-
import { WebsocketClient } from '../src';
2+
import { WebsocketClient } from '../../src/index.js';
33

44
/**
55
*
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// If you cloned the repo and are using typescript, you can import from src directly:
2-
import { DefaultLogger, WebsocketClient } from '../src';
2+
import { DefaultLogger, WebsocketClient } from '../../src/index.js';
33

44
// or use the module installed via `npm install okx-api`:
55
// import { WebsocketClient, DefaultLogger } from 'okx-api';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DefaultLogger, WebsocketClient } from '../src';
1+
import { DefaultLogger, WebsocketClient } from '../../src/index.js';
22

33
// or use the module installed via `npm install okx-api`:
44
// import { WebsocketClient, DefaultLogger } from 'okx-api';

examples/app.okx.com.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RestClient, WebsocketClient } from '../src/index';
1+
import { RestClient, WebsocketClient } from '../src/index.js';
22

33
// or
44
// import { RestClient } from 'okx-api';

0 commit comments

Comments
 (0)