From a782fc8c66933330a6f04729c728ae256065f951 Mon Sep 17 00:00:00 2001 From: Sebastian Boehler Date: Tue, 2 Apr 2024 21:51:44 +0200 Subject: [PATCH 1/5] chore: add simple earn endpoints --- src/main-client.ts | 107 +++++++++++++++++++++++++++------- src/types/simpleEarn.ts | 126 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 211 insertions(+), 22 deletions(-) create mode 100644 src/types/simpleEarn.ts diff --git a/src/main-client.ts b/src/main-client.ts index 6cfa0c86..5270c2fc 100644 --- a/src/main-client.ts +++ b/src/main-client.ts @@ -187,7 +187,6 @@ import { EnableConvertSubAccountParams, AcceptQuoteRequestParams, ReplaceSpotOrderParams, - ReplaceSpotOrderResultError, ReplaceSpotOrderResultSuccess, NewSpotSOROrderParams, SOROrderResponseFull, @@ -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( @@ -1145,6 +1158,77 @@ export class MainClient extends BaseRestClient { ); } + /** + * + * Simple earn Endpoints + * + **/ + + getFlexibleSavingProducts( + params: SimpleEarnProductListParams, + ): Promise { + return this.getPrivate( + `/sapi/v1/simple-earn/flexible/list?${serialiseParams(params)}`, + ); + } + + getSimpleEarnLockedProductList( + params: SimpleEarnProductListParams, + ): Promise { + return this.getPrivate( + `/sapi/v1/simple-earn/locked/list?${serialiseParams(params)}`, + ); + } + + purchaseFlexibleProduct( + params: SimpleEarnSubscribeProductParams, + ): Promise { + return this.postPrivate(`/sapi/v1/simple-earn/flexible/subscribe`, params); + } + + subscribeSimpleEarnLockedProduct( + params: SimpleEarnSubscribeProductParams, + ): Promise { + return this.postPrivate(`/sapi/v1/simple-earn/locked/subscribe`, params); + } + + redeemLockedProduct( + params: SimpleEarnRedeemParams, + ): Promise { + return this.postPrivate(`/sapi/v1/simple-earn/locked/redeem`, params); + } + + redeemFlexibleProduct( + params: SimpleEarnRedeemParams, + ): Promise { + return this.postPrivate(`/sapi/v1/simple-earn/flexible/redeem`, params); + } + + getFlexibleProductPosition( + params: SimpleEarnFlexibleProductPositionParams, + ): Promise { + return this.getPrivate( + `/sapi/v1/simple-earn/flexible/position?${serialiseParams(params)}`, + ); + } + + getLockedProductPosition( + params: SimpleEarnLockedProductPositionParams, + ): Promise { + return this.getPrivate( + `/sapi/v1/simple-earn/locked/position?${serialiseParams(params)}`, + ); + } + + getSimpleEarnAccount(params: { + recvWindow?: number; + timestamp: number; + }): Promise { + return this.getPrivate( + `/sapi/v1/simple-earn/account?${serialiseParams(params)}`, + ); + } + /** * * Staking Endpoints @@ -1188,27 +1272,6 @@ export class MainClient extends BaseRestClient { * Savings Endpoints * **/ - getFlexibleSavingProducts( - params: FlexibleSavingBasicParams, - ): Promise { - return this.getPrivate(`sapi/v1/simple-earn/flexible/list`, params); - } - - purchaseFlexibleProduct( - params: PurchaseFlexibleProductParams, - ): Promise { - 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 { - return this.getPrivate(`sapi/v1/simple-earn/flexible/position`, params); - } getLeftDailyPurchaseQuotaFlexibleProduct(params: { productId: string; diff --git a/src/types/simpleEarn.ts b/src/types/simpleEarn.ts new file mode 100644 index 00000000..efc0f694 --- /dev/null +++ b/src/types/simpleEarn.ts @@ -0,0 +1,126 @@ +export interface SimpleEarnProductListParams { + asset?: string; + current?: number; + size?: number; + recvWindow?: number; + timestamp: number; +} + +export interface SimpleEarnFlexibleProduct { + asset: string; + latestAnnualInterestRate: string; + tierAnnualPercentageRate: Record; + 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'; + recvWindow?: number; + timestamp: number; +} + +export interface SimpleEarnSubscribeFlexibleProductResponse { + purchaseId: string; + success: boolean; +} + +export interface SimpleEarnSubscribeLockedProductResponse { + purchaseId: string; + positionId: string; + success: boolean; +} + +export interface SimpleEarnRedeemParams { + positionId: string; + recvWindow?: number; + timestamp: number; +} + +export interface SimpleEarnRedeemResponse { + success: boolean; + redeemId: string; +} + +export interface SimpleEarnFlexibleProductPositionParams { + asset?: string; + productId?: string; + current?: number; + size?: number; + recvWindow?: number; + timestamp: number; +} + +export interface SimpleEarnLockedProductPositionParams + extends SimpleEarnFlexibleProductPositionParams { + 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; +} From 090bdb1b676ac784e1c12de9d5714ca9114797bd Mon Sep 17 00:00:00 2001 From: Sebastian Boehler Date: Tue, 2 Apr 2024 21:53:17 +0200 Subject: [PATCH 2/5] chore: version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e37e94ef..3c2d2223 100644 --- a/package.json +++ b/package.json @@ -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", From 45350c1c767a38ad0d71c3dbb8208b254f476b44 Mon Sep 17 00:00:00 2001 From: Sebastian Boehler Date: Wed, 3 Apr 2024 09:41:16 +0200 Subject: [PATCH 3/5] fix: query params --- src/main-client.ts | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/main-client.ts b/src/main-client.ts index 5270c2fc..e04c860b 100644 --- a/src/main-client.ts +++ b/src/main-client.ts @@ -1167,17 +1167,13 @@ export class MainClient extends BaseRestClient { getFlexibleSavingProducts( params: SimpleEarnProductListParams, ): Promise { - return this.getPrivate( - `/sapi/v1/simple-earn/flexible/list?${serialiseParams(params)}`, - ); + return this.getPrivate(`/sapi/v1/simple-earn/flexible/list`, params); } getSimpleEarnLockedProductList( params: SimpleEarnProductListParams, ): Promise { - return this.getPrivate( - `/sapi/v1/simple-earn/locked/list?${serialiseParams(params)}`, - ); + return this.getPrivate(`/sapi/v1/simple-earn/locked/list`, params); } purchaseFlexibleProduct( @@ -1207,26 +1203,20 @@ export class MainClient extends BaseRestClient { getFlexibleProductPosition( params: SimpleEarnFlexibleProductPositionParams, ): Promise { - return this.getPrivate( - `/sapi/v1/simple-earn/flexible/position?${serialiseParams(params)}`, - ); + return this.getPrivate(`/sapi/v1/simple-earn/flexible/position`, params); } getLockedProductPosition( params: SimpleEarnLockedProductPositionParams, ): Promise { - return this.getPrivate( - `/sapi/v1/simple-earn/locked/position?${serialiseParams(params)}`, - ); + return this.getPrivate(`/sapi/v1/simple-earn/locked/position`, params); } getSimpleEarnAccount(params: { recvWindow?: number; timestamp: number; }): Promise { - return this.getPrivate( - `/sapi/v1/simple-earn/account?${serialiseParams(params)}`, - ); + return this.getPrivate(`/sapi/v1/simple-earn/account`, params); } /** From dffb6f0faae15874971b5a0ff536e70fcb4ce19a Mon Sep 17 00:00:00 2001 From: Sebastian Boehler Date: Wed, 3 Apr 2024 20:14:54 +0200 Subject: [PATCH 4/5] fix: remove signature params as it is handled --- src/types/simpleEarn.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/types/simpleEarn.ts b/src/types/simpleEarn.ts index efc0f694..76ac3c14 100644 --- a/src/types/simpleEarn.ts +++ b/src/types/simpleEarn.ts @@ -2,8 +2,6 @@ export interface SimpleEarnProductListParams { asset?: string; current?: number; size?: number; - recvWindow?: number; - timestamp: number; } export interface SimpleEarnFlexibleProduct { @@ -56,8 +54,6 @@ export interface SimpleEarnSubscribeProductParams { amount: number; autoSubscribe?: boolean; sourceAccount?: 'SPOT' | 'FUND' | 'ALL'; - recvWindow?: number; - timestamp: number; } export interface SimpleEarnSubscribeFlexibleProductResponse { @@ -73,8 +69,6 @@ export interface SimpleEarnSubscribeLockedProductResponse { export interface SimpleEarnRedeemParams { positionId: string; - recvWindow?: number; - timestamp: number; } export interface SimpleEarnRedeemResponse { @@ -87,8 +81,6 @@ export interface SimpleEarnFlexibleProductPositionParams { productId?: string; current?: number; size?: number; - recvWindow?: number; - timestamp: number; } export interface SimpleEarnLockedProductPositionParams From 9cb88ba9f232be7a78b989df65a0d26876e0a206 Mon Sep 17 00:00:00 2001 From: Sebastian Boehler Date: Wed, 3 Apr 2024 20:48:27 +0200 Subject: [PATCH 5/5] chore: optional params and cleaner type --- src/main-client.ts | 15 ++++++--------- src/types/simpleEarn.ts | 7 +++++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main-client.ts b/src/main-client.ts index e04c860b..d5dbdcee 100644 --- a/src/main-client.ts +++ b/src/main-client.ts @@ -1165,13 +1165,13 @@ export class MainClient extends BaseRestClient { **/ getFlexibleSavingProducts( - params: SimpleEarnProductListParams, + params?: SimpleEarnProductListParams, ): Promise { return this.getPrivate(`/sapi/v1/simple-earn/flexible/list`, params); } getSimpleEarnLockedProductList( - params: SimpleEarnProductListParams, + params?: SimpleEarnProductListParams, ): Promise { return this.getPrivate(`/sapi/v1/simple-earn/locked/list`, params); } @@ -1201,22 +1201,19 @@ export class MainClient extends BaseRestClient { } getFlexibleProductPosition( - params: SimpleEarnFlexibleProductPositionParams, + params?: SimpleEarnFlexibleProductPositionParams, ): Promise { return this.getPrivate(`/sapi/v1/simple-earn/flexible/position`, params); } getLockedProductPosition( - params: SimpleEarnLockedProductPositionParams, + params?: SimpleEarnLockedProductPositionParams, ): Promise { return this.getPrivate(`/sapi/v1/simple-earn/locked/position`, params); } - getSimpleEarnAccount(params: { - recvWindow?: number; - timestamp: number; - }): Promise { - return this.getPrivate(`/sapi/v1/simple-earn/account`, params); + getSimpleEarnAccount(): Promise { + return this.getPrivate(`/sapi/v1/simple-earn/account`); } /** diff --git a/src/types/simpleEarn.ts b/src/types/simpleEarn.ts index 76ac3c14..5e7edbf6 100644 --- a/src/types/simpleEarn.ts +++ b/src/types/simpleEarn.ts @@ -83,8 +83,11 @@ export interface SimpleEarnFlexibleProductPositionParams { size?: number; } -export interface SimpleEarnLockedProductPositionParams - extends SimpleEarnFlexibleProductPositionParams { +export interface SimpleEarnLockedProductPositionParams { + asset?: string; + productId?: string; + current?: number; + size?: number; positionId?: string; }