Skip to content

Commit

Permalink
total earnings for a day
Browse files Browse the repository at this point in the history
  • Loading branch information
poly-rodr committed Apr 10, 2024
1 parent f0dcf2c commit c846ff2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
28 changes: 28 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
RewardsPercentages,
MarketReward,
UserRewardsEarning,
TotalUserEarning,
} from "./types";
import { createL1Headers, createL2Headers } from "./headers";
import {
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -704,6 +706,32 @@ export class ClobClient {
return results;
}

public async getTotalEarningsForUserForDay(date: string): Promise<TotalUserEarning[]> {
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 = "",
Expand Down
1 change: 1 addition & 0 deletions src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c846ff2

Please sign in to comment.