Skip to content

Commit 847cfdd

Browse files
committed
feat: add support for OPENAPI_GLOBAL market
- Updated WebsocketClient to handle OPENAPI_GLOBAL market. - Enhanced documentation to include OPENAPI_GLOBAL in APIMarket and RestClientOptions. - Added OPENAPI_GLOBAL base URL and WebSocket configurations. - Ensured compatibility with existing GLOBAL market functionality.
1 parent 3538e17 commit 847cfdd

6 files changed

Lines changed: 32 additions & 7 deletions

File tree

src/types/rest/client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export interface RestClientOptions {
77

88
/**
99
* The API group this client should connect to:
10-
* - market: 'prod' (default: OKX Global REST at https://openapi.okx.com)
10+
* - market: 'prod' (default: connects to OKX global) https://www.okx.com/docs-v5/en/#overview-production-trading-services
11+
* - market: 'OPENAPI_GLOBAL' // OKX Global REST at https://openapi.okx.com
1112
* - market: 'EEA' // also known as "my.okx.com" https://my.okx.com/docs-v5/en/#overview-production-trading-services
1213
* - market: 'US' // also known as "app.okx.com" https://app.okx.com/docs-v5/en/#overview-production-trading-services
1314
*/

src/types/shared.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ export interface APICredentials {
55
}
66

77
/**
8-
* The API Market represents the OKX Domain that you have signed up for. At this time, there are 3 supported domain groups:
8+
* The API Market represents the OKX Domain that you have signed up for. At this time, there are 4 supported domain groups:
99
*
10-
* - GLOBAL, OKX Global (REST: openapi.okx.com; www.okx.com also works).
10+
* - GLOBAL, otherwise known as "www.okx.com".
11+
* - OPENAPI_GLOBAL, OKX Global REST at openapi.okx.com (same WS as GLOBAL).
1112
* - EEA, otherwise known as "my.okx.com".
1213
* - US, otherwise known as "app.okx.com".
1314
*/
1415
export type APIMarket =
1516
| 'prod' // same as GLOBAL. Kept for some backwards compatibility
16-
// OKX Global REST: https://openapi.okx.com (recommended). www.okx.com remains supported.
17+
// also known as "www.okx.com" or OKX Global: https://www.okx.com/docs-v5/en/#overview-production-trading-services
1718
| 'GLOBAL'
19+
// OKX Global REST at https://openapi.okx.com. WebSocket URLs unchanged (same as GLOBAL).
20+
| 'OPENAPI_GLOBAL'
1821
// also known as "my.okx.com" https://my.okx.com/docs-v5/en/#overview-production-trading-services
1922
| 'EEA'
2023
// also known as "app.okx.com" https://app.okx.com/docs-v5/en/#overview-production-trading-services

src/types/websockets/ws-general.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface WSClientConfigurableOptions {
1010
/**
1111
* The API group this client should connect to:
1212
* - market: 'prod' (default: connects to OKX global) https://www.okx.com/docs-v5/en/#overview-production-trading-services
13+
* - market: 'OPENAPI_GLOBAL' // OKX Global REST at https://openapi.okx.com (WS same as GLOBAL)
1314
* - market: 'EEA' // also known as "my.okx.com" https://my.okx.com/docs-v5/en/#overview-production-trading-services
1415
* - market: 'US' // also known as "app.okx.com" https://app.okx.com/docs-v5/en/#overview-production-trading-services
1516
*/

src/util/requestUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ export function getRestBaseUrl(
4444

4545
switch (market) {
4646
default:
47-
// "prod" defaults to OKX Global REST API: https://openapi.okx.com (www.okx.com remains supported)
47+
// "prod" defaults to OKX Global: https://www.okx.com/docs-v5/en/#overview-production-trading-services
4848
case 'GLOBAL':
4949
case 'prod': {
50+
return 'https://www.okx.com';
51+
}
52+
case 'OPENAPI_GLOBAL': {
5053
return 'https://openapi.okx.com';
5154
}
5255
// also known as "my.okx.com" https://my.okx.com/docs-v5/en/#overview-production-trading-services

src/util/websocket-util.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ export const WS_BASE_URL_MAP: Record<
4444
business: 'wss://wspap.okx.com:8443/ws/v5/business?brokerId=9999',
4545
},
4646
},
47+
// OKX Global REST at openapi.okx.com. WebSocket URLs unchanged (same as GLOBAL).
48+
OPENAPI_GLOBAL: {
49+
live: {
50+
public: 'wss://ws.okx.com:8443/ws/v5/public',
51+
private: 'wss://ws.okx.com:8443/ws/v5/private',
52+
// Some channels require business suffix: https://www.okx.com/help/changes-to-v5-api-websocket-subscription-parameter-and-url
53+
business: 'wss://ws.okx.com:8443/ws/v5/business',
54+
},
55+
demo: {
56+
public: 'wss://wspap.okx.com:8443/ws/v5/public',
57+
private: 'wss://wspap.okx.com:8443/ws/v5/private',
58+
business: 'wss://wspap.okx.com:8443/ws/v5/business?brokerId=9999',
59+
},
60+
},
4761
// also known as "my.okx.com" https://my.okx.com/docs-v5/en/#overview-production-trading-services
4862
EEA: {
4963
live: {
@@ -367,7 +381,8 @@ export function getWsKeyForMarket(
367381
): WsKey {
368382
switch (market) {
369383
case 'prod':
370-
case 'GLOBAL': {
384+
case 'GLOBAL':
385+
case 'OPENAPI_GLOBAL': {
371386
if (isBusinessChannel) {
372387
return WS_KEY_MAP.prodBusiness;
373388
}
@@ -503,6 +518,7 @@ export function getMaxTopicsPerSubscribeEventForMarket(
503518
case 'prod':
504519
case 'EEA':
505520
case 'GLOBAL':
521+
case 'OPENAPI_GLOBAL':
506522
case 'US': {
507523
return null;
508524
}

src/websocket-client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ export class WebsocketClient extends BaseWebsocketClient<
253253
switch (this.options.market) {
254254
case undefined:
255255
case 'prod':
256-
case 'GLOBAL': {
256+
case 'GLOBAL':
257+
case 'OPENAPI_GLOBAL': {
257258
return isPrivateType
258259
? WS_KEY_MAP.prodPrivate
259260
: isBusinessType

0 commit comments

Comments
 (0)