Skip to content

Commit

Permalink
Merge pull request #1897 from idea2409/fwx
Browse files Browse the repository at this point in the history
update trade volume api FWX
  • Loading branch information
dtmkeng authored Sep 16, 2024
2 parents 53f4a2e + 70d835a commit be0609a
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions dexs/fwx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,26 @@ const fetch = (chain: Chain) => {
const formattedDate = date.toISOString().replace(/\.(\d{3})Z$/, ".$1Z");

// * call api for daily volume
const tradingVolumeRes = await httpPost(endpoints.tradingVolume, {
const tradingVolumePerpRes = await httpPost(endpoints.tradingVolume, {
from_date: formattedDate,
to_date: formattedDate,
chain_id: CHAIN_ID[chain],
is_perp: true,
});
const tradingVolume = tradingVolumeRes as IRes;
const dailyVolumeData = tradingVolume?.data.find(
const tradingVolumePerp = tradingVolumePerpRes as IRes;
const dailyPerpVolumeData = tradingVolumePerp?.data.find(
(x: IDailyData) =>
new Date(x.date).getTime() == new Date(formattedDate).getTime()
);

const tradingVolumeAphRes = await httpPost(endpoints.tradingVolume, {
from_date: formattedDate,
to_date: formattedDate,
chain_id: CHAIN_ID[chain],
is_perp: false,
});
const tradingVolumeAph = tradingVolumeAphRes as IRes;
const dailyAphVolumeData = tradingVolumeAph?.data.find(
(x: IDailyData) =>
new Date(x.date).getTime() == new Date(formattedDate).getTime()
);
Expand All @@ -57,9 +70,12 @@ const fetch = (chain: Chain) => {
);

return {
dailyVolume: convertStringNumber(dailyVolumeData?.total || "0"),
dailyVolume: convertStringNumber(
BigInt(dailyPerpVolumeData?.total || "0") +
BigInt(dailyAphVolumeData?.total || "0")
),
dailyOpenInterest: convertStringNumber(
dailyOpenInterestData?.total || "0"
BigInt(dailyOpenInterestData?.total || "0")
),
timestamp: timestamp,
};
Expand All @@ -82,8 +98,7 @@ const adapter: SimpleAdapter = {
export default adapter;

// devide by 1e18
function convertStringNumber(inputString: string) {
let number = BigInt(inputString);
function convertStringNumber(number: bigint) {
const divisor = BigInt(1e18);
let integerPart = number / divisor;
let fractionalPart = number % divisor;
Expand Down

0 comments on commit be0609a

Please sign in to comment.