v3.9.9: feat() support demo trading apis
This commit is contained in:
@@ -166,6 +166,10 @@ export class RestClientV5 extends BaseRestClient {
|
||||
return this.get('/v3/public/time');
|
||||
}
|
||||
|
||||
requestDemoTradingFunds(): Promise<{}> {
|
||||
return this.postPrivate('/v5/account/demo-apply/money');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
****** Market APIs
|
||||
|
||||
@@ -88,6 +88,13 @@ export interface WSClientConfigurableOptions {
|
||||
secret?: string;
|
||||
testnet?: boolean;
|
||||
|
||||
/**
|
||||
* Set to `true` to connect to Bybit's V5 demo trading: https://bybit-exchange.github.io/docs/v5/demo
|
||||
*
|
||||
* Only the "V5" "market" is supported here.
|
||||
*/
|
||||
demoTrading?: boolean;
|
||||
|
||||
/**
|
||||
* The API group this client should connect to.
|
||||
*
|
||||
@@ -109,7 +116,6 @@ export interface WSClientConfigurableOptions {
|
||||
}
|
||||
|
||||
export interface WebsocketClientOptions extends WSClientConfigurableOptions {
|
||||
testnet?: boolean;
|
||||
market: APIMarket;
|
||||
pongTimeout: number;
|
||||
pingInterval: number;
|
||||
|
||||
@@ -13,6 +13,11 @@ export interface RestClientOptions {
|
||||
/** Set to `true` to connect to testnet. Uses the live environment by default. */
|
||||
testnet?: boolean;
|
||||
|
||||
/**
|
||||
* Set to `true` to use Bybit's V5 demo trading: https://bybit-exchange.github.io/docs/v5/demo
|
||||
*/
|
||||
demoTrading?: boolean;
|
||||
|
||||
/** Override the max size of the request window (in ms) */
|
||||
recv_window?: number;
|
||||
|
||||
@@ -92,15 +97,20 @@ export function serializeParams(
|
||||
|
||||
export function getRestBaseUrl(
|
||||
useTestnet: boolean,
|
||||
restInverseOptions: RestClientOptions,
|
||||
restClientOptions: RestClientOptions,
|
||||
): string {
|
||||
const exchangeBaseUrls = {
|
||||
livenet: 'https://api.bybit.com',
|
||||
testnet: 'https://api-testnet.bybit.com',
|
||||
demoLivenet: 'https://api-demo.bybit.com',
|
||||
};
|
||||
|
||||
if (restInverseOptions.baseUrl) {
|
||||
return restInverseOptions.baseUrl;
|
||||
if (restClientOptions.baseUrl) {
|
||||
return restClientOptions.baseUrl;
|
||||
}
|
||||
|
||||
if (restClientOptions.demoTrading) {
|
||||
return exchangeBaseUrls.demoLivenet;
|
||||
}
|
||||
|
||||
if (useTestnet) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import WebSocket from 'isomorphic-ws';
|
||||
|
||||
import { APIMarket, CategoryV5, WsKey } from '../types';
|
||||
import { APIMarket, CategoryV5, WebsocketClientOptions, WsKey } from '../types';
|
||||
import { DefaultLogger } from './logger';
|
||||
|
||||
interface NetworkMapV3 {
|
||||
@@ -398,14 +398,21 @@ export function getWsKeyForTopic(
|
||||
|
||||
export function getWsUrl(
|
||||
wsKey: WsKey,
|
||||
wsUrl: string | undefined,
|
||||
isTestnet: boolean,
|
||||
wsClientOptions: WebsocketClientOptions,
|
||||
logger: typeof DefaultLogger,
|
||||
): string {
|
||||
const wsUrl = wsClientOptions.wsUrl;
|
||||
if (wsUrl) {
|
||||
return wsUrl;
|
||||
}
|
||||
|
||||
// https://bybit-exchange.github.io/docs/v5/demo
|
||||
const isDemoTrading = wsClientOptions.demoTrading;
|
||||
if (isDemoTrading) {
|
||||
return 'wss://stream-demo.bybit.com/v5/private';
|
||||
}
|
||||
|
||||
const isTestnet = wsClientOptions.testnet;
|
||||
const networkKey = isTestnet ? 'testnet' : 'livenet';
|
||||
|
||||
switch (wsKey) {
|
||||
|
||||
@@ -623,12 +623,7 @@ export class WebsocketClient extends EventEmitter {
|
||||
}
|
||||
|
||||
const authParams = await this.getAuthParams(wsKey);
|
||||
const url = getWsUrl(
|
||||
wsKey,
|
||||
this.options.wsUrl,
|
||||
this.isTestnet(),
|
||||
this.logger,
|
||||
);
|
||||
const url = getWsUrl(wsKey, this.options, this.logger);
|
||||
const ws = this.connectToWsUrl(url + authParams, wsKey);
|
||||
|
||||
return this.wsStore.setWs(wsKey, ws);
|
||||
|
||||
Reference in New Issue
Block a user