@typus/typus-perp-sdk 1.1.16 → 1.1.18
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 +10 -0
- package/dist/src/api/sentio.js +38 -2
- package/package.json +2 -2
package/dist/src/api/sentio.d.ts
CHANGED
|
@@ -31,5 +31,15 @@ export declare function getTlpPriceFromSentio(fromTimestamp?: number, toTimestam
|
|
|
31
31
|
timestamp: string;
|
|
32
32
|
value: number;
|
|
33
33
|
}[]>;
|
|
34
|
+
export declare function getTlpComparisonFromSentio(startTimestamp: number, endTimestamp: number): Promise<tlpComparison[]>;
|
|
35
|
+
interface tlpComparison {
|
|
36
|
+
hour: string;
|
|
37
|
+
portfolio_60sui_40usdc: number;
|
|
38
|
+
sui_value: number;
|
|
39
|
+
tlp_value: number;
|
|
40
|
+
sui_price: number;
|
|
41
|
+
tlp_price: number;
|
|
42
|
+
}
|
|
34
43
|
export declare function getUserPnlFromSentio(startTimestamp: number, endTimestamp: number, userAddress?: string): Promise<any[]>;
|
|
35
44
|
export declare function getLeaderboardFromSentio(startTs: number, endTs: number): Promise<any[]>;
|
|
45
|
+
export {};
|
package/dist/src/api/sentio.js
CHANGED
|
@@ -44,6 +44,7 @@ exports.getTlpFeeFromSentio = getTlpFeeFromSentio;
|
|
|
44
44
|
exports.getTotalVolumeFromSentio = getTotalVolumeFromSentio;
|
|
45
45
|
exports.getAccumulatedUser = getAccumulatedUser;
|
|
46
46
|
exports.getTlpPriceFromSentio = getTlpPriceFromSentio;
|
|
47
|
+
exports.getTlpComparisonFromSentio = getTlpComparisonFromSentio;
|
|
47
48
|
exports.getUserPnlFromSentio = getUserPnlFromSentio;
|
|
48
49
|
exports.getLeaderboardFromSentio = getLeaderboardFromSentio;
|
|
49
50
|
var src_1 = require("../../src");
|
|
@@ -486,6 +487,42 @@ function getTlpPriceFromSentio(fromTimestamp, toTimestamp) {
|
|
|
486
487
|
});
|
|
487
488
|
});
|
|
488
489
|
}
|
|
490
|
+
function getTlpComparisonFromSentio(startTimestamp, endTimestamp) {
|
|
491
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
492
|
+
var apiUrl, requestData, jsonData, response, data;
|
|
493
|
+
return __generator(this, function (_a) {
|
|
494
|
+
switch (_a.label) {
|
|
495
|
+
case 0:
|
|
496
|
+
apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
|
|
497
|
+
requestData = {
|
|
498
|
+
sqlQuery: {
|
|
499
|
+
sql: "\n with\n tlp_hourly as (\n select\n toStartOfHour(timestamp + interval 30 minute) as hour,\n argMin(value, abs(toUnixTimestamp(timestamp) - toUnixTimestamp(toStartOfHour(timestamp + interval 30 minute)))) as tlp_price\n from tlp_price\n WHERE timestamp >= ".concat(startTimestamp, " and timestamp < ").concat(endTimestamp, "\n group by hour\n ),\n\n sui_hourly as (\n select\n toStartOfHour(time + interval 30 minute) as hour,\n argMin(price, abs(toUnixTimestamp(time) - toUnixTimestamp(toStartOfHour(time + interval 30 minute)))) as sui_price\n from 'token.prices'\n where symbol = 'sui'\n and time >= ").concat(startTimestamp, " and time < ").concat(endTimestamp, "\n group by hour\n ),\n\n merged as (\n select\n t.hour,\n t.tlp_price,\n s.sui_price\n from tlp_hourly t\n join sui_hourly s\n on t.hour = s.hour\n ),\n\n base as (\n select min(hour) as base_hour\n from merged\n ),\n base_prices as (\n select\n anyIf(m.tlp_price, m.hour = b.base_hour) as base_tlp,\n anyIf(m.sui_price, m.hour = b.base_hour) as base_sui\n from merged m\n cross join base b\n )\n\n select\n m.hour,\n m.tlp_price,\n m.sui_price,\n 100 * m.tlp_price / bp.base_tlp as tlp_value,\n 100 * m.sui_price / bp.base_sui as sui_value,\n 0.6 * (100 * m.sui_price / bp.base_sui) + 0.4 * 100 as portfolio_60sui_40usdc\n from merged m\n cross join base_prices bp\n order by m.hour;\n "),
|
|
500
|
+
size: 1000,
|
|
501
|
+
},
|
|
502
|
+
};
|
|
503
|
+
jsonData = JSON.stringify(requestData);
|
|
504
|
+
return [4 /*yield*/, fetch(apiUrl, {
|
|
505
|
+
method: "POST",
|
|
506
|
+
headers: headers,
|
|
507
|
+
body: jsonData,
|
|
508
|
+
})];
|
|
509
|
+
case 1:
|
|
510
|
+
response = _a.sent();
|
|
511
|
+
return [4 /*yield*/, response.json()];
|
|
512
|
+
case 2:
|
|
513
|
+
data = _a.sent();
|
|
514
|
+
// console.log(data);
|
|
515
|
+
if (data.result) {
|
|
516
|
+
return [2 /*return*/, data.result.rows];
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
return [2 /*return*/, []];
|
|
520
|
+
}
|
|
521
|
+
return [2 /*return*/];
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
}
|
|
489
526
|
function getUserPnlFromSentio(startTimestamp, endTimestamp, userAddress) {
|
|
490
527
|
return __awaiter(this, void 0, void 0, function () {
|
|
491
528
|
var apiUrl, userFilter, requestData, jsonData, response, data;
|
|
@@ -498,7 +535,6 @@ function getUserPnlFromSentio(startTimestamp, endTimestamp, userAddress) {
|
|
|
498
535
|
userFilter = "AND address == '".concat(userAddress, "'");
|
|
499
536
|
}
|
|
500
537
|
requestData = {
|
|
501
|
-
version: 25,
|
|
502
538
|
sqlQuery: {
|
|
503
539
|
sql: "\n WITH\n Pnl_history as (\n SELECT\n timestamp as time,\n CAST( realized_pnl AS Float64 ) as Trader_PnlUSD,\n filled_size * filled_price as volumeUSD,\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 0 as volumeUSD,\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 0 as volumeUSD,\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 0 as volumeUSD,\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 sum(volumeUSD) as volumeUSD,\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 "),
|
|
504
540
|
size: 100,
|
|
@@ -536,7 +572,6 @@ function getLeaderboardFromSentio(startTs, endTs) {
|
|
|
536
572
|
apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp_mainnet/sql/execute";
|
|
537
573
|
size = (10 * (endTs - startTs)) / 60 / 60 / 24;
|
|
538
574
|
requestData = {
|
|
539
|
-
version: 25,
|
|
540
575
|
sqlQuery: {
|
|
541
576
|
sql: "\n WITH\n event AS (\n SELECT\n timestamp,\n toDate(timestamp - INTERVAL 3 HOUR) AS logical_date,\n toDate(timestamp - INTERVAL 3 HOUR) AS date,\n score/power(10, 9) AS volume,\n distinct_id\n FROM Score\n ),\n sum_vol AS (\n SELECT\n logical_date,\n distinct_id,\n sum(volume) AS total_volume\n FROM event\n GROUP BY logical_date, distinct_id\n ),\n ranked AS (\n SELECT\n *,\n row_number() OVER (PARTITION BY logical_date ORDER BY total_volume DESC) AS rk\n FROM sum_vol\n ),\n top10 AS (\n SELECT *\n FROM ranked\n WHERE rk <= 10\n ),\n top10_sum AS (\n SELECT\n logical_date,\n sum(total_volume) AS top10_total_volume\n FROM top10\n GROUP BY logical_date\n )\n SELECT\n toDateTime(logical_date + INTERVAL 3 HOUR) AS Date,\n t.distinct_id as Address,\n t.total_volume as Trading_Vol,\n cast(t.total_volume AS Decimal256(18)) / cast(s.top10_total_volume AS Decimal256(18)) AS Volume_Share_Top10,\n Volume_Share_Top10 * 150 as PrizePool_Share\n FROM top10 t\n JOIN top10_sum s ON t.logical_date = s.logical_date\n WHERE Date >= ".concat(startTs, " AND Date < ").concat(endTs, "\n ORDER BY\n Date DESC,\n t.rk ASC,\n Volume_Share_Top10\n\n "),
|
|
542
577
|
size: size,
|
|
@@ -574,3 +609,4 @@ function getLeaderboardFromSentio(startTs, endTs) {
|
|
|
574
609
|
// getUserPnlFromSentio(parseTimestamp("2025-06-24 11:00:00"), parseTimestamp("2025-07-08 11:00:00")).then((x) => console.log(x));
|
|
575
610
|
// getMinuteTradingVolumeFromSentio("SUI", 30, 10).then((x) => console.log(x));
|
|
576
611
|
// getLeaderboardFromSentio(1754362800, 1754362800 + 60 * 60 * 24 * 14).then((x) => console.log(x, x.length));
|
|
612
|
+
// getTlpComparisonFromSentio(1758076817, 1758681617).then((x) => console.log(x));
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typus/typus-perp-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.18",
|
|
4
4
|
"repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
|
|
5
5
|
"author": "Typus",
|
|
6
6
|
"description": "typus perp sdk",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@typus/typus-sdk": "1.8.
|
|
9
|
+
"@typus/typus-sdk": "1.8.12"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@types/bs58": "^4.0.1",
|