@gmx-io/sdk 1.5.0-alpha-2 → 1.5.0-alpha-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/src/clients/v2/index.js +5 -1
- package/build/cjs/src/configs/api.js +10 -6
- package/build/cjs/src/utils/markets/utils.js +15 -4
- package/build/esm/src/clients/v2/index.js +5 -1
- package/build/esm/src/configs/api.js +8 -5
- package/build/esm/src/utils/markets/utils.js +15 -4
- package/build/types/src/configs/api.d.ts +1 -0
- package/build/types/src/utils/markets/types.d.ts +8 -2
- package/package.json +1 -1
|
@@ -8,9 +8,13 @@ const api_3 = require("../../utils/orders/api");
|
|
|
8
8
|
const api_4 = require("../../utils/positions/api");
|
|
9
9
|
class GmxApiSdk {
|
|
10
10
|
constructor({ chainId }) {
|
|
11
|
+
const apiUrl = (0, api_1.getApiUrl)(chainId);
|
|
12
|
+
if (!apiUrl) {
|
|
13
|
+
throw new Error("api is not supported for current chainId");
|
|
14
|
+
}
|
|
11
15
|
this.ctx = {
|
|
12
16
|
chainId,
|
|
13
|
-
api: new http_1.HttpClient(
|
|
17
|
+
api: new http_1.HttpClient(apiUrl),
|
|
14
18
|
};
|
|
15
19
|
}
|
|
16
20
|
fetchMarketsInfo() {
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getApiUrl = void 0;
|
|
3
|
+
exports.isApiSupported = exports.getApiUrl = void 0;
|
|
4
4
|
const chains_1 = require("./chains");
|
|
5
5
|
const API_URLS = {
|
|
6
|
-
[chains_1.ARBITRUM]: "https://gmx-api-arbitrum-
|
|
7
|
-
[chains_1.AVALANCHE]: "",
|
|
8
|
-
[chains_1.AVALANCHE_FUJI]:
|
|
9
|
-
[chains_1.BOTANIX]:
|
|
10
|
-
[chains_1.ARBITRUM_SEPOLIA]: "",
|
|
6
|
+
[chains_1.ARBITRUM]: "https://gmx-api-arbitrum-2nlbk.ondigitalocean.app/api/v1",
|
|
7
|
+
[chains_1.AVALANCHE]: "https://gmx-api-avalanche-vxjas.ondigitalocean.app/api/v1",
|
|
8
|
+
[chains_1.AVALANCHE_FUJI]: undefined,
|
|
9
|
+
[chains_1.BOTANIX]: undefined,
|
|
10
|
+
[chains_1.ARBITRUM_SEPOLIA]: "https://gmx-api-arbitrum-sepolia-yp6pp.ondigitalocean.app/api/v1",
|
|
11
11
|
};
|
|
12
12
|
function getApiUrl(chainId) {
|
|
13
13
|
return API_URLS[chainId];
|
|
14
14
|
}
|
|
15
15
|
exports.getApiUrl = getApiUrl;
|
|
16
|
+
function isApiSupported(chainId) {
|
|
17
|
+
return getApiUrl(chainId) !== undefined;
|
|
18
|
+
}
|
|
19
|
+
exports.isApiSupported = isApiSupported;
|
|
@@ -234,6 +234,7 @@ function getMarket24Stats(dayPriceCandle) {
|
|
|
234
234
|
}
|
|
235
235
|
exports.getMarket24Stats = getMarket24Stats;
|
|
236
236
|
function getMarketTicker(marketInfo, dayPriceCandle) {
|
|
237
|
+
const { minPrice, maxPrice } = marketInfo.indexToken.prices;
|
|
237
238
|
const markPrice = (0, tokens_2.getMidPrice)(marketInfo.indexToken.prices);
|
|
238
239
|
const SECONDS_PER_HOUR = BigInt((0, time_1.periodToSeconds)(1, "1h"));
|
|
239
240
|
const fundingRateLong = (0, fees_1.getFundingFactorPerPeriod)(marketInfo, true, SECONDS_PER_HOUR);
|
|
@@ -242,8 +243,12 @@ function getMarketTicker(marketInfo, dayPriceCandle) {
|
|
|
242
243
|
const borrowingRateShort = (0, fees_1.getBorrowingFactorPerPeriod)(marketInfo, false, SECONDS_PER_HOUR);
|
|
243
244
|
const netRateLong = fundingRateLong - borrowingRateLong;
|
|
244
245
|
const netRateShort = fundingRateShort - borrowingRateShort;
|
|
245
|
-
const
|
|
246
|
-
const
|
|
246
|
+
const longInterestInTokens = getOpenInterestInTokens(marketInfo, true);
|
|
247
|
+
const shortInterestInTokens = getOpenInterestInTokens(marketInfo, false);
|
|
248
|
+
const longInterestUsd = getOpenInterestUsd(marketInfo, true);
|
|
249
|
+
const shortInterestUsd = getOpenInterestUsd(marketInfo, false);
|
|
250
|
+
const longInterestUsdMark = (0, tokens_2.convertToUsd)(longInterestInTokens, marketInfo.indexToken.decimals, markPrice);
|
|
251
|
+
const shortInterestUsdMark = (0, tokens_2.convertToUsd)(shortInterestInTokens, marketInfo.indexToken.decimals, markPrice);
|
|
247
252
|
const availableLiquidityLong = getAvailableUsdLiquidityForCollateral(marketInfo, true);
|
|
248
253
|
const availableLiquidityShort = getAvailableUsdLiquidityForCollateral(marketInfo, false);
|
|
249
254
|
const poolAmountLongUsd = getPoolUsdWithoutPnl(marketInfo, true, "midPrice");
|
|
@@ -252,6 +257,8 @@ function getMarketTicker(marketInfo, dayPriceCandle) {
|
|
|
252
257
|
return {
|
|
253
258
|
symbol: marketInfo.name,
|
|
254
259
|
marketTokenAddress: marketInfo.marketTokenAddress,
|
|
260
|
+
minPrice,
|
|
261
|
+
maxPrice,
|
|
255
262
|
markPrice,
|
|
256
263
|
high24h,
|
|
257
264
|
low24h,
|
|
@@ -259,8 +266,12 @@ function getMarketTicker(marketInfo, dayPriceCandle) {
|
|
|
259
266
|
close24h,
|
|
260
267
|
priceChange24h,
|
|
261
268
|
priceChangePercent24hBps,
|
|
262
|
-
|
|
263
|
-
|
|
269
|
+
longInterestInTokens,
|
|
270
|
+
shortInterestInTokens,
|
|
271
|
+
longInterestUsd,
|
|
272
|
+
shortInterestUsd,
|
|
273
|
+
longInterestUsdMark,
|
|
274
|
+
shortInterestUsdMark,
|
|
264
275
|
availableLiquidityLong,
|
|
265
276
|
availableLiquidityShort,
|
|
266
277
|
poolAmountLongUsd,
|
|
@@ -5,9 +5,13 @@ import { fetchApiOrders } from "../../utils/orders/api";
|
|
|
5
5
|
import { fetchApiPositionsInfo } from "../../utils/positions/api";
|
|
6
6
|
export class GmxApiSdk {
|
|
7
7
|
constructor({ chainId }) {
|
|
8
|
+
const apiUrl = getApiUrl(chainId);
|
|
9
|
+
if (!apiUrl) {
|
|
10
|
+
throw new Error("api is not supported for current chainId");
|
|
11
|
+
}
|
|
8
12
|
this.ctx = {
|
|
9
13
|
chainId,
|
|
10
|
-
api: new HttpClient(
|
|
14
|
+
api: new HttpClient(apiUrl),
|
|
11
15
|
};
|
|
12
16
|
}
|
|
13
17
|
fetchMarketsInfo() {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { ARBITRUM, ARBITRUM_SEPOLIA, AVALANCHE, AVALANCHE_FUJI, BOTANIX } from "./chains";
|
|
2
2
|
const API_URLS = {
|
|
3
|
-
[ARBITRUM]: "https://gmx-api-arbitrum-
|
|
4
|
-
[AVALANCHE]: "",
|
|
5
|
-
[AVALANCHE_FUJI]:
|
|
6
|
-
[BOTANIX]:
|
|
7
|
-
[ARBITRUM_SEPOLIA]: "",
|
|
3
|
+
[ARBITRUM]: "https://gmx-api-arbitrum-2nlbk.ondigitalocean.app/api/v1",
|
|
4
|
+
[AVALANCHE]: "https://gmx-api-avalanche-vxjas.ondigitalocean.app/api/v1",
|
|
5
|
+
[AVALANCHE_FUJI]: undefined,
|
|
6
|
+
[BOTANIX]: undefined,
|
|
7
|
+
[ARBITRUM_SEPOLIA]: "https://gmx-api-arbitrum-sepolia-yp6pp.ondigitalocean.app/api/v1",
|
|
8
8
|
};
|
|
9
9
|
export function getApiUrl(chainId) {
|
|
10
10
|
return API_URLS[chainId];
|
|
11
11
|
}
|
|
12
|
+
export function isApiSupported(chainId) {
|
|
13
|
+
return getApiUrl(chainId) !== undefined;
|
|
14
|
+
}
|
|
@@ -207,6 +207,7 @@ export function getMarket24Stats(dayPriceCandle) {
|
|
|
207
207
|
};
|
|
208
208
|
}
|
|
209
209
|
export function getMarketTicker(marketInfo, dayPriceCandle) {
|
|
210
|
+
const { minPrice, maxPrice } = marketInfo.indexToken.prices;
|
|
210
211
|
const markPrice = getMidPrice(marketInfo.indexToken.prices);
|
|
211
212
|
const SECONDS_PER_HOUR = BigInt(periodToSeconds(1, "1h"));
|
|
212
213
|
const fundingRateLong = getFundingFactorPerPeriod(marketInfo, true, SECONDS_PER_HOUR);
|
|
@@ -215,8 +216,12 @@ export function getMarketTicker(marketInfo, dayPriceCandle) {
|
|
|
215
216
|
const borrowingRateShort = getBorrowingFactorPerPeriod(marketInfo, false, SECONDS_PER_HOUR);
|
|
216
217
|
const netRateLong = fundingRateLong - borrowingRateLong;
|
|
217
218
|
const netRateShort = fundingRateShort - borrowingRateShort;
|
|
218
|
-
const
|
|
219
|
-
const
|
|
219
|
+
const longInterestInTokens = getOpenInterestInTokens(marketInfo, true);
|
|
220
|
+
const shortInterestInTokens = getOpenInterestInTokens(marketInfo, false);
|
|
221
|
+
const longInterestUsd = getOpenInterestUsd(marketInfo, true);
|
|
222
|
+
const shortInterestUsd = getOpenInterestUsd(marketInfo, false);
|
|
223
|
+
const longInterestUsdMark = convertToUsd(longInterestInTokens, marketInfo.indexToken.decimals, markPrice);
|
|
224
|
+
const shortInterestUsdMark = convertToUsd(shortInterestInTokens, marketInfo.indexToken.decimals, markPrice);
|
|
220
225
|
const availableLiquidityLong = getAvailableUsdLiquidityForCollateral(marketInfo, true);
|
|
221
226
|
const availableLiquidityShort = getAvailableUsdLiquidityForCollateral(marketInfo, false);
|
|
222
227
|
const poolAmountLongUsd = getPoolUsdWithoutPnl(marketInfo, true, "midPrice");
|
|
@@ -225,6 +230,8 @@ export function getMarketTicker(marketInfo, dayPriceCandle) {
|
|
|
225
230
|
return {
|
|
226
231
|
symbol: marketInfo.name,
|
|
227
232
|
marketTokenAddress: marketInfo.marketTokenAddress,
|
|
233
|
+
minPrice,
|
|
234
|
+
maxPrice,
|
|
228
235
|
markPrice,
|
|
229
236
|
high24h,
|
|
230
237
|
low24h,
|
|
@@ -232,8 +239,12 @@ export function getMarketTicker(marketInfo, dayPriceCandle) {
|
|
|
232
239
|
close24h,
|
|
233
240
|
priceChange24h,
|
|
234
241
|
priceChangePercent24hBps,
|
|
235
|
-
|
|
236
|
-
|
|
242
|
+
longInterestInTokens,
|
|
243
|
+
shortInterestInTokens,
|
|
244
|
+
longInterestUsd,
|
|
245
|
+
shortInterestUsd,
|
|
246
|
+
longInterestUsdMark,
|
|
247
|
+
shortInterestUsdMark,
|
|
237
248
|
availableLiquidityLong,
|
|
238
249
|
availableLiquidityShort,
|
|
239
250
|
poolAmountLongUsd,
|
|
@@ -169,6 +169,8 @@ export type ClaimableFundingData = {
|
|
|
169
169
|
export type MarketTicker = {
|
|
170
170
|
symbol: string;
|
|
171
171
|
marketTokenAddress: string;
|
|
172
|
+
minPrice: bigint;
|
|
173
|
+
maxPrice: bigint;
|
|
172
174
|
markPrice: bigint;
|
|
173
175
|
high24h: bigint;
|
|
174
176
|
low24h: bigint;
|
|
@@ -176,8 +178,12 @@ export type MarketTicker = {
|
|
|
176
178
|
close24h: bigint;
|
|
177
179
|
priceChange24h: bigint;
|
|
178
180
|
priceChangePercent24hBps: bigint;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
longInterestInTokens: bigint;
|
|
182
|
+
shortInterestInTokens: bigint;
|
|
183
|
+
longInterestUsd: bigint;
|
|
184
|
+
shortInterestUsd: bigint;
|
|
185
|
+
longInterestUsdMark: bigint;
|
|
186
|
+
shortInterestUsdMark: bigint;
|
|
181
187
|
availableLiquidityLong: bigint;
|
|
182
188
|
availableLiquidityShort: bigint;
|
|
183
189
|
poolAmountLongUsd: bigint;
|