Merge pull request #3 from tiagosiebler/linearCleaning
move script commands around. Move shared endpoint down.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { AxiosRequestConfig } from 'axios';
|
||||
import { GenericAPIResponse, getBaseRESTInverseUrl, RestClientInverseOptions } from './util/requestUtils';
|
||||
import { GenericAPIResponse, getRestBaseUrl, RestClientOptions } from './util/requestUtils';
|
||||
import RequestWrapper from './util/requestWrapper';
|
||||
import SharedEndpoints from './shared-endpoints';
|
||||
|
||||
@@ -12,23 +12,23 @@ export class InverseClient extends SharedEndpoints {
|
||||
* @param {string} key - your API key
|
||||
* @param {string} secret - your API secret
|
||||
* @param {boolean} [useLivenet=false]
|
||||
* @param {RestClientInverseOptions} [restInverseOptions={}] options to configure REST API connectivity
|
||||
* @param {RestClientOptions} [restInverseOptions={}] options to configure REST API connectivity
|
||||
* @param {AxiosRequestConfig} [requestOptions={}] HTTP networking options for axios
|
||||
*/
|
||||
constructor(
|
||||
key?: string | undefined,
|
||||
secret?: string | undefined,
|
||||
useLivenet?: boolean,
|
||||
restInverseOptions: RestClientInverseOptions = {},
|
||||
httpOptions: AxiosRequestConfig = {}
|
||||
restInverseOptions: RestClientOptions = {},
|
||||
requestOptions: AxiosRequestConfig = {}
|
||||
) {
|
||||
super()
|
||||
this.requestWrapper = new RequestWrapper(
|
||||
key,
|
||||
secret,
|
||||
getBaseRESTInverseUrl(useLivenet),
|
||||
getRestBaseUrl(useLivenet),
|
||||
restInverseOptions,
|
||||
httpOptions
|
||||
requestOptions
|
||||
);
|
||||
return this;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ export class InverseClient extends SharedEndpoints {
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('v2/public/kline/list', params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated use getTickers() instead
|
||||
*/
|
||||
@@ -56,7 +56,7 @@ export class InverseClient extends SharedEndpoints {
|
||||
}): GenericAPIResponse {
|
||||
return this.getTickers(params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated use getTrades() instead
|
||||
*/
|
||||
@@ -75,7 +75,7 @@ export class InverseClient extends SharedEndpoints {
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('v2/public/trading-records', params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated use getLiquidations() instead
|
||||
*/
|
||||
@@ -97,7 +97,7 @@ export class InverseClient extends SharedEndpoints {
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('v2/public/mark-price-kline', params);
|
||||
}
|
||||
|
||||
|
||||
getIndexPriceKline(params: {
|
||||
symbol: string;
|
||||
interval: string;
|
||||
@@ -106,7 +106,7 @@ export class InverseClient extends SharedEndpoints {
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('v2/public/index-price-kline', params);
|
||||
}
|
||||
|
||||
|
||||
getPremiumIndexKline(params: {
|
||||
symbol: string;
|
||||
interval: string;
|
||||
@@ -121,7 +121,7 @@ export class InverseClient extends SharedEndpoints {
|
||||
* Account Data Endpoints
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Active orders
|
||||
*/
|
||||
@@ -183,7 +183,7 @@ export class InverseClient extends SharedEndpoints {
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('v2/private/order', params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Conditional orders
|
||||
*/
|
||||
@@ -246,7 +246,7 @@ export class InverseClient extends SharedEndpoints {
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('v2/private/stop-order', params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Position
|
||||
*/
|
||||
@@ -328,7 +328,7 @@ export class InverseClient extends SharedEndpoints {
|
||||
/**
|
||||
* Risk Limit
|
||||
*/
|
||||
|
||||
|
||||
getRiskLimitList(): GenericAPIResponse {
|
||||
return this.requestWrapper.get('open-api/wallet/risk-limit/list');
|
||||
}
|
||||
@@ -339,7 +339,7 @@ export class InverseClient extends SharedEndpoints {
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.post('open-api/wallet/risk-limit', params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Funding
|
||||
*/
|
||||
@@ -361,7 +361,7 @@ export class InverseClient extends SharedEndpoints {
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('v2/private/funding/predicted-funding', params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* LCP Info
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AxiosRequestConfig } from 'axios';
|
||||
import { GenericAPIResponse, getBaseRESTInverseUrl, RestClientInverseOptions } from './util/requestUtils';
|
||||
import { GenericAPIResponse, getRestBaseUrl, RestClientOptions } from './util/requestUtils';
|
||||
import RequestWrapper from './util/requestWrapper';
|
||||
import SharedEndpoints from './shared-endpoints';
|
||||
|
||||
@@ -11,23 +11,22 @@ export class LinearClient extends SharedEndpoints {
|
||||
*
|
||||
* @param {string} key - your API key
|
||||
* @param {string} secret - your API secret
|
||||
* @param {boolean} [livenet=false]
|
||||
* @param {RestClientInverseOptions} [restInverseOptions={}] options to configure REST API connectivity
|
||||
* @param {boolean} [useLivenet=false]
|
||||
* @param {RestClientOptions} [restInverseOptions={}] options to configure REST API connectivity
|
||||
* @param {AxiosRequestConfig} [requestOptions={}] HTTP networking options for axios
|
||||
*/
|
||||
|
||||
constructor(
|
||||
key?: string | undefined,
|
||||
secret?: string | undefined,
|
||||
livenet?: boolean,
|
||||
restInverseOptions:RestClientInverseOptions = {}, // TODO: Rename this type to be more general.
|
||||
useLivenet?: boolean,
|
||||
restInverseOptions: RestClientOptions = {},
|
||||
requestOptions: AxiosRequestConfig = {}
|
||||
) {
|
||||
super()
|
||||
this.requestWrapper = new RequestWrapper(
|
||||
key,
|
||||
secret,
|
||||
getBaseRESTInverseUrl(livenet),
|
||||
getRestBaseUrl(useLivenet),
|
||||
restInverseOptions,
|
||||
requestOptions
|
||||
);
|
||||
@@ -46,23 +45,11 @@ export class LinearClient extends SharedEndpoints {
|
||||
from: number;
|
||||
limit?: number;
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('/public/linear/kline', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use getTrades() instead
|
||||
*/
|
||||
getPublicTradingRecords(params: {
|
||||
symbol: string;
|
||||
from?: number;
|
||||
limit?: number;
|
||||
}): GenericAPIResponse {
|
||||
return this.getTrades(params);
|
||||
return this.requestWrapper.get('public/linear/kline', params);
|
||||
}
|
||||
|
||||
getTrades(params: {
|
||||
symbol: string;
|
||||
//from?: number;
|
||||
limit?: number;
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('public/linear/recent-trading-records', params);
|
||||
@@ -82,7 +69,7 @@ export class LinearClient extends SharedEndpoints {
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('public/linear/mark-price-kline', params);
|
||||
}
|
||||
|
||||
|
||||
getIndexPriceKline(params: {
|
||||
symbol: string;
|
||||
interval: string;
|
||||
@@ -105,10 +92,6 @@ export class LinearClient extends SharedEndpoints {
|
||||
*
|
||||
* Account Data Endpoints
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Active orders
|
||||
*/
|
||||
|
||||
placeActiveOrder(params: {
|
||||
@@ -137,7 +120,6 @@ export class LinearClient extends SharedEndpoints {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
order_status?: string;
|
||||
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('private/linear/order/list', params);
|
||||
}
|
||||
@@ -345,7 +327,15 @@ export class LinearClient extends SharedEndpoints {
|
||||
getRiskLimitList(params: {
|
||||
symbol: string;
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('public/linear/risk-limit');
|
||||
return this.requestWrapper.get('public/linear/risk-limit', params);
|
||||
}
|
||||
|
||||
setRiskLimit(params: {
|
||||
symbol: string;
|
||||
side: string;
|
||||
risk_id: string;
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('private/linear/position/set-risk', params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -355,13 +345,12 @@ export class LinearClient extends SharedEndpoints {
|
||||
getPredictedFundingFee(params: {
|
||||
symbol: string;
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('private/linear/funding/predicted-funding');
|
||||
return this.requestWrapper.get('private/linear/funding/predicted-funding', params);
|
||||
}
|
||||
|
||||
getLastFundingFee(params: {
|
||||
symbol: string;
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('private/linear/funding/prev-funding');
|
||||
return this.requestWrapper.get('private/linear/funding/prev-funding', params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +37,12 @@ export default class SharedEndpoints {
|
||||
return this.requestWrapper.get('v2/public/liq-records', params);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Market Data : Advanced
|
||||
*
|
||||
*/
|
||||
|
||||
getOpenInterest(params: {
|
||||
symbol: string;
|
||||
period: string;
|
||||
@@ -113,6 +119,14 @@ export default class SharedEndpoints {
|
||||
return this.requestWrapper.get('v2/private/exchange-order/list', params);
|
||||
}
|
||||
|
||||
getAssetExchangeRecords(params?: {
|
||||
limit?: number;
|
||||
from?: number;
|
||||
direction?: string;
|
||||
}): GenericAPIResponse {
|
||||
return this.requestWrapper.get('v2/private/exchange-order/list', params);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* API Data Endpoints
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createHmac } from 'crypto';
|
||||
|
||||
export interface RestClientInverseOptions {
|
||||
export interface RestClientOptions {
|
||||
// override the max size of the request window (in ms)
|
||||
recv_window?: number;
|
||||
|
||||
@@ -42,7 +42,7 @@ export function serializeParams(params: object = {}, strict_validation = false):
|
||||
.join('&');
|
||||
};
|
||||
|
||||
export function getBaseRESTInverseUrl(useLivenet?: boolean, restInverseOptions?: RestClientInverseOptions) {
|
||||
export function getRestBaseUrl(useLivenet?: boolean, restInverseOptions?: RestClientOptions) {
|
||||
const baseUrlsInverse = {
|
||||
livenet: 'https://api.bybit.com',
|
||||
testnet: 'https://api-testnet.bybit.com'
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios';
|
||||
|
||||
import { signMessage, serializeParams, RestClientInverseOptions, GenericAPIResponse, isPublicEndpoint } from './requestUtils';
|
||||
import { signMessage, serializeParams, RestClientOptions, GenericAPIResponse, isPublicEndpoint } from './requestUtils';
|
||||
|
||||
export default class RequestUtil {
|
||||
private timeOffset: number | null;
|
||||
private syncTimePromise: null | Promise<any>;
|
||||
private options: RestClientInverseOptions;
|
||||
private options: RestClientOptions;
|
||||
private baseUrl: string;
|
||||
private globalRequestOptions: AxiosRequestConfig;
|
||||
private key: string | undefined;
|
||||
@@ -15,7 +15,7 @@ export default class RequestUtil {
|
||||
key: string | undefined,
|
||||
secret: string | undefined,
|
||||
baseUrl: string,
|
||||
options: RestClientInverseOptions = {},
|
||||
options: RestClientOptions = {},
|
||||
requestOptions: AxiosRequestConfig = {}
|
||||
) {
|
||||
this.timeOffset = null;
|
||||
|
||||
@@ -75,6 +75,16 @@ const getLinearWsKeyForTopic = (topic: string) => {
|
||||
return wsKeyLinearPublic;
|
||||
}
|
||||
|
||||
export declare interface WebsocketClient {
|
||||
on(event: 'open', listener: ({ wsKey: string, event: any }) => void): this;
|
||||
on(event: 'reconnected', listener: ({ wsKey: string, event: any }) => void): this;
|
||||
on(event: 'reconnect', listener: () => void): this;
|
||||
on(event: 'close', listener: () => void): this;
|
||||
on(event: 'response', listener: (response: any) => void): this;
|
||||
on(event: 'update', listener: (response: any) => void): this;
|
||||
on(event: 'error', listener: (response: any) => void): this;
|
||||
}
|
||||
|
||||
export class WebsocketClient extends EventEmitter {
|
||||
private logger: typeof DefaultLogger;
|
||||
private restClient: InverseClient | LinearClient;
|
||||
|
||||
Reference in New Issue
Block a user