From c846ff2582e5c57252254375ff1f29feac86739b Mon Sep 17 00:00:00 2001 From: Rodrigo <95635797+poly-rodr@users.noreply.github.com> Date: Wed, 10 Apr 2024 10:24:46 -0300 Subject: [PATCH] total earnings for a day --- examples/rewards.ts | 4 ++++ src/client.ts | 28 ++++++++++++++++++++++++++++ src/endpoints.ts | 1 + src/types.ts | 8 ++++++++ 4 files changed, 41 insertions(+) diff --git a/examples/rewards.ts b/examples/rewards.ts index 494cd9c..af2d4ac 100644 --- a/examples/rewards.ts +++ b/examples/rewards.ts @@ -22,6 +22,10 @@ async function main() { "today earnings", await clobClient.getEarningsForUserForDay("2024-04-09" /* UTC TIME */), ); + console.log( + "total earnings", + await clobClient.getTotalEarningsForUserForDay("2024-04-09" /* UTC TIME */), + ); console.log("rewards percentages", await clobClient.getRewardPercentages()); console.log("current rewards", await clobClient.getCurrentRewards()); console.log( diff --git a/src/client.ts b/src/client.ts index d484833..6221cd8 100644 --- a/src/client.ts +++ b/src/client.ts @@ -37,6 +37,7 @@ import { RewardsPercentages, MarketReward, UserRewardsEarning, + TotalUserEarning, } from "./types"; import { createL1Headers, createL2Headers } from "./headers"; import { @@ -98,6 +99,7 @@ import { GET_REWARDS_MARKETS_CURRENT, GET_REWARDS_MARKETS, GET_REWARDS_EARNINGS_PERCENTAGES, + GET_TOTAL_EARNINGS_FOR_USER_FOR_DAY, } from "./endpoints"; import { OrderBuilder } from "./order-builder/builder"; import { END_CURSOR, INITIAL_CURSOR } from "./constants"; @@ -704,6 +706,32 @@ export class ClobClient { return results; } + public async getTotalEarningsForUserForDay(date: string): Promise { + this.canL2Auth(); + + const endpoint = GET_TOTAL_EARNINGS_FOR_USER_FOR_DAY; + const headerArgs = { + method: GET, + requestPath: endpoint, + }; + + const headers = await createL2Headers( + this.signer as Wallet | JsonRpcSigner, + this.creds as ApiKeyCreds, + headerArgs, + ); + + const params = { + date, + signature_type: this.orderBuilder.signatureType, + }; + + return await this.get(`${this.host}${endpoint}`, { + headers, + params, + }); + } + public async getUserEarningsAndMarketsConfig( date: string, order_by = "", diff --git a/src/endpoints.ts b/src/endpoints.ts index 9138568..7114962 100644 --- a/src/endpoints.ts +++ b/src/endpoints.ts @@ -51,6 +51,7 @@ export const GET_MARKET_TRADES_EVENTS = "/live-activity/events/"; // Rewards export const GET_EARNINGS_FOR_USER_FOR_DAY = "/rewards/user"; +export const GET_TOTAL_EARNINGS_FOR_USER_FOR_DAY = "/rewards/user/total"; export const GET_LIQUIDITY_REWARD_PERCENTAGES = "/rewards/user/percentages"; export const GET_REWARDS_MARKETS_CURRENT = "/rewards/markets/current"; export const GET_REWARDS_MARKETS = "/rewards/markets/"; diff --git a/src/types.ts b/src/types.ts index 5c65b84..aab5b3a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -400,6 +400,14 @@ export interface UserEarning { asset_rate: number; } +export interface TotalUserEarning { + date: string; + asset_address: string; + maker_address: string; + earnings: number; + asset_rate: number; +} + export interface RewardsPercentages { [market: string]: number; }