perp-cli 0.5.3 → 0.6.1
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/README.md +54 -0
- package/dist/commands/agent.js +4 -2
- package/dist/commands/alerts.d.ts +2 -0
- package/dist/commands/alerts.js +487 -0
- package/dist/commands/history.js +329 -70
- package/dist/discord.d.ts +29 -0
- package/dist/discord.js +66 -0
- package/dist/index.js +52 -38
- package/dist/mcp-server.js +444 -1
- package/dist/settings.d.ts +26 -0
- package/dist/settings.js +14 -2
- package/dist/telegram.d.ts +32 -0
- package/dist/telegram.js +74 -0
- package/package.json +9 -2
- package/skills/perp-cli/package.json +35 -0
package/dist/settings.js
CHANGED
|
@@ -19,10 +19,15 @@ const DEFAULTS = {
|
|
|
19
19
|
pacifica: { taker: 0.00035, maker: 0.0001 },
|
|
20
20
|
lighter: { taker: 0, maker: 0 },
|
|
21
21
|
},
|
|
22
|
+
alerts: {
|
|
23
|
+
rules: [],
|
|
24
|
+
intervalSec: 300,
|
|
25
|
+
cooldownMin: 60,
|
|
26
|
+
},
|
|
22
27
|
};
|
|
23
28
|
export function loadSettings() {
|
|
24
29
|
if (!existsSync(SETTINGS_FILE))
|
|
25
|
-
return { ...DEFAULTS, referralCodes: { ...DEFAULTS.referralCodes }, fees: { ...DEFAULTS.fees } };
|
|
30
|
+
return { ...DEFAULTS, referralCodes: { ...DEFAULTS.referralCodes }, fees: { ...DEFAULTS.fees }, alerts: { ...DEFAULTS.alerts } };
|
|
26
31
|
try {
|
|
27
32
|
const stored = JSON.parse(readFileSync(SETTINGS_FILE, "utf-8"));
|
|
28
33
|
// Merge stored fees with defaults (so new exchanges get defaults)
|
|
@@ -47,11 +52,18 @@ export function loadSettings() {
|
|
|
47
52
|
hyperliquid: stored.referralApplied?.hyperliquid ?? DEFAULTS.referralApplied.hyperliquid,
|
|
48
53
|
lighter: stored.referralApplied?.lighter ?? DEFAULTS.referralApplied.lighter,
|
|
49
54
|
},
|
|
55
|
+
alerts: {
|
|
56
|
+
discord: stored.alerts?.discord ?? DEFAULTS.alerts.discord,
|
|
57
|
+
telegram: stored.alerts?.telegram ?? DEFAULTS.alerts.telegram,
|
|
58
|
+
rules: Array.isArray(stored.alerts?.rules) ? stored.alerts.rules : DEFAULTS.alerts.rules,
|
|
59
|
+
intervalSec: stored.alerts?.intervalSec ?? DEFAULTS.alerts.intervalSec,
|
|
60
|
+
cooldownMin: stored.alerts?.cooldownMin ?? DEFAULTS.alerts.cooldownMin,
|
|
61
|
+
},
|
|
50
62
|
fees,
|
|
51
63
|
};
|
|
52
64
|
}
|
|
53
65
|
catch {
|
|
54
|
-
return { ...DEFAULTS, referralCodes: { ...DEFAULTS.referralCodes }, fees: { ...DEFAULTS.fees } };
|
|
66
|
+
return { ...DEFAULTS, referralCodes: { ...DEFAULTS.referralCodes }, fees: { ...DEFAULTS.fees }, alerts: { ...DEFAULTS.alerts } };
|
|
55
67
|
}
|
|
56
68
|
}
|
|
57
69
|
export function saveSettings(settings) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram Bot API client.
|
|
3
|
+
*
|
|
4
|
+
* Sends messages to a user via Telegram Bot API (REST only).
|
|
5
|
+
* Requires: bot token (from @BotFather) + chat ID.
|
|
6
|
+
*/
|
|
7
|
+
export interface TelegramConfig {
|
|
8
|
+
botToken: string;
|
|
9
|
+
chatId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Send a message to the configured chat.
|
|
13
|
+
*/
|
|
14
|
+
export declare function sendTelegramMessage(config: TelegramConfig, message: string, opts?: {
|
|
15
|
+
parseMode?: "Markdown" | "HTML";
|
|
16
|
+
}): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Validate bot token by calling getMe.
|
|
19
|
+
* Returns the bot's username if valid.
|
|
20
|
+
*/
|
|
21
|
+
export declare function validateTelegramBot(token: string): Promise<{
|
|
22
|
+
valid: boolean;
|
|
23
|
+
username: string;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Get recent updates to find the chat ID from a user who messaged the bot.
|
|
27
|
+
* User must send /start to the bot first.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getRecentChatId(token: string): Promise<{
|
|
30
|
+
chatId: string;
|
|
31
|
+
firstName: string;
|
|
32
|
+
} | null>;
|
package/dist/telegram.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram Bot API client.
|
|
3
|
+
*
|
|
4
|
+
* Sends messages to a user via Telegram Bot API (REST only).
|
|
5
|
+
* Requires: bot token (from @BotFather) + chat ID.
|
|
6
|
+
*/
|
|
7
|
+
const TG_API = "https://api.telegram.org";
|
|
8
|
+
/**
|
|
9
|
+
* Send a message to the configured chat.
|
|
10
|
+
*/
|
|
11
|
+
export async function sendTelegramMessage(config, message, opts) {
|
|
12
|
+
const res = await fetch(`${TG_API}/bot${config.botToken}/sendMessage`, {
|
|
13
|
+
method: "POST",
|
|
14
|
+
headers: { "Content-Type": "application/json" },
|
|
15
|
+
body: JSON.stringify({
|
|
16
|
+
chat_id: config.chatId,
|
|
17
|
+
text: message,
|
|
18
|
+
parse_mode: opts?.parseMode,
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
if (!res.ok) {
|
|
22
|
+
const body = await res.text();
|
|
23
|
+
throw new Error(`Telegram send failed (${res.status}): ${body}`);
|
|
24
|
+
}
|
|
25
|
+
const data = (await res.json());
|
|
26
|
+
if (!data.ok) {
|
|
27
|
+
throw new Error(`Telegram API error: ${data.description ?? "unknown"}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Validate bot token by calling getMe.
|
|
32
|
+
* Returns the bot's username if valid.
|
|
33
|
+
*/
|
|
34
|
+
export async function validateTelegramBot(token) {
|
|
35
|
+
try {
|
|
36
|
+
const res = await fetch(`${TG_API}/bot${token}/getMe`);
|
|
37
|
+
if (!res.ok)
|
|
38
|
+
return { valid: false, username: "" };
|
|
39
|
+
const data = (await res.json());
|
|
40
|
+
if (!data.ok || !data.result)
|
|
41
|
+
return { valid: false, username: "" };
|
|
42
|
+
return { valid: true, username: `@${data.result.username}` };
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return { valid: false, username: "" };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get recent updates to find the chat ID from a user who messaged the bot.
|
|
50
|
+
* User must send /start to the bot first.
|
|
51
|
+
*/
|
|
52
|
+
export async function getRecentChatId(token) {
|
|
53
|
+
try {
|
|
54
|
+
const res = await fetch(`${TG_API}/bot${token}/getUpdates?limit=10&offset=-10`);
|
|
55
|
+
if (!res.ok)
|
|
56
|
+
return null;
|
|
57
|
+
const data = (await res.json());
|
|
58
|
+
if (!data.ok || !data.result?.length)
|
|
59
|
+
return null;
|
|
60
|
+
// Find the most recent /start message or any message
|
|
61
|
+
for (const update of data.result.reverse()) {
|
|
62
|
+
if (update.message?.chat?.id) {
|
|
63
|
+
return {
|
|
64
|
+
chatId: String(update.message.chat.id),
|
|
65
|
+
firstName: update.message.chat.first_name ?? "",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "perp-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Multi-DEX Perpetual Futures CLI - Pacifica, Hyperliquid, Lighter",
|
|
5
5
|
"bin": {
|
|
6
6
|
"perp": "dist/index.js",
|
|
@@ -29,7 +29,14 @@
|
|
|
29
29
|
"cli",
|
|
30
30
|
"trading",
|
|
31
31
|
"funding-rate",
|
|
32
|
-
"arbitrage"
|
|
32
|
+
"arbitrage",
|
|
33
|
+
"mcp",
|
|
34
|
+
"mcp-server",
|
|
35
|
+
"model-context-protocol",
|
|
36
|
+
"ai-agent",
|
|
37
|
+
"perpetual-futures",
|
|
38
|
+
"defi",
|
|
39
|
+
"ethereum"
|
|
33
40
|
],
|
|
34
41
|
"license": "MIT",
|
|
35
42
|
"engines": {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hypurrquant/perp-cli-skill",
|
|
3
|
+
"version": "0.5.3",
|
|
4
|
+
"description": "AI agent skill for perp-cli — multi-DEX perpetual futures trading via CLI",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ai-skill",
|
|
7
|
+
"claude",
|
|
8
|
+
"mcp",
|
|
9
|
+
"perp",
|
|
10
|
+
"perpetual-futures",
|
|
11
|
+
"trading",
|
|
12
|
+
"hyperliquid",
|
|
13
|
+
"pacifica",
|
|
14
|
+
"lighter",
|
|
15
|
+
"defi",
|
|
16
|
+
"arbitrage",
|
|
17
|
+
"funding-rate"
|
|
18
|
+
],
|
|
19
|
+
"author": "hypurrquant",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/hypurrquant/perp-cli",
|
|
24
|
+
"directory": "skills/perp-cli"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/hypurrquant/perp-cli#ai-agent-skill",
|
|
27
|
+
"files": [
|
|
28
|
+
"SKILL.md",
|
|
29
|
+
"references",
|
|
30
|
+
"scripts"
|
|
31
|
+
],
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"perp-cli": ">=0.5.0"
|
|
34
|
+
}
|
|
35
|
+
}
|