Skip to content

Commit

Permalink
Merge pull request #419 from SebastianBoehler/master
Browse files Browse the repository at this point in the history
v2.10.4: add some missing simple earn endpoints
  • Loading branch information
tiagosiebler authored Apr 3, 2024
2 parents 9f528a6 + 9cb88ba commit 05dd466
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "binance",
"version": "2.10.3",
"version": "2.10.4",
"description": "Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & end-to-end tests.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
94 changes: 72 additions & 22 deletions src/main-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ import {
EnableConvertSubAccountParams,
AcceptQuoteRequestParams,
ReplaceSpotOrderParams,
ReplaceSpotOrderResultError,
ReplaceSpotOrderResultSuccess,
NewSpotSOROrderParams,
SOROrderResponseFull,
Expand All @@ -204,6 +203,20 @@ import {
} from './util/requestUtils';

import BaseRestClient from './util/BaseRestClient';
import {
SimpleEarnAccountResponse,
SimpleEarnFlexibleProductListResponse,
SimpleEarnFlexibleProductPositionParams,
SimpleEarnLockedProductListResponse,
SimpleEarnLockedProductPositionParams,
SimpleEarnLockedProductPositionResponse,
SimpleEarnProductListParams,
SimpleEarnRedeemParams,
SimpleEarnRedeemResponse,
SimpleEarnSubscribeFlexibleProductResponse,
SimpleEarnSubscribeLockedProductResponse,
SimpleEarnSubscribeProductParams,
} from './types/simpleEarn';

export class MainClient extends BaseRestClient {
constructor(
Expand Down Expand Up @@ -1145,6 +1158,64 @@ export class MainClient extends BaseRestClient {
);
}

/**
*
* Simple earn Endpoints
*
**/

getFlexibleSavingProducts(
params?: SimpleEarnProductListParams,
): Promise<SimpleEarnFlexibleProductListResponse> {
return this.getPrivate(`/sapi/v1/simple-earn/flexible/list`, params);
}

getSimpleEarnLockedProductList(
params?: SimpleEarnProductListParams,
): Promise<SimpleEarnLockedProductListResponse> {
return this.getPrivate(`/sapi/v1/simple-earn/locked/list`, params);
}

purchaseFlexibleProduct(
params: SimpleEarnSubscribeProductParams,
): Promise<SimpleEarnSubscribeFlexibleProductResponse> {
return this.postPrivate(`/sapi/v1/simple-earn/flexible/subscribe`, params);
}

subscribeSimpleEarnLockedProduct(
params: SimpleEarnSubscribeProductParams,
): Promise<SimpleEarnSubscribeLockedProductResponse> {
return this.postPrivate(`/sapi/v1/simple-earn/locked/subscribe`, params);
}

redeemLockedProduct(
params: SimpleEarnRedeemParams,
): Promise<SimpleEarnRedeemResponse> {
return this.postPrivate(`/sapi/v1/simple-earn/locked/redeem`, params);
}

redeemFlexibleProduct(
params: SimpleEarnRedeemParams,
): Promise<SimpleEarnRedeemResponse> {
return this.postPrivate(`/sapi/v1/simple-earn/flexible/redeem`, params);
}

getFlexibleProductPosition(
params?: SimpleEarnFlexibleProductPositionParams,
): Promise<SimpleEarnFlexibleProductListResponse> {
return this.getPrivate(`/sapi/v1/simple-earn/flexible/position`, params);
}

getLockedProductPosition(
params?: SimpleEarnLockedProductPositionParams,
): Promise<SimpleEarnLockedProductPositionResponse> {
return this.getPrivate(`/sapi/v1/simple-earn/locked/position`, params);
}

getSimpleEarnAccount(): Promise<SimpleEarnAccountResponse> {
return this.getPrivate(`/sapi/v1/simple-earn/account`);
}

/**
*
* Staking Endpoints
Expand Down Expand Up @@ -1188,27 +1259,6 @@ export class MainClient extends BaseRestClient {
* Savings Endpoints
*
**/
getFlexibleSavingProducts(
params: FlexibleSavingBasicParams,
): Promise<StakingProduct[]> {
return this.getPrivate(`sapi/v1/simple-earn/flexible/list`, params);
}

purchaseFlexibleProduct(
params: PurchaseFlexibleProductParams,
): Promise<PurchaseFlexibleProductResponse> {
return this.postPrivate(`sapi/v1/simple-earn/flexible/subscribe`, params);
}

redeemFlexibleProduct(params: RedeemFlexibleProductParams): Promise<{}> {
return this.postPrivate(`sapi/v1/simple-earn/flexible/redeem`, params);
}

getFlexibleProductPosition(params: {
asset?: string;
}): Promise<StakingProduct[]> {
return this.getPrivate(`sapi/v1/simple-earn/flexible/position`, params);
}

getLeftDailyPurchaseQuotaFlexibleProduct(params: {
productId: string;
Expand Down
121 changes: 121 additions & 0 deletions src/types/simpleEarn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
export interface SimpleEarnProductListParams {
asset?: string;
current?: number;
size?: number;
}

export interface SimpleEarnFlexibleProduct {
asset: string;
latestAnnualInterestRate: string;
tierAnnualPercentageRate: Record<string, number>;
airDropPercentageRate: string;
canPurchase: boolean;
canRedeem: boolean;
isSoldOut: boolean;
hot: boolean;
minPurchaseAmount: string;
productId: string;
subscriptionStartTime: number;
status: string;
}

export interface SimpleEarnFlexibleProductListResponse {
rows: SimpleEarnFlexibleProduct[];
total: number;
}

export interface SimpleEarnLockedProduct {
projectId: string;
detail: {
asset: string;
rewardAsset: string;
duration: number;
renewable: boolean;
isSoldOut: boolean;
apr: string;
status: string;
subscriptionStartTime: number;
extraRewardAsset: string;
extraRewardAPR: string;
};
quota: {
totalPersonalQuota: string;
minimum: string;
};
}

export interface SimpleEarnLockedProductListResponse {
rows: SimpleEarnLockedProduct[];
total: number;
}

export interface SimpleEarnSubscribeProductParams {
productId: string;
amount: number;
autoSubscribe?: boolean;
sourceAccount?: 'SPOT' | 'FUND' | 'ALL';
}

export interface SimpleEarnSubscribeFlexibleProductResponse {
purchaseId: string;
success: boolean;
}

export interface SimpleEarnSubscribeLockedProductResponse {
purchaseId: string;
positionId: string;
success: boolean;
}

export interface SimpleEarnRedeemParams {
positionId: string;
}

export interface SimpleEarnRedeemResponse {
success: boolean;
redeemId: string;
}

export interface SimpleEarnFlexibleProductPositionParams {
asset?: string;
productId?: string;
current?: number;
size?: number;
}

export interface SimpleEarnLockedProductPositionParams {
asset?: string;
productId?: string;
current?: number;
size?: number;
positionId?: string;
}

export interface SimpleEarnLockedProductPosition {
positionId: string;
projectId: string;
asset: string;
amount: string;
purchaseTime: string;
duration: string;
accrualDays: string;
rewardAsset: string;
APY: string;
isRenewable: boolean;
isAutoRenew: boolean;
redeemDate: string;
}

export interface SimpleEarnLockedProductPositionResponse {
rows: SimpleEarnLockedProductPosition[];
total: number;
}

export interface SimpleEarnAccountResponse {
totalAmountInBTC: string;
totalAmountInUSDT: string;
totalFlexibleAmountInBTC: string;
totalFlexibleAmountInUSDT: string;
totalLockedinBTC: string;
totalLockedinUSDT: string;
}

0 comments on commit 05dd466

Please sign in to comment.