@myx-trade/sdk 0.1.158 → 0.1.159
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/dist/index.js +52 -8
- package/dist/index.mjs +52 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1821,7 +1821,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
|
|
|
1821
1821
|
// package.json
|
|
1822
1822
|
var package_default = {
|
|
1823
1823
|
name: "@myx-trade/sdk",
|
|
1824
|
-
version: "0.1.
|
|
1824
|
+
version: "0.1.159",
|
|
1825
1825
|
private: false,
|
|
1826
1826
|
publishConfig: {
|
|
1827
1827
|
access: "public"
|
|
@@ -21026,6 +21026,13 @@ var Account_default = [
|
|
|
21026
21026
|
|
|
21027
21027
|
// src/manager/account/index.ts
|
|
21028
21028
|
var import_dayjs3 = __toESM(require("dayjs"));
|
|
21029
|
+
|
|
21030
|
+
// src/api/pool/index.ts
|
|
21031
|
+
var getPoolList = async () => {
|
|
21032
|
+
return http.get(`${baseUrl}/openapi/gateway/scan/market/list`);
|
|
21033
|
+
};
|
|
21034
|
+
|
|
21035
|
+
// src/manager/account/index.ts
|
|
21029
21036
|
var Account = class {
|
|
21030
21037
|
constructor(configManager, logger, utils, client2) {
|
|
21031
21038
|
this.configManager = configManager;
|
|
@@ -21083,16 +21090,53 @@ var Account = class {
|
|
|
21083
21090
|
}
|
|
21084
21091
|
}
|
|
21085
21092
|
async getAvailableMarginBalance({ poolId, chainId, address }) {
|
|
21086
|
-
|
|
21087
|
-
|
|
21088
|
-
|
|
21093
|
+
try {
|
|
21094
|
+
const poolListRes = await getPoolList();
|
|
21095
|
+
if (poolListRes.code !== 0) {
|
|
21096
|
+
throw new MyxSDKError(
|
|
21097
|
+
"REQUEST_FAILED" /* RequestFailed */,
|
|
21098
|
+
"Failed to get pool list"
|
|
21099
|
+
);
|
|
21100
|
+
}
|
|
21101
|
+
const poolList = poolListRes.data;
|
|
21102
|
+
const pool = poolList?.find((pool2) => pool2.poolId === poolId);
|
|
21103
|
+
const orderRes = await this.client.order.getOrders();
|
|
21104
|
+
if (orderRes.code !== 0) {
|
|
21105
|
+
throw new MyxSDKError(
|
|
21106
|
+
"REQUEST_FAILED" /* RequestFailed */,
|
|
21107
|
+
"Failed to get orders"
|
|
21108
|
+
);
|
|
21109
|
+
}
|
|
21110
|
+
const orders = orderRes.data;
|
|
21111
|
+
const openOrders = orders?.filter((order) => order.poolId === poolId);
|
|
21112
|
+
const used = openOrders?.reduce((acc, order) => {
|
|
21113
|
+
const prev = BigInt(acc);
|
|
21114
|
+
const curr = BigInt(order.collateralAmount ?? 0) + prev;
|
|
21115
|
+
return curr.toString();
|
|
21116
|
+
}, "0");
|
|
21117
|
+
const marginAccountBalanceRes = await this.getAccountInfo(chainId, address, poolId);
|
|
21118
|
+
if (marginAccountBalanceRes.code !== 0) {
|
|
21119
|
+
throw new MyxSDKError(
|
|
21120
|
+
"REQUEST_FAILED" /* RequestFailed */,
|
|
21121
|
+
"Failed to get account info"
|
|
21122
|
+
);
|
|
21123
|
+
}
|
|
21124
|
+
const marginAccountBalance = marginAccountBalanceRes.data;
|
|
21125
|
+
const usedMargin = import_ethers26.ethers.parseUnits(used ?? "0", pool?.quoteDecimals ?? 6);
|
|
21126
|
+
const quoteProfit = BigInt(marginAccountBalance.quoteProfit ?? 0);
|
|
21127
|
+
const freeAmount = BigInt(marginAccountBalance?.freeAmount.toString() ?? 0);
|
|
21128
|
+
const accountMargin = freeAmount + quoteProfit;
|
|
21129
|
+
if (accountMargin < usedMargin) {
|
|
21130
|
+
return BigInt(0);
|
|
21131
|
+
}
|
|
21132
|
+
const availableAccountMarginBalance = accountMargin - usedMargin;
|
|
21133
|
+
return availableAccountMarginBalance;
|
|
21134
|
+
} catch (error) {
|
|
21089
21135
|
throw new MyxSDKError(
|
|
21090
|
-
"
|
|
21091
|
-
"
|
|
21136
|
+
"REQUEST_FAILED" /* RequestFailed */,
|
|
21137
|
+
"Failed to get orders"
|
|
21092
21138
|
);
|
|
21093
21139
|
}
|
|
21094
|
-
const availableAccountMarginBalance = BigInt(marginAccountBalance?.freeAmount.toString() ?? 0) + (!marginAccountBalance?.tradeableProfit ? BigInt(marginAccountBalance?.tradeableProfit) : BigInt(0));
|
|
21095
|
-
return availableAccountMarginBalance;
|
|
21096
21140
|
}
|
|
21097
21141
|
async getTradeFlow(params) {
|
|
21098
21142
|
const accessToken = await this.configManager.getAccessToken();
|
package/dist/index.mjs
CHANGED
|
@@ -1731,7 +1731,7 @@ var RotationProvider = class extends BaseProvider {
|
|
|
1731
1731
|
// package.json
|
|
1732
1732
|
var package_default = {
|
|
1733
1733
|
name: "@myx-trade/sdk",
|
|
1734
|
-
version: "0.1.
|
|
1734
|
+
version: "0.1.159",
|
|
1735
1735
|
private: false,
|
|
1736
1736
|
publishConfig: {
|
|
1737
1737
|
access: "public"
|
|
@@ -20936,6 +20936,13 @@ var Account_default = [
|
|
|
20936
20936
|
|
|
20937
20937
|
// src/manager/account/index.ts
|
|
20938
20938
|
import dayjs3 from "dayjs";
|
|
20939
|
+
|
|
20940
|
+
// src/api/pool/index.ts
|
|
20941
|
+
var getPoolList = async () => {
|
|
20942
|
+
return http.get(`${baseUrl}/openapi/gateway/scan/market/list`);
|
|
20943
|
+
};
|
|
20944
|
+
|
|
20945
|
+
// src/manager/account/index.ts
|
|
20939
20946
|
var Account = class {
|
|
20940
20947
|
constructor(configManager, logger, utils, client2) {
|
|
20941
20948
|
this.configManager = configManager;
|
|
@@ -20993,16 +21000,53 @@ var Account = class {
|
|
|
20993
21000
|
}
|
|
20994
21001
|
}
|
|
20995
21002
|
async getAvailableMarginBalance({ poolId, chainId, address }) {
|
|
20996
|
-
|
|
20997
|
-
|
|
20998
|
-
|
|
21003
|
+
try {
|
|
21004
|
+
const poolListRes = await getPoolList();
|
|
21005
|
+
if (poolListRes.code !== 0) {
|
|
21006
|
+
throw new MyxSDKError(
|
|
21007
|
+
"REQUEST_FAILED" /* RequestFailed */,
|
|
21008
|
+
"Failed to get pool list"
|
|
21009
|
+
);
|
|
21010
|
+
}
|
|
21011
|
+
const poolList = poolListRes.data;
|
|
21012
|
+
const pool = poolList?.find((pool2) => pool2.poolId === poolId);
|
|
21013
|
+
const orderRes = await this.client.order.getOrders();
|
|
21014
|
+
if (orderRes.code !== 0) {
|
|
21015
|
+
throw new MyxSDKError(
|
|
21016
|
+
"REQUEST_FAILED" /* RequestFailed */,
|
|
21017
|
+
"Failed to get orders"
|
|
21018
|
+
);
|
|
21019
|
+
}
|
|
21020
|
+
const orders = orderRes.data;
|
|
21021
|
+
const openOrders = orders?.filter((order) => order.poolId === poolId);
|
|
21022
|
+
const used = openOrders?.reduce((acc, order) => {
|
|
21023
|
+
const prev = BigInt(acc);
|
|
21024
|
+
const curr = BigInt(order.collateralAmount ?? 0) + prev;
|
|
21025
|
+
return curr.toString();
|
|
21026
|
+
}, "0");
|
|
21027
|
+
const marginAccountBalanceRes = await this.getAccountInfo(chainId, address, poolId);
|
|
21028
|
+
if (marginAccountBalanceRes.code !== 0) {
|
|
21029
|
+
throw new MyxSDKError(
|
|
21030
|
+
"REQUEST_FAILED" /* RequestFailed */,
|
|
21031
|
+
"Failed to get account info"
|
|
21032
|
+
);
|
|
21033
|
+
}
|
|
21034
|
+
const marginAccountBalance = marginAccountBalanceRes.data;
|
|
21035
|
+
const usedMargin = ethers8.parseUnits(used ?? "0", pool?.quoteDecimals ?? 6);
|
|
21036
|
+
const quoteProfit = BigInt(marginAccountBalance.quoteProfit ?? 0);
|
|
21037
|
+
const freeAmount = BigInt(marginAccountBalance?.freeAmount.toString() ?? 0);
|
|
21038
|
+
const accountMargin = freeAmount + quoteProfit;
|
|
21039
|
+
if (accountMargin < usedMargin) {
|
|
21040
|
+
return BigInt(0);
|
|
21041
|
+
}
|
|
21042
|
+
const availableAccountMarginBalance = accountMargin - usedMargin;
|
|
21043
|
+
return availableAccountMarginBalance;
|
|
21044
|
+
} catch (error) {
|
|
20999
21045
|
throw new MyxSDKError(
|
|
21000
|
-
"
|
|
21001
|
-
"
|
|
21046
|
+
"REQUEST_FAILED" /* RequestFailed */,
|
|
21047
|
+
"Failed to get orders"
|
|
21002
21048
|
);
|
|
21003
21049
|
}
|
|
21004
|
-
const availableAccountMarginBalance = BigInt(marginAccountBalance?.freeAmount.toString() ?? 0) + (!marginAccountBalance?.tradeableProfit ? BigInt(marginAccountBalance?.tradeableProfit) : BigInt(0));
|
|
21005
|
-
return availableAccountMarginBalance;
|
|
21006
21050
|
}
|
|
21007
21051
|
async getTradeFlow(params) {
|
|
21008
21052
|
const accessToken = await this.configManager.getAccessToken();
|