feat(): added new rest EARN endpoints
This commit is contained in:
19
examples/apidoc/V5/Earn/get-product-info.js
Normal file
19
examples/apidoc/V5/Earn/get-product-info.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
const { RestClientV5 } = require('bybit-api');
|
||||||
|
|
||||||
|
const client = new RestClientV5({
|
||||||
|
testnet: true,
|
||||||
|
key: 'apikey',
|
||||||
|
secret: 'apisecret',
|
||||||
|
});
|
||||||
|
|
||||||
|
client
|
||||||
|
.getEarnProduct({
|
||||||
|
category: 'FlexibleSaving',
|
||||||
|
coin: 'BTC',
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
19
examples/apidoc/V5/Earn/get-stake-redeem-order-history.js
Normal file
19
examples/apidoc/V5/Earn/get-stake-redeem-order-history.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
const { RestClientV5 } = require('bybit-api');
|
||||||
|
|
||||||
|
const client = new RestClientV5({
|
||||||
|
testnet: true,
|
||||||
|
key: 'apikey',
|
||||||
|
secret: 'apisecret',
|
||||||
|
});
|
||||||
|
|
||||||
|
client
|
||||||
|
.getEarnOrderHistory({
|
||||||
|
category: 'FlexibleSaving',
|
||||||
|
orderId: '0572b030-6a0b-423f-88c4-b6ce31c0c82d',
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
19
examples/apidoc/V5/Earn/get-staked-position.js
Normal file
19
examples/apidoc/V5/Earn/get-staked-position.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
const { RestClientV5 } = require('bybit-api');
|
||||||
|
|
||||||
|
const client = new RestClientV5({
|
||||||
|
testnet: true,
|
||||||
|
key: 'apikey',
|
||||||
|
secret: 'apisecret',
|
||||||
|
});
|
||||||
|
|
||||||
|
client
|
||||||
|
.getEarnPosition({
|
||||||
|
category: 'FlexibleSaving',
|
||||||
|
coin: 'USDT',
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
24
examples/apidoc/V5/Earn/stake-redeem.js
Normal file
24
examples/apidoc/V5/Earn/stake-redeem.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
const { RestClientV5 } = require('bybit-api');
|
||||||
|
|
||||||
|
const client = new RestClientV5({
|
||||||
|
testnet: true,
|
||||||
|
key: 'apikey',
|
||||||
|
secret: 'apisecret',
|
||||||
|
});
|
||||||
|
|
||||||
|
client
|
||||||
|
.submitStakeRedeem({
|
||||||
|
category: 'FlexibleSaving',
|
||||||
|
orderType: 'Stake',
|
||||||
|
accountType: 'FUND',
|
||||||
|
amount: '0.35',
|
||||||
|
coin: 'BTC',
|
||||||
|
productId: '430',
|
||||||
|
orderLinkId: 'btc-earn-001',
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
@@ -193,6 +193,16 @@ import {
|
|||||||
WithdrawableAmountV5,
|
WithdrawableAmountV5,
|
||||||
WithdrawalRecordV5,
|
WithdrawalRecordV5,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
import {
|
||||||
|
GetEarnOrderHistoryParams,
|
||||||
|
GetEarnPositionParams,
|
||||||
|
SubmitStakeRedeemParams,
|
||||||
|
} from './types/request/v5-earn';
|
||||||
|
import {
|
||||||
|
EarnOrderHistory,
|
||||||
|
EarnPosition,
|
||||||
|
EarnProduct,
|
||||||
|
} from './types/response/v5-earn';
|
||||||
|
|
||||||
import { REST_CLIENT_TYPE_ENUM } from './util';
|
import { REST_CLIENT_TYPE_ENUM } from './util';
|
||||||
import BaseRestClient from './util/BaseRestClient';
|
import BaseRestClient from './util/BaseRestClient';
|
||||||
@@ -2546,4 +2556,73 @@ export class RestClientV5 extends BaseRestClient {
|
|||||||
): Promise<APIResponseV3<BrokerIssuedVoucherV5>> {
|
): Promise<APIResponseV3<BrokerIssuedVoucherV5>> {
|
||||||
return this.postPrivate('/v5/broker/award/distribution-record', params);
|
return this.postPrivate('/v5/broker/award/distribution-record', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
****** EARN
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Product Info for Earn products
|
||||||
|
*
|
||||||
|
* INFO: Do not need authentication
|
||||||
|
*/
|
||||||
|
getEarnProduct(params: { category: string; coin?: string }): Promise<
|
||||||
|
APIResponseV3WithTime<{
|
||||||
|
list: EarnProduct[];
|
||||||
|
}>
|
||||||
|
> {
|
||||||
|
return this.get('/v5/earn/product', params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stake or Redeem Earn products
|
||||||
|
*
|
||||||
|
* INFO: API key needs "Earn" permission
|
||||||
|
*
|
||||||
|
* NOTE: In times of high demand for loans in the market for a specific cryptocurrency,
|
||||||
|
* the redemption of the principal may encounter delays and is expected to be processed
|
||||||
|
* within 48 hours. Once the redemption request is initiated, it cannot be canceled,
|
||||||
|
* and your principal will continue to earn interest until the process is completed.
|
||||||
|
*/
|
||||||
|
submitStakeRedeem(params: SubmitStakeRedeemParams): Promise<
|
||||||
|
APIResponseV3WithTime<{
|
||||||
|
orderId: string;
|
||||||
|
orderLinkId: string;
|
||||||
|
}>
|
||||||
|
> {
|
||||||
|
return this.postPrivate('/v5/earn/place-order', params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Stake/Redeem Order History
|
||||||
|
*
|
||||||
|
* INFO: API key needs "Earn" permission
|
||||||
|
*
|
||||||
|
* Note: Either orderId or orderLinkId is required. If both are passed,
|
||||||
|
* make sure they're matched, otherwise returning empty result
|
||||||
|
*/
|
||||||
|
getEarnOrderHistory(params: GetEarnOrderHistoryParams): Promise<
|
||||||
|
APIResponseV3WithTime<{
|
||||||
|
list: EarnOrderHistory[];
|
||||||
|
}>
|
||||||
|
> {
|
||||||
|
return this.getPrivate('/v5/earn/order', params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Staked Position
|
||||||
|
*
|
||||||
|
* INFO: API key needs "Earn" permission
|
||||||
|
*
|
||||||
|
* Note: Fully redeemed position is also returned in the response
|
||||||
|
*/
|
||||||
|
getEarnPosition(params: GetEarnPositionParams): Promise<
|
||||||
|
APIResponseV3WithTime<{
|
||||||
|
list: EarnPosition[];
|
||||||
|
}>
|
||||||
|
> {
|
||||||
|
return this.getPrivate('/v5/earn/position', params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/types/request/v5-earn.ts
Normal file
21
src/types/request/v5-earn.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
export interface SubmitStakeRedeemParams {
|
||||||
|
category: string;
|
||||||
|
orderType: 'Stake' | 'Redeem';
|
||||||
|
accountType: 'FUND' | 'UNIFIED';
|
||||||
|
amount: string;
|
||||||
|
coin: string;
|
||||||
|
productId: string;
|
||||||
|
orderLinkId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetEarnOrderHistoryParams {
|
||||||
|
category: string;
|
||||||
|
orderId?: string;
|
||||||
|
orderLinkId?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetEarnPositionParams {
|
||||||
|
category: string;
|
||||||
|
productId?: string;
|
||||||
|
coin?: string;
|
||||||
|
}
|
||||||
30
src/types/response/v5-earn.ts
Normal file
30
src/types/response/v5-earn.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
export interface EarnProduct {
|
||||||
|
category: string;
|
||||||
|
estimateApr: string;
|
||||||
|
coin: string;
|
||||||
|
minStakeAmount: string;
|
||||||
|
maxStakeAmount: string;
|
||||||
|
precision: string;
|
||||||
|
productId: string;
|
||||||
|
status: 'Available' | 'NotAvailable';
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EarnOrderHistory {
|
||||||
|
coin: string;
|
||||||
|
orderValue: string;
|
||||||
|
orderType: 'Redeem' | 'Stake';
|
||||||
|
orderId: string;
|
||||||
|
orderLinkId: string;
|
||||||
|
status: 'Success' | 'Fail' | 'Pending';
|
||||||
|
createdAt: string;
|
||||||
|
productId: string;
|
||||||
|
updatedAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EarnPosition {
|
||||||
|
coin: string;
|
||||||
|
productId: string;
|
||||||
|
amount: string;
|
||||||
|
totalPnl: string;
|
||||||
|
claimableYield: string;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user