public usdc perp ws test
This commit is contained in:
@@ -3,13 +3,15 @@ import { LinearClient } from '../linear-client';
|
||||
import { SpotClient } from '../spot-client';
|
||||
import { SpotClientV3 } from '../spot-client-v3';
|
||||
import { USDCOptionClient } from '../usdc-option-client';
|
||||
import { USDCPerpetualClient } from '../usdc-perpetual-client';
|
||||
|
||||
export type RESTClient =
|
||||
| InverseClient
|
||||
| LinearClient
|
||||
| SpotClient
|
||||
| SpotClientV3
|
||||
| USDCOptionClient;
|
||||
| USDCOptionClient
|
||||
| USDCPerpetualClient;
|
||||
|
||||
export type numberInString = string;
|
||||
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { RestClientOptions, WS_KEY_MAP } from '../util';
|
||||
|
||||
/** For spot markets, spotV3 is recommended */
|
||||
export type APIMarket = 'inverse' | 'linear' | 'spot' | 'spotv3' | 'usdcOption';
|
||||
export type APIMarket =
|
||||
| 'inverse'
|
||||
| 'linear'
|
||||
| 'spot'
|
||||
| 'spotv3'
|
||||
| 'usdcOption'
|
||||
| 'usdcPerp';
|
||||
|
||||
// Same as inverse futures
|
||||
export type WsPublicInverseTopic =
|
||||
|
||||
@@ -69,6 +69,18 @@ export const WS_BASE_URL_MAP: Record<
|
||||
testnet: 'wss://stream-testnet.bybit.com/trade/option/usdc/private/v1',
|
||||
},
|
||||
},
|
||||
usdcPerp: {
|
||||
public: {
|
||||
livenet: 'wss://stream.bybit.com/perpetual/ws/v1/realtime_public',
|
||||
livenet2: 'wss://stream.bytick.com/perpetual/ws/v1/realtime_public',
|
||||
testnet: 'wss://stream-testnet.bybit.com/perpetual/ws/v1/realtime_public',
|
||||
},
|
||||
private: {
|
||||
livenet: 'wss://stream.bybit.com/trade/option/usdc/private/v1',
|
||||
livenet2: 'wss://stream.bytick.com/trade/option/usdc/private/v1',
|
||||
testnet: 'wss://stream-testnet.bybit.com/trade/option/usdc/private/v1',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const WS_KEY_MAP = {
|
||||
@@ -81,8 +93,8 @@ export const WS_KEY_MAP = {
|
||||
spotV3Public: 'spotV3Public',
|
||||
usdcOptionPrivate: 'usdcOptionPrivate',
|
||||
usdcOptionPublic: 'usdcOptionPublic',
|
||||
// usdcPerpPrivate: 'usdcPerpPrivate',
|
||||
// usdcPerpPublic: 'usdcPerpPublic',
|
||||
usdcPerpPrivate: 'usdcPerpPrivate',
|
||||
usdcPerpPublic: 'usdcPerpPublic',
|
||||
} as const;
|
||||
|
||||
export const WS_AUTH_ON_CONNECT_KEYS: WsKey[] = [WS_KEY_MAP.spotV3Private];
|
||||
@@ -92,6 +104,7 @@ export const PUBLIC_WS_KEYS = [
|
||||
WS_KEY_MAP.spotPublic,
|
||||
WS_KEY_MAP.spotV3Public,
|
||||
WS_KEY_MAP.usdcOptionPublic,
|
||||
WS_KEY_MAP.usdcPerpPublic,
|
||||
] as string[];
|
||||
|
||||
/** Used to automatically determine if a sub request should be to the public or private ws (when there's two) */
|
||||
@@ -158,6 +171,11 @@ export function getWsKeyForTopic(
|
||||
? WS_KEY_MAP.usdcOptionPrivate
|
||||
: WS_KEY_MAP.usdcOptionPublic;
|
||||
}
|
||||
case 'usdcPerp': {
|
||||
return isPrivateTopic
|
||||
? WS_KEY_MAP.usdcPerpPrivate
|
||||
: WS_KEY_MAP.usdcPerpPublic;
|
||||
}
|
||||
default: {
|
||||
throw neverGuard(market, `getWsKeyForTopic(): Unhandled market`);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
neverGuard,
|
||||
} from './util';
|
||||
import { USDCOptionClient } from './usdc-option-client';
|
||||
import { USDCPerpetualClient } from './usdc-perpetual-client';
|
||||
|
||||
const loggerCategory = { category: 'bybit-ws' };
|
||||
|
||||
@@ -165,6 +166,17 @@ export class WebsocketClient extends EventEmitter {
|
||||
this.connectPublic();
|
||||
break;
|
||||
}
|
||||
case 'usdcPerp': {
|
||||
this.restClient = new USDCPerpetualClient(
|
||||
undefined,
|
||||
undefined,
|
||||
!this.isTestnet(),
|
||||
this.options.restOptions,
|
||||
this.options.requestOptions
|
||||
);
|
||||
this.connectPublic();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw neverGuard(
|
||||
this.options.market,
|
||||
@@ -223,7 +235,8 @@ export class WebsocketClient extends EventEmitter {
|
||||
case 'linear':
|
||||
case 'spot':
|
||||
case 'spotv3':
|
||||
case 'usdcOption': {
|
||||
case 'usdcOption':
|
||||
case 'usdcPerp': {
|
||||
return [this.connectPublic(), this.connectPrivate()];
|
||||
}
|
||||
default: {
|
||||
@@ -249,6 +262,9 @@ export class WebsocketClient extends EventEmitter {
|
||||
case 'usdcOption': {
|
||||
return this.connect(WS_KEY_MAP.usdcOptionPublic);
|
||||
}
|
||||
case 'usdcPerp': {
|
||||
return this.connect(WS_KEY_MAP.usdcPerpPublic);
|
||||
}
|
||||
default: {
|
||||
throw neverGuard(
|
||||
this.options.market,
|
||||
@@ -275,6 +291,9 @@ export class WebsocketClient extends EventEmitter {
|
||||
case 'usdcOption': {
|
||||
return this.connect(WS_KEY_MAP.usdcOptionPrivate);
|
||||
}
|
||||
case 'usdcPerp': {
|
||||
return this.connect(WS_KEY_MAP.usdcPerpPrivate);
|
||||
}
|
||||
default: {
|
||||
throw neverGuard(
|
||||
this.options.market,
|
||||
@@ -719,12 +738,12 @@ export class WebsocketClient extends EventEmitter {
|
||||
case WS_KEY_MAP.usdcOptionPrivate: {
|
||||
return WS_BASE_URL_MAP.usdcOption.private[networkKey];
|
||||
}
|
||||
// case WS_KEY_MAP.usdcPerpPublic: {
|
||||
// return WS_BASE_URL_MAP.usdcOption.public[networkKey];
|
||||
// }
|
||||
// case WS_KEY_MAP.usdcPerpPrivate: {
|
||||
// return WS_BASE_URL_MAP.usdcOption.private[networkKey];
|
||||
// }
|
||||
case WS_KEY_MAP.usdcPerpPublic: {
|
||||
return WS_BASE_URL_MAP.usdcPerp.public[networkKey];
|
||||
}
|
||||
case WS_KEY_MAP.usdcPerpPrivate: {
|
||||
return WS_BASE_URL_MAP.usdcPerp.private[networkKey];
|
||||
}
|
||||
default: {
|
||||
this.logger.error('getWsUrl(): Unhandled wsKey: ', {
|
||||
...loggerCategory,
|
||||
|
||||
Reference in New Issue
Block a user