feat(): add/update missing v5 market endpoints. add api doc examples for each endpoint.

This commit is contained in:
tiagosiebler
2023-06-07 12:13:25 +01:00
parent 15d5ae00cf
commit 4f563a65a5
21 changed files with 322 additions and 4 deletions

View File

@@ -0,0 +1,3 @@
# V5 - REST - Market
https://bybit-exchange.github.io/docs/v5/market/kline

View File

@@ -0,0 +1,17 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getTickers({
category: 'inverse',
symbol: 'BTCUSDT',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,18 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getFundingRateHistory({
category: 'linear',
symbol: 'ETHPERP',
limit: 1,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,18 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getHistoricalVolatility({
category: 'option',
baseCoin: 'ETH',
period: 30,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,17 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getInstrumentsInfo({
category: 'linear',
symbol: 'BTCUSDT',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,16 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getInsurance({
coin: 'ETH',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,21 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getIndexPriceKline({
category: 'inverse',
symbol: 'BTCUSDZ22',
interval: '1',
start: 1670601600000,
end: 1670608800000,
limit: 2,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,21 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getMarkPriceKline({
category: 'linear',
symbol: 'BTCUSD',
interval: '15',
start: 1670601600000,
end: 1670608800000,
limit: 1,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,20 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getPremiumIndexPriceKline({
category: 'linear',
symbol: 'BTCUSDT',
interval: 'D',
start: 1652112000000,
end: 1652544000000,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,20 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getKline({
category: 'inverse',
symbol: 'BTCUSD',
interval: '60',
start: 1670601600000,
end: 1670608800000,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,20 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getOpenInterest({
category: 'inverse',
symbol: 'BTCUSD',
intervalTime: '5min',
startTime: 1669571100000,
endTime: 1669571400000,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,17 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getOrderbook({
category: 'linear',
symbol: 'BTCUSDT',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,18 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getPublicTradingHistory({
category: 'spot',
symbol: 'BTCUSDT',
limit: 1,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,17 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getRiskLimit({
category: 'inverse',
symbol: 'BTCUSD',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,17 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getTickers({
category: 'inverse',
symbol: 'BTCUSDT',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,3 @@
# V5 - REST - Trade
https://bybit-exchange.github.io/docs/v5/order/create-order

View File

@@ -0,0 +1,19 @@
import { RestClientV5 } from '../../src';
const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});
client
.getDeliveryPrice({
category: 'option',
symbol: 'ETH-26DEC22-1400-C"',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -35,6 +35,7 @@ import {
CreateSubMemberParamsV5, CreateSubMemberParamsV5,
CreateSubMemberResultV5, CreateSubMemberResultV5,
CursorListV5, CursorListV5,
DeliveryPriceV5,
DeliveryRecordV5, DeliveryRecordV5,
DepositAddressResultV5, DepositAddressResultV5,
DepositRecordV5, DepositRecordV5,
@@ -50,6 +51,7 @@ import {
GetBorrowHistoryParamsV5, GetBorrowHistoryParamsV5,
GetClosedPnLParamsV5, GetClosedPnLParamsV5,
GetCoinExchangeRecordParamsV5, GetCoinExchangeRecordParamsV5,
GetDeliveryPriceParamsV5,
GetDeliveryRecordParamsV5, GetDeliveryRecordParamsV5,
GetDepositRecordParamsV5, GetDepositRecordParamsV5,
GetExecutionListParamsV5, GetExecutionListParamsV5,
@@ -333,6 +335,8 @@ export class RestClientV5 extends BaseRestClient {
* Get the delivery price for option * Get the delivery price for option
* *
* Covers: Option * Covers: Option
*
* @deprecated use getDeliveryPrice() instead
*/ */
getOptionDeliveryPrice( getOptionDeliveryPrice(
params: GetOptionDeliveryPriceParamsV5, params: GetOptionDeliveryPriceParamsV5,
@@ -342,6 +346,17 @@ export class RestClientV5 extends BaseRestClient {
return this.get('/v5/market/delivery-price', params); return this.get('/v5/market/delivery-price', params);
} }
/**
* Get the delivery price of Inverse futures, USDC futures and Options
*
* Covers: USDC futures / Inverse futures / Option
*/
getDeliveryPrice(
params: GetDeliveryPriceParamsV5,
): Promise<APIResponseV3WithTime<CategoryCursorListV5<DeliveryPriceV5[]>>> {
return this.get('/v5/market/delivery-price', params);
}
/** /**
* *
****** Trade APIs ****** Trade APIs

View File

@@ -1,5 +1,5 @@
import { KlineIntervalV3 } from '../shared'; import { KlineIntervalV3 } from '../shared';
import { CategoryV5, OptionTypeV5 } from '../v5-shared'; import { CategoryV5, InstrumentStatusV5, OptionTypeV5 } from '../v5-shared';
export interface GetKlineParamsV5 { export interface GetKlineParamsV5 {
category: 'spot' | 'linear' | 'inverse'; category: 'spot' | 'linear' | 'inverse';
@@ -40,6 +40,7 @@ export interface GetPremiumIndexPriceKlineParamsV5 {
export interface GetInstrumentsInfoParamsV5 { export interface GetInstrumentsInfoParamsV5 {
category: CategoryV5; category: CategoryV5;
symbol?: string; symbol?: string;
status?: InstrumentStatusV5;
baseCoin?: string; baseCoin?: string;
limit?: number; limit?: number;
cursor?: string; cursor?: string;
@@ -95,7 +96,7 @@ export interface GetOpenInterestParamsV5 {
export interface GetHistoricalVolatilityParamsV5 { export interface GetHistoricalVolatilityParamsV5 {
category: 'option'; category: 'option';
baseCoin?: string; baseCoin?: string;
period?: number; period?: 7 | 14 | 21 | 30 | 60 | 90 | 180 | 270;
startTime?: number; startTime?: number;
endTime?: number; endTime?: number;
} }
@@ -116,3 +117,11 @@ export interface GetOptionDeliveryPriceParamsV5 {
limit?: number; limit?: number;
cursor?: string; cursor?: string;
} }
export interface GetDeliveryPriceParamsV5 {
category: 'linear' | 'inverse' | 'option';
symbol?: string;
baseCoin?: string;
limit?: number;
cursor?: string;
}

View File

@@ -24,7 +24,7 @@ export type OHLCVKlineV5 = [
string, string,
string, string,
string, string,
string string,
]; ];
/** /**
@@ -257,8 +257,15 @@ export interface RiskLimitV5 {
maxLeverage: string; maxLeverage: string;
} }
/** @deprecated use DeliveryPriceV5 instead */
export interface OptionDeliveryPriceV5 { export interface OptionDeliveryPriceV5 {
symbol: string; symbol: string;
deliveryPrice: string; deliveryPrice: string;
deliveryTime: string; deliveryTime: string;
} }
export interface DeliveryPriceV5 {
symbol: string;
deliveryPrice: string;
deliveryTime: string;
}

View File

@@ -4,7 +4,12 @@ export type ContractTypeV5 =
| 'LinearPerpetual' | 'LinearPerpetual'
| 'InverseFutures'; | 'InverseFutures';
export type InstrumentStatusV5 = 'Pending' | 'Trading' | 'Settling' | 'Closed'; export type InstrumentStatusV5 =
| 'PreLaunch'
| 'Trading'
| 'Settling'
| 'Delivering'
| 'Closed';
export type OrderFilterV5 = 'Order' | 'tpslOrder'; export type OrderFilterV5 = 'Order' | 'tpslOrder';
export type OrderSideV5 = 'Buy' | 'Sell'; export type OrderSideV5 = 'Buy' | 'Sell';