Comparing version 1.0.6 to 1.1.0
@@ -6,2 +6,2 @@ export interface APICredentials { | ||
} | ||
export declare type APIMarket = 'prod' | 'aws' | 'demo'; | ||
export declare type APIMarket = 'prod' | 'business' | 'businessAws' | 'aws' | 'demo' | 'businessDemo'; |
@@ -15,2 +15,5 @@ export interface WsAuthRequestArg { | ||
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'; | ||
export declare type WsBusinessPrivateChannel = 'orders-algo' | 'algo-advance' | 'deposit-info' | 'withdrawal-info' | 'grid-orders-spot' | 'grid-orders-contract' | 'grid-orders-moon' | 'grid-positions' | 'grid-sub-orders' | 'algo-recurring-buy'; | ||
export declare type WsBusinessPublicChannel = WsPublicKlineChannel | WsPublicMarkPriceKlineChannel | WsPublicIndexKlineChannel; | ||
export declare type WsBusinessChannel = WsBusinessPrivateChannel | WsBusinessPublicChannel; | ||
export declare type WsChannel = WsPublicChannel | WsPrivateChannel; | ||
@@ -17,0 +20,0 @@ export interface WsBaseRequest { |
@@ -10,5 +10,11 @@ import { APIMarket, WebsocketClientOptions, WsChannel } from '../types'; | ||
readonly demoPrivate: "demoPrivate"; | ||
readonly businessPrivate: "businessPrivate"; | ||
readonly businessPublic: "businessPublic"; | ||
readonly businessAwsPrivate: "businessAwsPrivate"; | ||
readonly businessAwsPublic: "businessAwsPublic"; | ||
readonly businessDemoPublic: "businessDemoPublic"; | ||
readonly businessDemoPrivate: "businessDemoPrivate"; | ||
}; | ||
/** This is used to differentiate between each of the available websocket streams (as bybit has multiple websockets) */ | ||
export declare type WsKey = typeof WS_KEY_MAP[keyof typeof WS_KEY_MAP]; | ||
export declare type WsKey = (typeof WS_KEY_MAP)[keyof typeof WS_KEY_MAP]; | ||
export declare const PRIVATE_WS_KEYS: WsKey[]; | ||
@@ -18,3 +24,3 @@ export declare const PUBLIC_WS_KEYS: WsKey[]; | ||
export declare function getWsKeyForTopicChannel(market: APIMarket, channel: WsChannel, isPrivate?: boolean): WsKey; | ||
export declare function getWsKeyForMarket(market: APIMarket, isPrivate: boolean): WsKey; | ||
export declare function getWsKeyForMarket(market: APIMarket, isPrivate: boolean, isBusinessChannel: boolean): WsKey; | ||
/** Maps a WS key back to a WS URL */ | ||
@@ -21,0 +27,0 @@ export declare function getWsUrlForWsKey(wsKey: WsKey, wsClientOptions: WebsocketClientOptions): string; |
@@ -14,2 +14,14 @@ "use strict"; | ||
}, | ||
business: { | ||
public: 'wss://ws.okx.com:8443/ws/v5/business', | ||
private: 'wss://ws.okx.com:8443/ws/v5/business', | ||
}, | ||
businessAws: { | ||
public: 'wss://wsaws.okx.com:8443/ws/v5/business', | ||
private: 'wss://wsaws.okx.com:8443/ws/v5/business', | ||
}, | ||
businessDemo: { | ||
public: 'wss://wspap.okx.com:8443/ws/v5/business?brokerId=9999', | ||
private: 'wss://wspap.okx.com:8443/ws/v5/business?brokerId=9999', | ||
}, | ||
demo: { | ||
@@ -27,2 +39,8 @@ public: 'wss://wspap.okx.com:8443/ws/v5/public?brokerId=9999', | ||
demoPrivate: 'demoPrivate', | ||
businessPrivate: 'businessPrivate', | ||
businessPublic: 'businessPublic', | ||
businessAwsPrivate: 'businessAwsPrivate', | ||
businessAwsPublic: 'businessAwsPublic', | ||
businessDemoPublic: 'businessDemoPublic', | ||
businessDemoPrivate: 'businessDemoPrivate', | ||
}; | ||
@@ -32,3 +50,6 @@ exports.PRIVATE_WS_KEYS = [ | ||
exports.WS_KEY_MAP.awsPrivate, | ||
exports.WS_KEY_MAP.businessPrivate, | ||
exports.WS_KEY_MAP.businessAwsPrivate, | ||
exports.WS_KEY_MAP.demoPrivate, | ||
exports.WS_KEY_MAP.businessDemoPrivate, | ||
]; | ||
@@ -38,3 +59,6 @@ exports.PUBLIC_WS_KEYS = [ | ||
exports.WS_KEY_MAP.awsPublic, | ||
exports.WS_KEY_MAP.businessPublic, | ||
exports.WS_KEY_MAP.businessAwsPublic, | ||
exports.WS_KEY_MAP.demoPublic, | ||
exports.WS_KEY_MAP.businessDemoPublic, | ||
]; | ||
@@ -57,19 +81,150 @@ /** Used to automatically determine if a sub request should be to the public or private ws (when there's two) */ | ||
]; | ||
/** | ||
* The following channels only support the new business wss endpoint: | ||
* https://www.okx.com/help-center/changes-to-v5-api-websocket-subscription-parameter-and-url | ||
*/ | ||
const BUSINESS_CHANNELS = [ | ||
'orders-algo', | ||
'algo-advance', | ||
'deposit-info', | ||
'withdrawal-info', | ||
'grid-orders-spot', | ||
'grid-orders-contract', | ||
'grid-orders-moon', | ||
'grid-positions', | ||
'grid-sub-orders', | ||
'algo-recurring-buy', | ||
'candle1Y', | ||
'candle6M', | ||
'candle3M', | ||
'candle1M', | ||
'candle1W', | ||
'candle1D', | ||
'candle2D', | ||
'candle3D', | ||
'candle5D', | ||
'candle12H', | ||
'candle6H', | ||
'candle4H', | ||
'candle2H', | ||
'candle1H', | ||
'candle30m', | ||
'candle15m', | ||
'candle5m', | ||
'candle3m', | ||
'candle1m', | ||
'candle1Yutc', | ||
'candle3Mutc', | ||
'candle1Mutc', | ||
'candle1Wutc', | ||
'candle1Dutc', | ||
'candle2Dutc', | ||
'candle3Dutc', | ||
'candle5Dutc', | ||
'candle12Hutc', | ||
'candle6Hutc', | ||
'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', | ||
'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', | ||
]; | ||
/** Determine which WsKey (ws connection) to route an event to */ | ||
function getWsKeyForTopicChannel(market, channel, isPrivate) { | ||
const isPrivateTopic = isPrivate === true || PRIVATE_CHANNELS.includes(channel); | ||
return getWsKeyForMarket(market, isPrivateTopic); | ||
const isBusinessChannel = BUSINESS_CHANNELS.includes(channel); | ||
return getWsKeyForMarket(market, isPrivateTopic, isBusinessChannel); | ||
} | ||
exports.getWsKeyForTopicChannel = getWsKeyForTopicChannel; | ||
function getWsKeyForMarket(market, isPrivate) { | ||
function getWsKeyForMarket(market, isPrivate, isBusinessChannel) { | ||
switch (market) { | ||
case 'prod': { | ||
if (isBusinessChannel) { | ||
return isPrivate | ||
? exports.WS_KEY_MAP.businessPrivate | ||
: exports.WS_KEY_MAP.businessPublic; | ||
} | ||
return isPrivate ? exports.WS_KEY_MAP.prodPrivate : exports.WS_KEY_MAP.prodPublic; | ||
} | ||
case 'aws': { | ||
if (isBusinessChannel) { | ||
return isPrivate | ||
? exports.WS_KEY_MAP.businessAwsPrivate | ||
: exports.WS_KEY_MAP.businessAwsPublic; | ||
} | ||
return isPrivate ? exports.WS_KEY_MAP.awsPrivate : exports.WS_KEY_MAP.awsPublic; | ||
} | ||
case 'demo': { | ||
if (isBusinessChannel) { | ||
return isPrivate | ||
? exports.WS_KEY_MAP.businessDemoPrivate | ||
: exports.WS_KEY_MAP.businessDemoPublic; | ||
} | ||
return isPrivate ? exports.WS_KEY_MAP.demoPrivate : exports.WS_KEY_MAP.demoPublic; | ||
} | ||
case 'business': { | ||
return isPrivate ? exports.WS_KEY_MAP.businessPrivate : exports.WS_KEY_MAP.businessPublic; | ||
} | ||
case 'businessAws': { | ||
return isPrivate | ||
? exports.WS_KEY_MAP.businessAwsPrivate | ||
: exports.WS_KEY_MAP.businessAwsPublic; | ||
} | ||
case 'businessDemo': { | ||
return isPrivate | ||
? exports.WS_KEY_MAP.businessDemoPrivate | ||
: exports.WS_KEY_MAP.businessDemoPublic; | ||
} | ||
default: { | ||
@@ -99,2 +254,14 @@ throw (0, typeGuards_1.neverGuard)(market, `getWsKeyForTopic(): Unhandled market`); | ||
return exports.WS_BASE_URL_MAP.demo.private; | ||
case 'businessPublic': | ||
return exports.WS_BASE_URL_MAP.business.public; | ||
case 'businessPrivate': | ||
return exports.WS_BASE_URL_MAP.business.private; | ||
case 'businessAwsPublic': | ||
return exports.WS_BASE_URL_MAP.businessAws.public; | ||
case 'businessAwsPrivate': | ||
return exports.WS_BASE_URL_MAP.businessAws.private; | ||
case 'businessDemoPublic': | ||
return exports.WS_BASE_URL_MAP.businessDemo.public; | ||
case 'businessDemoPrivate': | ||
return exports.WS_BASE_URL_MAP.businessDemo.private; | ||
default: { | ||
@@ -115,3 +282,6 @@ const errorMessage = 'getWsUrl(): Unhandled wsKey: '; | ||
case 'aws': | ||
case 'demo': { | ||
case 'demo': | ||
case 'business': | ||
case 'businessDemo': | ||
case 'businessAws': { | ||
return null; | ||
@@ -118,0 +288,0 @@ } |
@@ -64,4 +64,4 @@ /// <reference types="node" /> | ||
connectAll(): Promise<WebSocket | undefined>[]; | ||
connectPublic(): Promise<WebSocket | undefined>; | ||
connectPrivate(): Promise<WebSocket | undefined>; | ||
connectPublic(businessEndpoint?: boolean): Promise<WebSocket | undefined>; | ||
connectPrivate(businessEndpoint?: boolean): Promise<WebSocket | undefined>; | ||
private connect; | ||
@@ -68,0 +68,0 @@ private parseWsError; |
@@ -97,10 +97,10 @@ "use strict"; | ||
} | ||
connectPublic() { | ||
connectPublic(businessEndpoint) { | ||
const isPrivate = false; | ||
const wsKey = (0, websocket_util_1.getWsKeyForMarket)(this.options.market, isPrivate); | ||
const wsKey = (0, websocket_util_1.getWsKeyForMarket)(this.options.market, isPrivate, !!businessEndpoint); | ||
return this.connect(util_1.WS_KEY_MAP[wsKey]); | ||
} | ||
connectPrivate() { | ||
connectPrivate(businessEndpoint) { | ||
const isPrivate = true; | ||
const wsKey = (0, websocket_util_1.getWsKeyForMarket)(this.options.market, isPrivate); | ||
const wsKey = (0, websocket_util_1.getWsKeyForMarket)(this.options.market, isPrivate, !!businessEndpoint); | ||
return this.connect(util_1.WS_KEY_MAP[wsKey]); | ||
@@ -107,0 +107,0 @@ } |
{ | ||
"name": "okx-api", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"description": "Complete & robust Node.js SDK for OKX's REST APIs and WebSockets, with TypeScript & end-to-end tests.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
244080
4514