feat(): added Crypto Loan endpoints

This commit is contained in:
Jerko J
2024-10-15 12:34:43 +02:00
parent e019fb40f2
commit 7b7258b009
18 changed files with 566 additions and 4 deletions

View File

@@ -42,6 +42,7 @@ Node.js & JavaScript SDK for the Bybit REST APIs and WebSockets:
- Issues? Check the [issues tab](https://github.com/tiagosiebler/bybit-api/issues). - Issues? Check the [issues tab](https://github.com/tiagosiebler/bybit-api/issues).
- Discuss & collaborate with other node devs? Join our [Node.js Algo Traders](https://t.me/nodetraders) engineering community on telegram. - Discuss & collaborate with other node devs? Join our [Node.js Algo Traders](https://t.me/nodetraders) engineering community on telegram.
- Follow our announcement channel for real-time updates on [X/Twitter](https://x.com/QuantSDKs)
<!-- template_related_projects --> <!-- template_related_projects -->

View File

@@ -182,6 +182,17 @@ This table includes all endpoints from the official Exchange API docs and corres
| `getSpotMarginBorrowOrderDetail()` | :closed_lock_with_key: | GET | `/v5/spot-cross-margin-trade/orders` | | `getSpotMarginBorrowOrderDetail()` | :closed_lock_with_key: | GET | `/v5/spot-cross-margin-trade/orders` |
| `getSpotMarginRepaymentOrderDetail()` | :closed_lock_with_key: | GET | `/v5/spot-cross-margin-trade/repay-history` | | `getSpotMarginRepaymentOrderDetail()` | :closed_lock_with_key: | GET | `/v5/spot-cross-margin-trade/repay-history` |
| `toggleSpotCrossMarginTrade()` | :closed_lock_with_key: | POST | `/v5/spot-cross-margin-trade/switch` | | `toggleSpotCrossMarginTrade()` | :closed_lock_with_key: | POST | `/v5/spot-cross-margin-trade/switch` |
| `getCollateralCoins()` | | GET | `/v5/crypto-loan/collateral-data` |
| `getBorrowableCoins()` | | GET | `/v5/crypto-loan/loanable-data` |
| `getAccountBorrowCollateralLimit()` | :closed_lock_with_key: | GET | `/v5/crypto-loan/borrowable-collateralisable-number` |
| `borrowCryptoLoan()` | :closed_lock_with_key: | POST | `/v5/crypto-loan/borrow` |
| `repayCryptoLoan()` | :closed_lock_with_key: | POST | `/v5/crypto-loan/repay` |
| `getUnpaidLoanOrders()` | :closed_lock_with_key: | GET | `/v5/crypto-loan/ongoing-orders` |
| `getRepaymentHistory()` | :closed_lock_with_key: | GET | `/v5/crypto-loan/repayment-history` |
| `getCompletedLoanOrderHistory()` | :closed_lock_with_key: | GET | `/v5/crypto-loan/borrow-history` |
| `getMaxAllowedReductionCollateralAmount()` | :closed_lock_with_key: | GET | `/v5/crypto-loan/max-collateral-amount` |
| `adjustCollateralAmount()` | :closed_lock_with_key: | POST | `/v5/crypto-loan/adjust-ltv` |
| `getLoanLTVAdjustmentHistory()` | :closed_lock_with_key: | GET | `/v5/crypto-loan/adjustment-history` |
| `getInstitutionalLendingProductInfo()` | | GET | `/v5/ins-loan/product-infos` | | `getInstitutionalLendingProductInfo()` | | GET | `/v5/ins-loan/product-infos` |
| `getInstitutionalLendingMarginCoinInfo()` | | GET | `/v5/ins-loan/ensure-tokens` | | `getInstitutionalLendingMarginCoinInfo()` | | GET | `/v5/ins-loan/ensure-tokens` |
| `getInstitutionalLendingMarginCoinInfoWithConversionRate()` | | GET | `/v5/ins-loan/ensure-tokens-convert` | | `getInstitutionalLendingMarginCoinInfoWithConversionRate()` | | GET | `/v5/ins-loan/ensure-tokens-convert` |
@@ -192,4 +203,7 @@ This table includes all endpoints from the official Exchange API docs and corres
| `bindOrUnbindUID()` | :closed_lock_with_key: | POST | `/v5/ins-loan/association-uid` | | `bindOrUnbindUID()` | :closed_lock_with_key: | POST | `/v5/ins-loan/association-uid` |
| `getExchangeBrokerEarnings()` | :closed_lock_with_key: | GET | `/v5/broker/earnings-info` | | `getExchangeBrokerEarnings()` | :closed_lock_with_key: | GET | `/v5/broker/earnings-info` |
| `getExchangeBrokerAccountInfo()` | :closed_lock_with_key: | GET | `/v5/broker/account-info` | | `getExchangeBrokerAccountInfo()` | :closed_lock_with_key: | GET | `/v5/broker/account-info` |
| `getBrokerSubAccountDeposits()` | :closed_lock_with_key: | GET | `/v5/broker/asset/query-sub-member-deposit-record` | | `getBrokerSubAccountDeposits()` | :closed_lock_with_key: | GET | `/v5/broker/asset/query-sub-member-deposit-record` |
| `getBrokerVoucherSpec()` | :closed_lock_with_key: | POST | `/v5/broker/award/info` |
| `issueBrokerVoucher()` | :closed_lock_with_key: | POST | `/v5/broker/award/distribute-award` |
| `getBrokerIssuedVoucher()` | :closed_lock_with_key: | POST | `/v5/broker/award/distribution-record` |

View File

@@ -0,0 +1,20 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});
client
.adjustCollateralAmount({
orderId: '1794267532472646144',
amount: '0.001',
direction: '1',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,22 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});
client
.borrowCryptoLoan({
loanCurrency: 'USDT',
loanAmount: '550',
collateralCurrency: 'BTC',
loanTerm: null,
collateralAmount: null,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,19 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});
client
.getAccountBorrowCollateralLimit({
loanCurrency: 'USDT',
collateralCurrency: 'BTC',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,19 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});
client
.getBorrowableCoins({
currency: 'USDT',
vipLevel: 'VIP0',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,19 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});
client
.getCollateralCoins({
currency: 'ETH',
vipLevel: 'PRO1',
})
.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,
key: 'apikey',
secret: 'apisecret',
});
client
.getCompletedLoanOrderHistory({ orderId: '1794267532472646144' })
.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,
key: 'apikey',
secret: 'apisecret',
});
client
.getLoanLTVAdjustmentHistory({ adjustId: '1794271131730737664' })
.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,
key: 'apikey',
secret: 'apisecret',
});
client
.getMaxAllowedReductionCollateralAmount({ orderId: '1794267532472646144' })
.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,
key: 'apikey',
secret: 'apisecret',
});
client
.getRepaymentHistory({ repayId: '1794271131730737664' })
.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,
key: 'apikey',
secret: 'apisecret',
});
client
.getUnpaidLoanOrders({ orderId: '1793683005081680384' })
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

View File

@@ -0,0 +1,19 @@
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});
client
.repayCryptoLoan({
orderId: '1794267532472646144',
amount: '100',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "3.10.19", "version": "3.10.20",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "bybit-api", "name": "bybit-api",
"version": "3.10.19", "version": "3.10.20",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^1.6.6", "axios": "^1.6.6",

View File

@@ -1,6 +1,6 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "3.10.19", "version": "3.10.20",
"description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.", "description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@@ -179,6 +179,22 @@ import {
WithdrawParamsV5, WithdrawParamsV5,
WithdrawalRecordV5, WithdrawalRecordV5,
} from './types'; } from './types';
import {
BorrowCryptoLoanParamsV5,
GetCompletedLoanOrderHistoryParamsV5,
GetLoanLTVAdjustmentHistoryParamsV5,
GetRepaymentHistoryParamsV5,
GetUnpaidLoanOrdersParamsV5,
} from './types/request/v5-crypto-loan';
import {
AccountBorrowCollateralLimitV5,
CompletedLoanOrderV5,
LoanLTVAdjustmentHistoryV5,
RepaymentHistoryV5,
UnpaidLoanOrderV5,
VipBorrowableCoinListV5,
VipCollateralCoinListV5,
} from './types/response/v5-crypto-loan';
import { REST_CLIENT_TYPE_ENUM } from './util'; import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient'; import BaseRestClient from './util/BaseRestClient';
@@ -2022,6 +2038,206 @@ export class RestClientV5 extends BaseRestClient {
return this.postPrivate('/v5/spot-cross-margin-trade/switch', params); return this.postPrivate('/v5/spot-cross-margin-trade/switch', params);
} }
/**
*
****** Crypto Loan
*
*/
/**
* Get Collateral Coins
*
* INFO: Do not need authentication
*/
getCollateralCoins(params?: {
vipLevel?: string;
currency?: string;
}): Promise<
APIResponseV3WithTime<{
vipCoinList: VipCollateralCoinListV5[];
}>
> {
return this.get('/v5/crypto-loan/collateral-data', params);
}
/**
* Get Borrowable Coins
*
* INFO: Do not need authentication
*/
getBorrowableCoins(params?: {
vipLevel?: string;
currency?: string;
}): Promise<
APIResponseV3WithTime<{
vipCoinList: VipBorrowableCoinListV5[];
}>
> {
return this.get('/v5/crypto-loan/loanable-data', params);
}
/**
* Get Account Borrow/Collateral Limit
* Query the account borrowable/collateral limit
*
* Permission: "Spot trade"
*/
getAccountBorrowCollateralLimit(params: {
loanCurrency: string;
collateralCurrency: string;
}): Promise<APIResponseV3WithTime<AccountBorrowCollateralLimitV5>> {
return this.getPrivate(
'/v5/crypto-loan/borrowable-collateralisable-number',
params,
);
}
/**
* Borrow Crypto Loan
*
* Permission: "Spot trade"
*
* INFO:
* The loan funds are released to the Funding account
* The collateral funds are deducted from the Funding account, so make sure you have enough collateral amount in the funding wallet
*/
borrowCryptoLoan(params: BorrowCryptoLoanParamsV5): Promise<
APIResponseV3WithTime<{
orderId: string;
}>
> {
return this.postPrivate('/v5/crypto-loan/borrow', params);
}
/**
* Repay Crypto Loan
*
* You can repay partial loan. If there is interest occurred, interest will be repaid in priority
*
* Permission: "Spot trade"
*
* INFO:
* The repaid amount will be deducted from Funding account
* The collateral amount will not be auto returned when you don't fully repay the debt, but you can also adjust collateral amount
*/
repayCryptoLoan(params: { orderId: string; amount: string }): Promise<
APIResponseV3WithTime<{
repayId: string;
}>
> {
return this.postPrivate('/v5/crypto-loan/repay', params);
}
/**
* Get Unpaid Loan Orders
* Query the ongoing loan orders, which are not fully repaid
*
* Permission: "Spot trade"
*/
getUnpaidLoanOrders(params?: GetUnpaidLoanOrdersParamsV5): Promise<
APIResponseV3WithTime<{
list: UnpaidLoanOrderV5[];
nextPageCursor: string;
}>
> {
return this.getPrivate('/v5/crypto-loan/ongoing-orders', params);
}
/**
* Get Repayment Transaction History
* Query repaid transaction history
*
* Permission: "Spot trade"
*
* INFO:
* Support querying last 6 months completed loan orders
* Only successful repayments can be queried
*/
getRepaymentHistory(params?: GetRepaymentHistoryParamsV5): Promise<
APIResponseV3WithTime<{
list: RepaymentHistoryV5[];
nextPageCursor: string;
}>
> {
return this.getPrivate('/v5/crypto-loan/repayment-history', params);
}
/**
* Get Completed Loan Order History
* Query the completed loan orders
*
* Permission: "Spot trade"
*
* INFO:
* Support querying last 6 months completed loan orders
*/
getCompletedLoanOrderHistory(
params?: GetCompletedLoanOrderHistoryParamsV5,
): Promise<
APIResponseV3WithTime<{
list: CompletedLoanOrderV5[];
nextPageCursor: string;
}>
> {
return this.getPrivate('/v5/crypto-loan/borrow-history', params);
}
/**
* Get Max. Allowed Reduction Collateral Amount
* Query the maximum allowed reduction collateral amount
*
* Permission: "Spot trade"
*/
getMaxAllowedReductionCollateralAmount(params: { orderId: string }): Promise<
APIResponseV3WithTime<{
maxCollateralAmount: string;
}>
> {
return this.getPrivate('/v5/crypto-loan/max-collateral-amount', params);
}
/**
* Adjust Collateral Amount
* You can increase or reduce collateral amount. When you reduce, please follow the max. allowed reduction amount.
*
* Permission: "Spot trade"
*
* INFO:
* The adjusted collateral amount will be returned to or deducted from Funding account
*/
adjustCollateralAmount(params: {
orderId: string;
amount: string;
direction: '0' | '1';
}): Promise<
APIResponseV3WithTime<{
adjustId: string;
}>
> {
return this.postPrivate('/v5/crypto-loan/adjust-ltv', params);
}
/**
* Get Loan LTV Adjustment History
* Query the transaction history of collateral amount adjustment
*
* Permission: "Spot trade"
*
* INFO:
* Support querying last 6 months adjustment transactions
* Only the ltv adjustment transactions launched by the user can be queried
*/
getLoanLTVAdjustmentHistory(
params?: GetLoanLTVAdjustmentHistoryParamsV5,
): Promise<
APIResponseV3WithTime<{
list: LoanLTVAdjustmentHistoryV5[];
nextPageCursor: string;
}>
> {
return this.getPrivate('/v5/crypto-loan/adjustment-history', params);
}
/** /**
* *
****** Institutional Lending ****** Institutional Lending

View File

@@ -0,0 +1,41 @@
export interface BorrowCryptoLoanParamsV5 {
loanCurrency: string;
loanAmount?: string;
loanTerm?: string;
collateralCurrency: string;
collateralAmount?: string;
}
export interface GetUnpaidLoanOrdersParamsV5 {
orderId?: string;
loanCurrency?: string;
collateralCurrency?: string;
loanTermType?: string;
loanTerm?: string;
limit?: string;
cursor?: string;
}
export interface GetRepaymentHistoryParamsV5 {
orderId?: string;
repayId?: string;
loanCurrency?: string;
limit?: string;
cursor?: string;
}
export interface GetCompletedLoanOrderHistoryParamsV5 {
orderId?: string;
loanCurrency?: string;
collateralCurrency?: string;
limit?: string;
cursor?: string;
}
export interface GetLoanLTVAdjustmentHistoryParamsV5 {
orderId?: string;
adjustId?: string;
collateralCurrency?: string;
limit?: string;
cursor?: string;
}

View File

@@ -0,0 +1,92 @@
export interface CollateralCoinV5 {
collateralAccuracy: number;
currency: string;
initialLTV: string;
liquidationLTV: string;
marginCallLTV: string;
maxLimit: string;
}
export interface VipCollateralCoinListV5 {
list: CollateralCoinV5[];
vipLevel: string;
}
export interface BorrowableCoinV5 {
borrowingAccuracy: number;
currency: string;
flexibleHourlyInterestRate: string;
hourlyInterestRate7D: string;
hourlyInterestRate14D: string;
hourlyInterestRate30D: string;
hourlyInterestRate90D: string;
hourlyInterestRate180D: string;
maxBorrowingAmount: string;
minBorrowingAmount: string;
}
export interface VipBorrowableCoinListV5 {
list: BorrowableCoinV5[];
vipLevel: string;
}
export interface AccountBorrowCollateralLimitV5 {
collateralCurrency: string;
loanCurrency: string;
maxCollateralAmount: string;
maxLoanAmount: string;
minCollateralAmount: string;
minLoanAmount: string;
}
export interface UnpaidLoanOrderV5 {
collateralAmount: string;
collateralCurrency: string;
currentLTV: string;
expirationTime: string;
hourlyInterestRate: string;
loanCurrency: string;
loanTerm: string;
orderId: string;
residualInterest: string;
residualPenaltyInterest: string;
totalDebt: string;
}
export interface RepaymentHistoryV5 {
collateralCurrency: string;
collateralReturn: string;
loanCurrency: string;
loanTerm: string;
orderId: string;
repayAmount: string;
repayId: string;
repayStatus: number;
repayTime: string;
repayType: string;
}
export interface CompletedLoanOrderV5 {
borrowTime: string;
collateralCurrency: string;
expirationTime: string;
hourlyInterestRate: string;
initialCollateralAmount: string;
initialLoanAmount: string;
loanCurrency: string;
loanTerm: string;
orderId: string;
repaidInterest: string;
repaidPenaltyInterest: string;
status: number;
}
export interface LoanLTVAdjustmentHistoryV5 {
collateralCurrency: string;
orderId: string;
adjustId: string;
adjustTime: string;
preLTV: string;
afterLTV: string;
direction: number;
amount: string;
}