@typus/typus-perp-sdk 1.0.77 → 1.0.79
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/src/api/sentio.d.ts +1 -0
- package/dist/src/api/sentio.js +46 -0
- package/dist/src/index.js +1 -1
- package/package.json +1 -1
package/dist/src/api/sentio.d.ts
CHANGED
package/dist/src/api/sentio.js
CHANGED
|
@@ -43,6 +43,7 @@ exports.getTlpFeeFromSentio = getTlpFeeFromSentio;
|
|
|
43
43
|
exports.getTotalVolumeFromSentio = getTotalVolumeFromSentio;
|
|
44
44
|
exports.getAccumulatedUser = getAccumulatedUser;
|
|
45
45
|
exports.getTlpPriceFromSentio = getTlpPriceFromSentio;
|
|
46
|
+
exports.getUserPnlFromSentio = getUserPnlFromSentio;
|
|
46
47
|
var src_1 = require("../../src");
|
|
47
48
|
var headers = {
|
|
48
49
|
"api-key": "ffJa6FwxeJNrQP8NZ5doEMXqdSA7XM6mT",
|
|
@@ -212,6 +213,9 @@ function getTradingVolumeFromSentio(fromTimestamp, interval, toTimestamp) {
|
|
|
212
213
|
function now() {
|
|
213
214
|
return Math.round(Date.now() / 1000);
|
|
214
215
|
}
|
|
216
|
+
function parseTimestamp(s) {
|
|
217
|
+
return Math.round(Date.parse(s) / 1000);
|
|
218
|
+
}
|
|
215
219
|
function getTlpFeeFromSentio(fromTimestamp, toTimestamp) {
|
|
216
220
|
return __awaiter(this, void 0, void 0, function () {
|
|
217
221
|
var apiUrl, requestData, jsonData, response, data, first, last, initial_value, fee;
|
|
@@ -440,9 +444,51 @@ function getTlpPriceFromSentio(fromTimestamp, toTimestamp) {
|
|
|
440
444
|
});
|
|
441
445
|
});
|
|
442
446
|
}
|
|
447
|
+
function getUserPnlFromSentio(startTimestamp, endTimestamp, userAddress) {
|
|
448
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
449
|
+
var apiUrl, userFilter, requestData, jsonData, response, data;
|
|
450
|
+
return __generator(this, function (_a) {
|
|
451
|
+
switch (_a.label) {
|
|
452
|
+
case 0:
|
|
453
|
+
apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
|
|
454
|
+
userFilter = "";
|
|
455
|
+
if (userAddress) {
|
|
456
|
+
userFilter = "AND address == '".concat(userAddress, "'");
|
|
457
|
+
}
|
|
458
|
+
requestData = {
|
|
459
|
+
version: 25,
|
|
460
|
+
sqlQuery: {
|
|
461
|
+
sql: "\n WITH\n Pnl_history as (\n SELECT\n timestamp as time,\n CAST( realized_pnl AS Float64 ) as Trader_PnlUSD,\n distinct_id as address\n from OrderFilled\n WHERE timestamp >= ".concat(startTimestamp, " and timestamp < ").concat(endTimestamp, "\n UNION ALL\n SELECT\n timestamp as time,\n CAST(value_for_lp_pool_usd + liquidator_fee_usd AS Float64) * (-1) as Trader_PnlUSD,\n distinct_id as address\n from Liquidate -- collateral liquidate, liquidate fee\u4E0D\u7B97\n WHERE timestamp >= ").concat(startTimestamp, " and timestamp < ").concat(endTimestamp, "\n UNION ALL\n SELECT\n timestamp as time,\n CAST(realized_funding_fee_usd AS Float64) * (-1) as Trader_PnlUSD,\n distinct_id as address\n from 'RealizeFunding' -- funding fee \u6B63\u7684\u662F user paid to pool\n WHERE timestamp >= ").concat(startTimestamp, " and timestamp < ").concat(endTimestamp, "\n UNION ALL\n SELECT\n timestamp as time,\n CAST(\n user_remaining_in_usd + (realized_loss_value - exercise_balance_value) * (user_remaining_in_usd / user_remaining_value) AS Float64\n ) as Trader_PnlUSD,\n distinct_id as address\n from 'RealizeOption'\n WHERE timestamp >= ").concat(startTimestamp, " and timestamp < ").concat(endTimestamp, "\n ),\n sum_Trader_PnlUSD as (\n SELECT\n sum(Trader_PnlUSD) as Trader_PnlUSD,\n address\n from Pnl_history\n GROUP BY address\n )\n SELECT\n *\n from sum_Trader_PnlUSD\n where address not in (\n '0xc9ea1b9c3542551189cf26a08f5ca5ed7964aef34c14d06c888d30c8d91867e4',\n '0x83d2cb640ee252bae6b01bd6104c4afc69071e67b688db85a029ce452c61f11c',\n '0x39770d149a9bc9d9639314fca2c380e9061c0d230737635762c5bcc61dee13d0',\n '0x834d17f7b2e167cae224325a17b49babffe168182c418caa0c63a92d6f70b83a',\n '0xd35ae21660aee607ee21e104d093d03643d36efbf79df669092c4411308ed2e2',\n '0xe6cbba68c446f52cf8211c12ae79179233c8f9cec5e0b5008418ec339ca72fea'\n )\n ").concat(userFilter, "\n order by Trader_PnlUSD desc\n "),
|
|
462
|
+
size: 100,
|
|
463
|
+
},
|
|
464
|
+
};
|
|
465
|
+
jsonData = JSON.stringify(requestData);
|
|
466
|
+
return [4 /*yield*/, fetch(apiUrl, {
|
|
467
|
+
method: "POST",
|
|
468
|
+
headers: headers,
|
|
469
|
+
body: jsonData,
|
|
470
|
+
})];
|
|
471
|
+
case 1:
|
|
472
|
+
response = _a.sent();
|
|
473
|
+
return [4 /*yield*/, response.json()];
|
|
474
|
+
case 2:
|
|
475
|
+
data = _a.sent();
|
|
476
|
+
console.log(data);
|
|
477
|
+
if (data.result) {
|
|
478
|
+
return [2 /*return*/, data.result.rows];
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
return [2 /*return*/, []];
|
|
482
|
+
}
|
|
483
|
+
return [2 /*return*/];
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
}
|
|
443
488
|
// getRecentTradesFromSentio().then((x) => console.log(x));
|
|
444
489
|
// getAccumulatedUser().then((x) => console.log(x));
|
|
445
490
|
// getTradingVolumeFromSentio(1747008000, 1, 1747011600);
|
|
446
491
|
// getTlpPriceFromSentio(0).then((x) => console.dir(x, { depth: null }));
|
|
447
492
|
// getTotalVolumeFromSentio(0).then((x) => console.log(x));
|
|
448
493
|
// getTlpFeeFromSentio(0).then((x) => console.log(x));
|
|
494
|
+
// getUserPnlFromSentio(parseTimestamp("2025-06-24 11:00:00"), parseTimestamp("2025-07-08 11:00:00")).then((x) => console.log(x));
|
package/dist/src/index.js
CHANGED
|
@@ -36,7 +36,7 @@ transactions_1.Transaction.registerGlobalSerializationPlugin("namedPackagesPlugi
|
|
|
36
36
|
exports.PERP_PACKAGE_ID = exports.NETWORK == "MAINNET"
|
|
37
37
|
? "0xe27969a70f93034de9ce16e6ad661b480324574e68d15a64b513fd90eb2423e5"
|
|
38
38
|
: "0x585924f160f83ef16f8927ec117e4d740abb6f4e571ecfa89ff3e973042cb1b9";
|
|
39
|
-
exports.PERP_PUBLISHED_AT = exports.NETWORK == "MAINNET" ? "
|
|
39
|
+
exports.PERP_PUBLISHED_AT = exports.NETWORK == "MAINNET" ? "0xb52138bfce4e79d0d25c69b1d9dfe6ec81a821ed3ef03cdb1c077cb4ac9c9b9d" : "@typus/perp";
|
|
40
40
|
exports.PERP_PKG_V1 = exports.NETWORK == "MAINNET"
|
|
41
41
|
? "0xe27969a70f93034de9ce16e6ad661b480324574e68d15a64b513fd90eb2423e5"
|
|
42
42
|
: "0x585924f160f83ef16f8927ec117e4d740abb6f4e571ecfa89ff3e973042cb1b9";
|