Skip to content

Commit

Permalink
Merge pull request #2442 from mars-protocol/mars-perp-api-fixes
Browse files Browse the repository at this point in the history
mars-perp API endpoint adjustments
  • Loading branch information
dtmkeng authored Feb 21, 2025
2 parents 43a3ac2 + df1520c commit 0845261
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions dexs/mars-perp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { CHAIN } from "../../helpers/chains";

const fetch = async (options: FetchOptions): Promise<FetchResult> => {
const { fromTimestamp } = options;
const perpsInfoApi = `https://backend.prod.mars-dev.net/v2/perps_overview?chain=neutron&days=30&response_type=global`;
const perpsInfoApi =
"https://backend.prod.mars-dev.net/v2/perps_overview?chain=neutron&days=30&response_type=global&granularity=day";
const perpsVolumeData = await axios(perpsInfoApi);
const globalOverview = perpsVolumeData.data.global_overview;

Expand All @@ -21,20 +22,20 @@ const fetch = async (options: FetchOptions): Promise<FetchResult> => {
if (globalOverview) {
let foundLatestData = false;

globalOverview.daily_trading_volume.forEach((volumeData, index) => {
globalOverview.trading_volume.forEach((volumeData, index) => {
const dataTimestamp = Math.round(
new Date(volumeData.date).getTime() / 1000
);
if (dataTimestamp <= fromTimestamp && !foundLatestData) {
const nextIndex = index + 1;
last24HourVolume = convertToUsd(volumeData.value);
fetchTimestamp = dataTimestamp;

last24HourFees = convertToUsd(
globalOverview.fees.trading_fee[index].value -
Number(globalOverview.fees.trading_fee[nextIndex].value ?? 0)
globalOverview.fees.realized_trading_fee[index].value -
Number(
globalOverview.fees.realized_trading_fee[nextIndex].value ?? 0
)
);

last24HourRevenue = last24HourFees * 0.25;
last24HoursShortOpenInterest = convertToUsd(
globalOverview.open_interest.short[index].value
Expand Down

0 comments on commit 0845261

Please sign in to comment.