Skip to content

Commit

Permalink
Merge pull request #2323 from lnfi-network/master
Browse files Browse the repository at this point in the history
add lnexchange
  • Loading branch information
dtmkeng authored Jan 17, 2025
2 parents dd88970 + 13c14a5 commit e4cd04b
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
36 changes: 36 additions & 0 deletions dexs/lnexchange-perp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { SimpleAdapter } from "../../adapters/types";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import { httpPost } from "../../utils/fetchURL";
import BigNumber from "bignumber.js";
import { CHAIN } from "../../helpers/chains";

const URL =
"https://test-futures-api.ln.exchange/napi/common/getDayTradeAmount";

interface Response {
dayNtlVlm: number;
}
const fetch = async (timestamp: number) => {
const respose: Response[] = (
await httpPost(URL, { dayTimestamp: timestamp * 1000 })
).data;
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
const dailyVolume = respose.reduce((acc, item) => {
return acc.plus(item.dayNtlVlm);
}, new BigNumber(0));
return {
dailyVolume: dailyVolume?.toString(),
timestamp: dayTimestamp,
};
};

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.BITCOIN]: {
fetch,
start: "2024-10-20",
},
},
};

export default adapter;
36 changes: 36 additions & 0 deletions dexs/lnexchange-spot/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { SimpleAdapter } from "../../adapters/types";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import { httpPost } from "../../utils/fetchURL";
import BigNumber from "bignumber.js";
import { CHAIN } from "../../helpers/chains";

const URL =
"https://test-spots-api.ln.exchange/napi/common/getDayTradeAmount";

interface Response {
dayNtlVlm: number;
}
const fetch = async (timestamp: number) => {
const respose: Response[] = (
await httpPost(URL, { dayTimestamp: timestamp * 1000 })
).data;
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
const dailyVolume = respose.reduce((acc, item) => {
return acc.plus(item.dayNtlVlm);
}, new BigNumber(0));
return {
dailyVolume: dailyVolume?.toString(),
timestamp: dayTimestamp,
};
};

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.BITCOIN]: {
fetch,
start: "2024-08-30",
},
},
};

export default adapter;
34 changes: 34 additions & 0 deletions fees/lnexchange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { CHAIN } from "../helpers/chains";
import { Adapter, FetchOptions } from "../adapters/types";
import { httpPost } from "../utils/fetchURL";

const fetchFees = async (options: FetchOptions) => {
const respose = await httpPost(
`https://test-futures-api.ln.exchange/napi/common/getTradeFee`,
{
startTimestamp: options.startTimestamp * 1000,
endTimestamp: options.endTimestamp * 1000,
}
);

const dailyFees = respose.data.dailyFees;
const totalFees = respose.data.totalFees;

return {
dailyFees,
dailyRevenue: dailyFees,
totalFees,
totalRevenue: totalFees,
};
};

const adapter: Adapter = {
version: 2,
adapter: {
[CHAIN.BITCOIN]: {
fetch: fetchFees,
start: "2024-10-20",
},
},
};
export default adapter;

0 comments on commit e4cd04b

Please sign in to comment.