Skip to content

Commit

Permalink
Merge pull request #359 from JJ-Cro/ReleaseNotes170724
Browse files Browse the repository at this point in the history
v3.10.12: feat() Add convert endpoints, convert examples, small updates to request/response types
  • Loading branch information
tiagosiebler authored Jul 25, 2024
2 parents 17be240 + 351300d commit bd7ccb4
Show file tree
Hide file tree
Showing 16 changed files with 305 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ bundleReport.html
.history/
rawReq.ts
localtest.sh
localtest.ts

18 changes: 18 additions & 0 deletions examples/apidoc/V5/Asset/confirm-convert-quote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { RestClientV5 } = require('bybit-api');

const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});

client
.confirmConvertQuote({
quoteTxId: '10100108106409343501030232064',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
16 changes: 16 additions & 0 deletions examples/apidoc/V5/Asset/get-convert-coins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { RestClientV5 } = require('bybit-api');

const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});

client
.getConvertCoins({ accountType: 'eb_convert_spot' })
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
16 changes: 16 additions & 0 deletions examples/apidoc/V5/Asset/get-convert-history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { RestClientV5 } = require('bybit-api');

const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});

client
.getConvertHistory()
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
19 changes: 19 additions & 0 deletions examples/apidoc/V5/Asset/get-convert-status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { RestClientV5 } = require('bybit-api');

const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});

client
.getConvertStatus({
quoteTxId: 'quoteTransactionId',
accountType: 'eb_convert_funding',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
23 changes: 23 additions & 0 deletions examples/apidoc/V5/Asset/request-convert-quote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { RestClientV5 } = require('bybit-api');

const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});

client
.requestConvertQuote({
requestId: 'test-00002',
fromCoin: 'ETH',
toCoin: 'BTC',
accountType: 'eb_convert_funding',
requestCoin: 'ETH',
requestAmount: '0.1',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bybit-api",
"version": "3.10.11",
"version": "3.10.12",
"description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -38,8 +38,8 @@
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-simple-import-sort": "^12.0.0",
"jest": "^29.7.0",
"ts-node": "^10.9.2",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"optionalDependencies": {
Expand Down
88 changes: 88 additions & 0 deletions src/rest-client-v5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ import {
CoinInfoV5,
CollateralInfoV5,
ConfirmNewRiskLimitParamsV5,
ConvertCoinSpecV5,
ConvertCoinsParamsV5,
ConvertHistoryRecordV5,
ConvertQuoteV5,
ConvertStatusV5,
CreateSubApiKeyParamsV5,
CreateSubApiKeyResultV5,
CreateSubMemberParamsV5,
Expand Down Expand Up @@ -64,6 +69,7 @@ import {
GetClassicTransactionLogsParamsV5,
GetClosedPnLParamsV5,
GetCoinExchangeRecordParamsV5,
GetConvertHistoryParamsV5,
GetDeliveryPriceParamsV5,
GetDeliveryRecordParamsV5,
GetDepositRecordParamsV5,
Expand Down Expand Up @@ -130,6 +136,7 @@ import {
RedeemSpotLeveragedTokenResultV5,
RepayLiabilityParamsV5,
RepayLiabilityResultV5,
RequestConvertQuoteParamsV5,
RiskLimitV5,
SetAutoAddMarginParamsV5,
SetCollateralCoinParamsV5,
Expand Down Expand Up @@ -552,6 +559,10 @@ export class RestClientV5 extends BaseRestClient {
*
* If you need to turn it on/off, you can contact your client manager for consultation and application.
* The default time window is 10 seconds.
*
* Only for institutional clients!
*
* If it doesn't work, use v2!
*/
setDisconnectCancelAllWindow(
category: 'option',
Expand All @@ -563,6 +574,21 @@ export class RestClientV5 extends BaseRestClient {
});
}

/**
* This endpoint allows you to set the disconnection protect time window. Covers: option (unified account).
*
* If you need to turn it on/off, you can contact your client manager for consultation and application.
* The default time window is 10 seconds.
*
* Only for institutional clients!
*/
setDisconnectCancelAllWindowV2(params: {
product: 'OPTION' | 'SPOT' | 'DERIVATIVES',
timeWindow: number,
}): Promise<APIResponseV3<undefined>> {
return this.postPrivate('/v5/order/disconnected-cancel-all', params);
}

/**
*
****** Position APIs
Expand Down Expand Up @@ -1385,6 +1411,68 @@ export class RestClientV5 extends BaseRestClient {
return this.postPrivate('/v5/asset/withdraw/cancel', { id });
}

/**
* Query the coin list of convert from (to).
*/
getConvertCoins(params: ConvertCoinsParamsV5): Promise<
APIResponseV3WithTime<{
coins: ConvertCoinSpecV5[];
}>
> {
return this.getPrivate('/v5/asset/exchange/query-coin-list', params);
}

/**
* Request a quote for converting coins.
*/
requestConvertQuote(
params: RequestConvertQuoteParamsV5,
): Promise<APIResponseV3WithTime<ConvertQuoteV5>> {
return this.postPrivate('/v5/asset/exchange/quote-apply', params);
}

/**
* Confirm a quote for converting coins.
*/
confirmConvertQuote(params: { quoteTxId: string }): Promise<
APIResponseV3WithTime<{
quoteTxId: string;
exchangeStatus: 'init' | 'processing' | 'success' | 'failure';
}>
> {
return this.postPrivate('/v5/asset/exchange/convert-execute', params);
}

/**
* Query the exchange result by sending quoteTxId.
*/
getConvertStatus(params: {
quoteTxId?: string;
accountType:
| 'eb_convert_funding'
| 'eb_convert_uta'
| 'eb_convert_spot'
| 'eb_convert_contract'
| 'eb_convert_inverse';
}): Promise<
APIResponseV3WithTime<{
result: ConvertStatusV5;
}>
> {
return this.getPrivate('/v5/asset/exchange/convert-result-query', params);
}

/**
* Query the conversion history.
*/
getConvertHistory(params?: GetConvertHistoryParamsV5): Promise<
APIResponseV3WithTime<{
list: ConvertHistoryRecordV5[];
}>
> {
return this.getPrivate('/v5/asset/exchange/query-convert-history', params);
}

/**
*
****** User APIs
Expand Down
28 changes: 28 additions & 0 deletions src/types/request/v5-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,31 @@ export interface WithdrawParamsV5 {
forceChain?: number;
accountType?: 'SPOT' | 'FUND';
}

export interface ConvertCoinsParamsV5 {
coin?: string;
side?: number;
accountType:
| 'eb_convert_funding'
| 'eb_convert_uta'
| 'eb_convert_spot'
| 'eb_convert_contract'
| 'eb_convert_inverse';
}

export interface RequestConvertQuoteParamsV5 {
fromCoin: string;
toCoin: string;
fromCoinType?: string;
toCoinType?: string;
requestCoin: string;
requestAmount: string;
accountType: 'eb_convert_funding' | 'eb_convert_uta' | 'eb_convert_spot' | 'eb_convert_contract' | 'eb_convert_inverse';
requestId?: string;
}

export interface GetConvertHistoryParamsV5 {
accountType?: string;
index?: number;
limit?: number;
}
2 changes: 1 addition & 1 deletion src/types/request/v5-broker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface GetExchangeBrokerEarningsParamsV5 {
bizType?: 'SPOT' | 'DERIVATIVES' | 'OPTIONS';
bizType?: 'SPOT' | 'DERIVATIVES' | 'OPTIONS' | 'CONVERT';
begin?: string;
end?: string;
uid?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/types/response/v5-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export interface FeeRateV5 {
export interface AccountInfoV5 {
unifiedMarginStatus: number;
marginMode: AccountMarginModeV5;
isMasterTrader: boolean;
spotHedgingStatus: string;
updatedTime: string;
}

Expand Down Expand Up @@ -134,5 +136,3 @@ export interface DCPInfoV5 {
dcpStatus: 'ON';
timeWindow: string;
}


70 changes: 68 additions & 2 deletions src/types/response/v5-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,74 @@ export interface WithdrawalRecordV5 {
updateTime: string;
}


export interface VaspEntityV5 {
vaspEntityId: string;
vaspName: string;
}
}

export interface ConvertCoinSpecV5 {
coin: string;
fullName: string;
icon: string;
iconNight: string;
accuracyLength: number;
coinType: string;
balance: string;
uBalance: string;
singleFromMinLimit: string;
singleFromMaxLimit: string;
disableFrom: boolean;
disableTo: boolean;
timePeriod: number;
singleToMinLimit: string;
singleToMaxLimit: string;
dailyFromMinLimit: string;
dailyFromMaxLimit: string;
dailyToMinLimit: string;
dailyToMaxLimit: string;
}

export interface ConvertQuoteV5 {
quoteTxId: string;
exchangeRate: string;
fromCoin: string;
fromCoinType: string;
toCoin: string;
toCoinType: string;
fromAmount: string;
toAmount: string;
expiredTime: string;
requestId: string;
}

export interface ConvertStatusV5 {
accountType: string;
exchangeTxId: string;
userId: string;
fromCoin: string;
fromCoinType: string;
toCoin: string;
toCoinType: string;
fromAmount: string;
toAmount: string;
exchangeStatus: 'init' | 'processing' | 'success' | 'failure';
extInfo: object;
convertRate: string;
createdAt: string;
}

export interface ConvertHistoryRecordV5 {
accountType: string;
exchangeTxId: string;
userId: string;
fromCoin: string;
fromCoinType: string;
toCoin: string;
toCoinType: string;
fromAmount: string;
toAmount: string;
exchangeStatus: 'init' | 'processing' | 'success' | 'failure';
extInfo: object;
convertRate: string;
createdAt: string;
}
Loading

0 comments on commit bd7ccb4

Please sign in to comment.