Skip to content

Commit

Permalink
Merge branch 'main' into feat/OP-5033-real-time-trades
Browse files Browse the repository at this point in the history
# Conflicts:
#	package-lock.json
#	package.json
  • Loading branch information
TheJuze committed Feb 22, 2024
2 parents 89f15be + 6d03092 commit 48d0692
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package",
"name": "@electra.finance/sdk",
"version": "0.2.4-rc6",
"version": "0.2.5",
"description": "Electra finance SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",
Expand Down
38 changes: 37 additions & 1 deletion src/services/PriceFeed/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fetchWithValidation } from 'simple-typed-fetch';
import type { BasicAuthCredentials } from '../../types.js';
import { allTickersSchema, candlesSchema } from './schemas/';
import { allTickersSchema, candlesSchema, leaderboardSchema, statisticsOverviewSchema, topPairsSchema, winnersSchema } from './schemas/';
import { PriceFeedWS } from './ws/index.js';

class PriceFeed {
Expand All @@ -24,6 +24,10 @@ class PriceFeed {

this.getCandles = this.getCandles.bind(this);
this.getAllTickers = this.getAllTickers.bind(this);
this.getLeaderboard = this.getLeaderboard.bind(this);
this.getStatisticsOverview = this.getStatisticsOverview.bind(this);
this.getTopPairs = this.getTopPairs.bind(this);
this.getWinners = this.getWinners.bind(this);
}

get basicAuthHeaders() {
Expand Down Expand Up @@ -64,6 +68,38 @@ class PriceFeed {
);
}

getLeaderboard = () => {
return fetchWithValidation(
`${this.statisticsUrl}/futures/addresses`,
leaderboardSchema,
{ headers: this.basicAuthHeaders }
);
}

getStatisticsOverview = () => {
return fetchWithValidation(
`${this.statisticsUrl}/overview?exchange=ALL`,
statisticsOverviewSchema,
{ headers: this.basicAuthHeaders }
);
}

getTopPairs = () => {
return fetchWithValidation(
`${this.statisticsUrl}/top-pairs?exchange=ALL`,
topPairsSchema,
{ headers: this.basicAuthHeaders }
);
}

getWinners = () => {
return fetchWithValidation(
`${this.statisticsUrl}/futures/winners`,
winnersSchema,
{ headers: this.basicAuthHeaders }
);
}

get wsUrl() {
const url = new URL(this.apiUrl);
const wsProtocol = url.protocol === 'https:' ? 'wss' : 'ws';
Expand Down
4 changes: 4 additions & 0 deletions src/services/PriceFeed/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
export { default as candlesSchema } from './candlesSchema.js';
export { allTickersSchema } from './allTickersSchema.js';
export { leaderboardSchema } from './leaderboardSchema.js'
export { statisticsOverviewSchema } from './statisticsOverviewSchema.js'
export { topPairsSchema } from './topPairsSchema.js';
export { winnersSchema } from './winnersSchema.js'
13 changes: 13 additions & 0 deletions src/services/PriceFeed/schemas/leaderboardSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { z } from 'zod';

export const leaderboardSchema = z
.object({
address: z.string(),
totalVolume: z.number(),
todayVolume: z.number(),
totalPnl: z.number(),
todayPnl: z.number(),
totalRoi: z.number(),
todayRoi: z.number(),
})
.array();
11 changes: 11 additions & 0 deletions src/services/PriceFeed/schemas/statisticsOverviewSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z } from 'zod';

export const statisticsOverviewSchema = z
.object({
time: z.number(),
statisticsOverview: z.object({
volume24h: z.number(),
volume7d: z.number(),
volumeAllTime: z.number()
})
});
14 changes: 14 additions & 0 deletions src/services/PriceFeed/schemas/topPairsSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { z } from 'zod';

export const topPairsSchema = z.object({
time: z.number(),
topPairs: z.array(
z.object({
assetPair: z.string(),
statisticsOverview: z.object({
volume24h: z.number(),
volume7d: z.number()
})
})
)
});
20 changes: 20 additions & 0 deletions src/services/PriceFeed/schemas/winnersSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { z } from 'zod';

export const winnersSchema = z.object({
bestTrade: z.object({
address: z.string(),
instrument: z.string(),
leverage: z.number(),
pnl: z.number(),
side: z.string()
}),
worstTrade: z.object({
address: z.string(),
instrument: z.string(),
leverage: z.number(),
pnl: z.number(),
side: z.string()
}),
bestPnl: z.object({ address: z.string(), pnl: z.number() }),
worstPnl: z.object({ address: z.string(), pnl: z.number() })
});

0 comments on commit 48d0692

Please sign in to comment.