@guiie/buda-mcp 1.1.2 → 1.2.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/CHANGELOG.md +35 -0
- package/PUBLISH.md +5 -5
- package/PUBLISH_CHECKLIST.md +59 -62
- package/README.md +3 -3
- package/dist/client.d.ts +15 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +56 -52
- package/dist/http.js +30 -148
- package/dist/index.js +2 -1
- package/dist/tools/balances.d.ts +8 -0
- package/dist/tools/balances.d.ts.map +1 -1
- package/dist/tools/balances.js +11 -3
- package/dist/tools/cancel_order.d.ts +30 -0
- package/dist/tools/cancel_order.d.ts.map +1 -1
- package/dist/tools/cancel_order.js +59 -38
- package/dist/tools/compare_markets.d.ts +14 -0
- package/dist/tools/compare_markets.d.ts.map +1 -1
- package/dist/tools/compare_markets.js +17 -3
- package/dist/tools/markets.d.ts +13 -0
- package/dist/tools/markets.d.ts.map +1 -1
- package/dist/tools/markets.js +23 -2
- package/dist/tools/orderbook.d.ts +18 -0
- package/dist/tools/orderbook.d.ts.map +1 -1
- package/dist/tools/orderbook.js +28 -2
- package/dist/tools/orders.d.ts +26 -0
- package/dist/tools/orders.d.ts.map +1 -1
- package/dist/tools/orders.js +36 -2
- package/dist/tools/place_order.d.ts +50 -0
- package/dist/tools/place_order.d.ts.map +1 -1
- package/dist/tools/place_order.js +104 -58
- package/dist/tools/price_history.d.ts +22 -0
- package/dist/tools/price_history.d.ts.map +1 -1
- package/dist/tools/price_history.js +42 -7
- package/dist/tools/spread.d.ts +14 -0
- package/dist/tools/spread.d.ts.map +1 -1
- package/dist/tools/spread.js +24 -2
- package/dist/tools/ticker.d.ts +14 -0
- package/dist/tools/ticker.d.ts.map +1 -1
- package/dist/tools/ticker.js +24 -2
- package/dist/tools/trades.d.ts +22 -0
- package/dist/tools/trades.d.ts.map +1 -1
- package/dist/tools/trades.js +32 -2
- package/dist/tools/volume.d.ts +14 -0
- package/dist/tools/volume.d.ts.map +1 -1
- package/dist/tools/volume.js +24 -2
- package/dist/validation.d.ts +6 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +14 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/marketplace/README.md +1 -1
- package/marketplace/claude-listing.md +2 -2
- package/marketplace/gemini-tools.json +3 -3
- package/marketplace/openapi.yaml +7 -6
- package/package.json +5 -2
- package/scripts/sync-version.mjs +19 -0
- package/server.json +2 -2
- package/src/client.ts +77 -53
- package/src/http.ts +32 -150
- package/src/index.ts +2 -1
- package/src/tools/balances.ts +14 -4
- package/src/tools/cancel_order.ts +77 -43
- package/src/tools/compare_markets.ts +21 -4
- package/src/tools/markets.ts +27 -3
- package/src/tools/orderbook.ts +32 -3
- package/src/tools/orders.ts +41 -3
- package/src/tools/place_order.ts +134 -69
- package/src/tools/price_history.ts +50 -8
- package/src/tools/spread.ts +28 -3
- package/src/tools/ticker.ts +28 -3
- package/src/tools/trades.ts +37 -3
- package/src/tools/volume.ts +28 -3
- package/src/validation.ts +16 -0
- package/src/version.ts +8 -0
- package/test/run-all.ts +13 -1
- package/test/unit.ts +414 -0
|
@@ -3,13 +3,84 @@ import { z } from "zod";
|
|
|
3
3
|
import { BudaClient, BudaApiError } from "../client.js";
|
|
4
4
|
import type { OrderResponse } from "../types.js";
|
|
5
5
|
|
|
6
|
+
export const toolSchema = {
|
|
7
|
+
name: "cancel_order",
|
|
8
|
+
description:
|
|
9
|
+
"Cancel an open order by ID on Buda.com. " +
|
|
10
|
+
"IMPORTANT: To prevent accidental cancellation from ambiguous prompts, you must pass " +
|
|
11
|
+
"confirmation_token='CONFIRM' to execute. " +
|
|
12
|
+
"Requires BUDA_API_KEY and BUDA_API_SECRET environment variables.",
|
|
13
|
+
inputSchema: {
|
|
14
|
+
type: "object" as const,
|
|
15
|
+
properties: {
|
|
16
|
+
order_id: {
|
|
17
|
+
type: "number",
|
|
18
|
+
description: "The numeric ID of the order to cancel.",
|
|
19
|
+
},
|
|
20
|
+
confirmation_token: {
|
|
21
|
+
type: "string",
|
|
22
|
+
description:
|
|
23
|
+
"Safety confirmation. Must equal exactly 'CONFIRM' (case-sensitive) to cancel the order. " +
|
|
24
|
+
"Any other value will reject the request without canceling.",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
required: ["order_id", "confirmation_token"],
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type CancelOrderArgs = {
|
|
32
|
+
order_id: number;
|
|
33
|
+
confirmation_token: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export async function handleCancelOrder(
|
|
37
|
+
args: CancelOrderArgs,
|
|
38
|
+
client: BudaClient,
|
|
39
|
+
): Promise<{ content: Array<{ type: "text"; text: string }>; isError?: boolean }> {
|
|
40
|
+
const { order_id, confirmation_token } = args;
|
|
41
|
+
|
|
42
|
+
if (confirmation_token !== "CONFIRM") {
|
|
43
|
+
return {
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: "text",
|
|
47
|
+
text: JSON.stringify({
|
|
48
|
+
error:
|
|
49
|
+
"Order not canceled. confirmation_token must equal 'CONFIRM' to execute. " +
|
|
50
|
+
"Verify the order ID and set confirmation_token='CONFIRM' to proceed.",
|
|
51
|
+
code: "CONFIRMATION_REQUIRED",
|
|
52
|
+
order_id,
|
|
53
|
+
}),
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
isError: true,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const data = await client.put<OrderResponse>(`/orders/${order_id}`, {
|
|
62
|
+
state: "canceling",
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
content: [{ type: "text", text: JSON.stringify(data.order, null, 2) }],
|
|
67
|
+
};
|
|
68
|
+
} catch (err) {
|
|
69
|
+
const msg =
|
|
70
|
+
err instanceof BudaApiError
|
|
71
|
+
? { error: err.message, code: err.status, path: err.path }
|
|
72
|
+
: { error: String(err), code: "UNKNOWN" };
|
|
73
|
+
return {
|
|
74
|
+
content: [{ type: "text", text: JSON.stringify(msg) }],
|
|
75
|
+
isError: true,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
6
80
|
export function register(server: McpServer, client: BudaClient): void {
|
|
7
81
|
server.tool(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"IMPORTANT: To prevent accidental cancellation from ambiguous prompts, you must pass " +
|
|
11
|
-
"confirmation_token='CONFIRM' to execute. " +
|
|
12
|
-
"Requires BUDA_API_KEY and BUDA_API_SECRET environment variables.",
|
|
82
|
+
toolSchema.name,
|
|
83
|
+
toolSchema.description,
|
|
13
84
|
{
|
|
14
85
|
order_id: z
|
|
15
86
|
.number()
|
|
@@ -23,43 +94,6 @@ export function register(server: McpServer, client: BudaClient): void {
|
|
|
23
94
|
"Any other value will reject the request without canceling.",
|
|
24
95
|
),
|
|
25
96
|
},
|
|
26
|
-
|
|
27
|
-
if (confirmation_token !== "CONFIRM") {
|
|
28
|
-
return {
|
|
29
|
-
content: [
|
|
30
|
-
{
|
|
31
|
-
type: "text",
|
|
32
|
-
text: JSON.stringify({
|
|
33
|
-
error:
|
|
34
|
-
"Order not canceled. confirmation_token must equal 'CONFIRM' to execute. " +
|
|
35
|
-
"Verify the order ID and set confirmation_token='CONFIRM' to proceed.",
|
|
36
|
-
code: "CONFIRMATION_REQUIRED",
|
|
37
|
-
order_id,
|
|
38
|
-
}),
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
isError: true,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
const data = await client.put<OrderResponse>(`/orders/${order_id}`, {
|
|
47
|
-
state: "canceling",
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
content: [{ type: "text", text: JSON.stringify(data.order, null, 2) }],
|
|
52
|
-
};
|
|
53
|
-
} catch (err) {
|
|
54
|
-
const msg =
|
|
55
|
-
err instanceof BudaApiError
|
|
56
|
-
? { error: err.message, code: err.status, path: err.path }
|
|
57
|
-
: { error: String(err), code: "UNKNOWN" };
|
|
58
|
-
return {
|
|
59
|
-
content: [{ type: "text", text: JSON.stringify(msg) }],
|
|
60
|
-
isError: true,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
},
|
|
97
|
+
(args) => handleCancelOrder(args, client),
|
|
64
98
|
);
|
|
65
99
|
}
|
|
@@ -4,12 +4,29 @@ import { BudaClient, BudaApiError } from "../client.js";
|
|
|
4
4
|
import { MemoryCache, CACHE_TTL } from "../cache.js";
|
|
5
5
|
import type { AllTickersResponse } from "../types.js";
|
|
6
6
|
|
|
7
|
+
export const toolSchema = {
|
|
8
|
+
name: "compare_markets",
|
|
9
|
+
description:
|
|
10
|
+
"Compare ticker data for all trading pairs of a given base currency across Buda.com's " +
|
|
11
|
+
"supported quote currencies (CLP, COP, PEN, BTC, USDC, ETH). " +
|
|
12
|
+
"For example, passing 'BTC' returns side-by-side data for BTC-CLP, BTC-COP, BTC-PEN, etc.",
|
|
13
|
+
inputSchema: {
|
|
14
|
+
type: "object" as const,
|
|
15
|
+
properties: {
|
|
16
|
+
base_currency: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description:
|
|
19
|
+
"Base currency to compare across all available markets (e.g. 'BTC', 'ETH', 'XRP').",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
required: ["base_currency"],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
7
26
|
export function register(server: McpServer, client: BudaClient, cache: MemoryCache): void {
|
|
8
27
|
server.tool(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"supported quote currencies (CLP, COP, PEN, BTC, USDC, ETH). " +
|
|
12
|
-
"For example, passing 'BTC' returns side-by-side data for BTC-CLP, BTC-COP, BTC-PEN, etc.",
|
|
28
|
+
toolSchema.name,
|
|
29
|
+
toolSchema.description,
|
|
13
30
|
{
|
|
14
31
|
base_currency: z
|
|
15
32
|
.string()
|
package/src/tools/markets.ts
CHANGED
|
@@ -2,13 +2,29 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { BudaClient, BudaApiError } from "../client.js";
|
|
4
4
|
import { MemoryCache, CACHE_TTL } from "../cache.js";
|
|
5
|
+
import { validateMarketId } from "../validation.js";
|
|
5
6
|
import type { MarketsResponse, MarketResponse } from "../types.js";
|
|
6
7
|
|
|
8
|
+
export const toolSchema = {
|
|
9
|
+
name: "get_markets",
|
|
10
|
+
description:
|
|
11
|
+
"List all available trading pairs on Buda.com, or get details for a specific market. " +
|
|
12
|
+
"Returns base/quote currencies, fees, and minimum order sizes.",
|
|
13
|
+
inputSchema: {
|
|
14
|
+
type: "object" as const,
|
|
15
|
+
properties: {
|
|
16
|
+
market_id: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "Optional market ID (e.g. 'BTC-CLP', 'ETH-BTC'). Omit to list all markets.",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
7
24
|
export function register(server: McpServer, client: BudaClient, cache: MemoryCache): void {
|
|
8
25
|
server.tool(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"Returns base/quote currencies, fees, and minimum order sizes.",
|
|
26
|
+
toolSchema.name,
|
|
27
|
+
toolSchema.description,
|
|
12
28
|
{
|
|
13
29
|
market_id: z
|
|
14
30
|
.string()
|
|
@@ -20,6 +36,14 @@ export function register(server: McpServer, client: BudaClient, cache: MemoryCac
|
|
|
20
36
|
async ({ market_id }) => {
|
|
21
37
|
try {
|
|
22
38
|
if (market_id) {
|
|
39
|
+
const validationError = validateMarketId(market_id);
|
|
40
|
+
if (validationError) {
|
|
41
|
+
return {
|
|
42
|
+
content: [{ type: "text", text: JSON.stringify({ error: validationError, code: "INVALID_MARKET_ID" }) }],
|
|
43
|
+
isError: true,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
23
47
|
const id = market_id.toLowerCase();
|
|
24
48
|
const data = await cache.getOrFetch<MarketResponse>(
|
|
25
49
|
`market:${id}`,
|
package/src/tools/orderbook.ts
CHANGED
|
@@ -2,13 +2,34 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { BudaClient, BudaApiError } from "../client.js";
|
|
4
4
|
import { MemoryCache, CACHE_TTL } from "../cache.js";
|
|
5
|
+
import { validateMarketId } from "../validation.js";
|
|
5
6
|
import type { OrderBookResponse } from "../types.js";
|
|
6
7
|
|
|
8
|
+
export const toolSchema = {
|
|
9
|
+
name: "get_orderbook",
|
|
10
|
+
description:
|
|
11
|
+
"Get the current order book (bids and asks) for a Buda.com market. Returns sorted arrays of " +
|
|
12
|
+
"bids (buy orders) and asks (sell orders), each as [price, amount] pairs.",
|
|
13
|
+
inputSchema: {
|
|
14
|
+
type: "object" as const,
|
|
15
|
+
properties: {
|
|
16
|
+
market_id: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "Market ID (e.g. 'BTC-CLP', 'ETH-BTC').",
|
|
19
|
+
},
|
|
20
|
+
limit: {
|
|
21
|
+
type: "number",
|
|
22
|
+
description: "Maximum number of levels to return per side (default: all).",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
required: ["market_id"],
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
7
29
|
export function register(server: McpServer, client: BudaClient, cache: MemoryCache): void {
|
|
8
30
|
server.tool(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"bids (buy orders) and asks (sell orders), each as [price, amount] pairs.",
|
|
31
|
+
toolSchema.name,
|
|
32
|
+
toolSchema.description,
|
|
12
33
|
{
|
|
13
34
|
market_id: z
|
|
14
35
|
.string()
|
|
@@ -22,6 +43,14 @@ export function register(server: McpServer, client: BudaClient, cache: MemoryCac
|
|
|
22
43
|
},
|
|
23
44
|
async ({ market_id, limit }) => {
|
|
24
45
|
try {
|
|
46
|
+
const validationError = validateMarketId(market_id);
|
|
47
|
+
if (validationError) {
|
|
48
|
+
return {
|
|
49
|
+
content: [{ type: "text", text: JSON.stringify({ error: validationError, code: "INVALID_MARKET_ID" }) }],
|
|
50
|
+
isError: true,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
25
54
|
const id = market_id.toLowerCase();
|
|
26
55
|
const data = await cache.getOrFetch<OrderBookResponse>(
|
|
27
56
|
`orderbook:${id}`,
|
package/src/tools/orders.ts
CHANGED
|
@@ -1,13 +1,43 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { BudaClient, BudaApiError } from "../client.js";
|
|
4
|
+
import { validateMarketId } from "../validation.js";
|
|
4
5
|
import type { OrdersResponse } from "../types.js";
|
|
5
6
|
|
|
7
|
+
export const toolSchema = {
|
|
8
|
+
name: "get_orders",
|
|
9
|
+
description:
|
|
10
|
+
"Get orders for a given Buda.com market. Filter by state (pending, active, traded, canceled). " +
|
|
11
|
+
"Requires BUDA_API_KEY and BUDA_API_SECRET environment variables.",
|
|
12
|
+
inputSchema: {
|
|
13
|
+
type: "object" as const,
|
|
14
|
+
properties: {
|
|
15
|
+
market_id: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "Market ID (e.g. 'BTC-CLP', 'ETH-BTC').",
|
|
18
|
+
},
|
|
19
|
+
state: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description:
|
|
22
|
+
"Filter by order state: 'pending', 'active', 'traded', 'canceled', 'canceled_and_traded'.",
|
|
23
|
+
},
|
|
24
|
+
per: {
|
|
25
|
+
type: "number",
|
|
26
|
+
description: "Results per page (default: 20, max: 300).",
|
|
27
|
+
},
|
|
28
|
+
page: {
|
|
29
|
+
type: "number",
|
|
30
|
+
description: "Page number (default: 1).",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
required: ["market_id"],
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
6
37
|
export function register(server: McpServer, client: BudaClient): void {
|
|
7
38
|
server.tool(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"Requires BUDA_API_KEY and BUDA_API_SECRET environment variables.",
|
|
39
|
+
toolSchema.name,
|
|
40
|
+
toolSchema.description,
|
|
11
41
|
{
|
|
12
42
|
market_id: z
|
|
13
43
|
.string()
|
|
@@ -35,6 +65,14 @@ export function register(server: McpServer, client: BudaClient): void {
|
|
|
35
65
|
},
|
|
36
66
|
async ({ market_id, state, per, page }) => {
|
|
37
67
|
try {
|
|
68
|
+
const validationError = validateMarketId(market_id);
|
|
69
|
+
if (validationError) {
|
|
70
|
+
return {
|
|
71
|
+
content: [{ type: "text", text: JSON.stringify({ error: validationError, code: "INVALID_MARKET_ID" }) }],
|
|
72
|
+
isError: true,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
38
76
|
const params: Record<string, string | number> = {};
|
|
39
77
|
if (state) params.state = state;
|
|
40
78
|
if (per !== undefined) params.per = per;
|
package/src/tools/place_order.ts
CHANGED
|
@@ -1,16 +1,143 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { BudaClient, BudaApiError } from "../client.js";
|
|
4
|
+
import { validateMarketId } from "../validation.js";
|
|
4
5
|
import type { OrderResponse } from "../types.js";
|
|
5
6
|
|
|
7
|
+
export const toolSchema = {
|
|
8
|
+
name: "place_order",
|
|
9
|
+
description:
|
|
10
|
+
"Place a limit or market order on Buda.com. " +
|
|
11
|
+
"IMPORTANT: To prevent accidental execution from ambiguous prompts, you must pass " +
|
|
12
|
+
"confirmation_token='CONFIRM' to execute the order. " +
|
|
13
|
+
"Requires BUDA_API_KEY and BUDA_API_SECRET environment variables. " +
|
|
14
|
+
"WARNING: Only use this tool on a locally-run instance — never on a publicly exposed server.",
|
|
15
|
+
inputSchema: {
|
|
16
|
+
type: "object" as const,
|
|
17
|
+
properties: {
|
|
18
|
+
market_id: {
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "Market ID (e.g. 'BTC-CLP', 'ETH-BTC').",
|
|
21
|
+
},
|
|
22
|
+
type: {
|
|
23
|
+
type: "string",
|
|
24
|
+
description: "Order side: 'Bid' to buy, 'Ask' to sell.",
|
|
25
|
+
},
|
|
26
|
+
price_type: {
|
|
27
|
+
type: "string",
|
|
28
|
+
description: "Order type: 'limit' places at a specific price, 'market' executes immediately.",
|
|
29
|
+
},
|
|
30
|
+
amount: {
|
|
31
|
+
type: "number",
|
|
32
|
+
description: "Order size in the market's base currency (e.g. BTC amount for BTC-CLP).",
|
|
33
|
+
},
|
|
34
|
+
limit_price: {
|
|
35
|
+
type: "number",
|
|
36
|
+
description:
|
|
37
|
+
"Limit price in quote currency. Required when price_type is 'limit'. " +
|
|
38
|
+
"For Bid orders: highest price you will pay. For Ask orders: lowest price you will accept.",
|
|
39
|
+
},
|
|
40
|
+
confirmation_token: {
|
|
41
|
+
type: "string",
|
|
42
|
+
description:
|
|
43
|
+
"Safety confirmation. Must equal exactly 'CONFIRM' (case-sensitive) to execute the order. " +
|
|
44
|
+
"Any other value will reject the request without placing an order.",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
required: ["market_id", "type", "price_type", "amount", "confirmation_token"],
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type PlaceOrderArgs = {
|
|
52
|
+
market_id: string;
|
|
53
|
+
type: "Bid" | "Ask";
|
|
54
|
+
price_type: "limit" | "market";
|
|
55
|
+
amount: number;
|
|
56
|
+
limit_price?: number;
|
|
57
|
+
confirmation_token: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export async function handlePlaceOrder(
|
|
61
|
+
args: PlaceOrderArgs,
|
|
62
|
+
client: BudaClient,
|
|
63
|
+
): Promise<{ content: Array<{ type: "text"; text: string }>; isError?: boolean }> {
|
|
64
|
+
const { market_id, type, price_type, amount, limit_price, confirmation_token } = args;
|
|
65
|
+
|
|
66
|
+
if (confirmation_token !== "CONFIRM") {
|
|
67
|
+
return {
|
|
68
|
+
content: [
|
|
69
|
+
{
|
|
70
|
+
type: "text",
|
|
71
|
+
text: JSON.stringify({
|
|
72
|
+
error:
|
|
73
|
+
"Order not placed. confirmation_token must equal 'CONFIRM' to execute. " +
|
|
74
|
+
"Review the order details and set confirmation_token='CONFIRM' to proceed.",
|
|
75
|
+
code: "CONFIRMATION_REQUIRED",
|
|
76
|
+
order_preview: { market_id, type, price_type, amount, limit_price },
|
|
77
|
+
}),
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
isError: true,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const validationError = validateMarketId(market_id);
|
|
85
|
+
if (validationError) {
|
|
86
|
+
return {
|
|
87
|
+
content: [{ type: "text", text: JSON.stringify({ error: validationError, code: "INVALID_MARKET_ID" }) }],
|
|
88
|
+
isError: true,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const payload: Record<string, unknown> = {
|
|
94
|
+
type,
|
|
95
|
+
price_type,
|
|
96
|
+
amount,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
if (price_type === "limit") {
|
|
100
|
+
if (limit_price === undefined) {
|
|
101
|
+
return {
|
|
102
|
+
content: [
|
|
103
|
+
{
|
|
104
|
+
type: "text",
|
|
105
|
+
text: JSON.stringify({
|
|
106
|
+
error: "limit_price is required when price_type is 'limit'.",
|
|
107
|
+
code: "VALIDATION_ERROR",
|
|
108
|
+
}),
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
isError: true,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
payload.limit = { price: limit_price, type: "gtc" };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const data = await client.post<OrderResponse>(
|
|
118
|
+
`/markets/${market_id.toLowerCase()}/orders`,
|
|
119
|
+
payload,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
content: [{ type: "text", text: JSON.stringify(data.order, null, 2) }],
|
|
124
|
+
};
|
|
125
|
+
} catch (err) {
|
|
126
|
+
const msg =
|
|
127
|
+
err instanceof BudaApiError
|
|
128
|
+
? { error: err.message, code: err.status, path: err.path }
|
|
129
|
+
: { error: String(err), code: "UNKNOWN" };
|
|
130
|
+
return {
|
|
131
|
+
content: [{ type: "text", text: JSON.stringify(msg) }],
|
|
132
|
+
isError: true,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
6
137
|
export function register(server: McpServer, client: BudaClient): void {
|
|
7
138
|
server.tool(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"IMPORTANT: To prevent accidental execution from ambiguous prompts, you must pass " +
|
|
11
|
-
"confirmation_token='CONFIRM' to execute the order. " +
|
|
12
|
-
"Requires BUDA_API_KEY and BUDA_API_SECRET environment variables. " +
|
|
13
|
-
"WARNING: Only use this tool on a locally-run instance — never on a publicly exposed server.",
|
|
139
|
+
toolSchema.name,
|
|
140
|
+
toolSchema.description,
|
|
14
141
|
{
|
|
15
142
|
market_id: z
|
|
16
143
|
.string()
|
|
@@ -40,68 +167,6 @@ export function register(server: McpServer, client: BudaClient): void {
|
|
|
40
167
|
"Any other value will reject the request without placing an order.",
|
|
41
168
|
),
|
|
42
169
|
},
|
|
43
|
-
|
|
44
|
-
if (confirmation_token !== "CONFIRM") {
|
|
45
|
-
return {
|
|
46
|
-
content: [
|
|
47
|
-
{
|
|
48
|
-
type: "text",
|
|
49
|
-
text: JSON.stringify({
|
|
50
|
-
error:
|
|
51
|
-
"Order not placed. confirmation_token must equal 'CONFIRM' to execute. " +
|
|
52
|
-
"Review the order details and set confirmation_token='CONFIRM' to proceed.",
|
|
53
|
-
code: "CONFIRMATION_REQUIRED",
|
|
54
|
-
order_preview: { market_id, type, price_type, amount, limit_price },
|
|
55
|
-
}),
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
isError: true,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
const payload: Record<string, unknown> = {
|
|
64
|
-
type,
|
|
65
|
-
price_type,
|
|
66
|
-
amount,
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
if (price_type === "limit") {
|
|
70
|
-
if (limit_price === undefined) {
|
|
71
|
-
return {
|
|
72
|
-
content: [
|
|
73
|
-
{
|
|
74
|
-
type: "text",
|
|
75
|
-
text: JSON.stringify({
|
|
76
|
-
error: "limit_price is required when price_type is 'limit'.",
|
|
77
|
-
code: "VALIDATION_ERROR",
|
|
78
|
-
}),
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
isError: true,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
payload.limit = { price: limit_price, type: "gtc" };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const data = await client.post<OrderResponse>(
|
|
88
|
-
`/markets/${market_id.toLowerCase()}/orders`,
|
|
89
|
-
payload,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
content: [{ type: "text", text: JSON.stringify(data.order, null, 2) }],
|
|
94
|
-
};
|
|
95
|
-
} catch (err) {
|
|
96
|
-
const msg =
|
|
97
|
-
err instanceof BudaApiError
|
|
98
|
-
? { error: err.message, code: err.status, path: err.path }
|
|
99
|
-
: { error: String(err), code: "UNKNOWN" };
|
|
100
|
-
return {
|
|
101
|
-
content: [{ type: "text", text: JSON.stringify(msg) }],
|
|
102
|
-
isError: true,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
},
|
|
170
|
+
(args) => handlePlaceOrder(args, client),
|
|
106
171
|
);
|
|
107
172
|
}
|
|
@@ -2,6 +2,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { BudaClient, BudaApiError } from "../client.js";
|
|
4
4
|
import { MemoryCache } from "../cache.js";
|
|
5
|
+
import { validateMarketId } from "../validation.js";
|
|
5
6
|
import type { TradesResponse } from "../types.js";
|
|
6
7
|
|
|
7
8
|
const PERIOD_MS: Record<string, number> = {
|
|
@@ -20,13 +21,40 @@ interface OhlcvCandle {
|
|
|
20
21
|
trade_count: number;
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
export const toolSchema = {
|
|
25
|
+
name: "get_price_history",
|
|
26
|
+
description:
|
|
27
|
+
"IMPORTANT: Candles are aggregated client-side from raw trades (Buda has no native candlestick " +
|
|
28
|
+
"endpoint) — fetching more trades via the 'limit' parameter gives deeper history but slower " +
|
|
29
|
+
"responses. Returns OHLCV (open/high/low/close/volume) price history for a Buda.com market. " +
|
|
30
|
+
"Candle timestamps are UTC bucket boundaries (e.g. '2026-04-10T12:00:00.000Z' for 1h). " +
|
|
31
|
+
"Supports 1h, 4h, and 1d candle periods.",
|
|
32
|
+
inputSchema: {
|
|
33
|
+
type: "object" as const,
|
|
34
|
+
properties: {
|
|
35
|
+
market_id: {
|
|
36
|
+
type: "string",
|
|
37
|
+
description: "Market ID (e.g. 'BTC-CLP', 'ETH-BTC').",
|
|
38
|
+
},
|
|
39
|
+
period: {
|
|
40
|
+
type: "string",
|
|
41
|
+
description: "Candle period: '1h' (1 hour), '4h' (4 hours), or '1d' (1 day). Default: '1h'.",
|
|
42
|
+
},
|
|
43
|
+
limit: {
|
|
44
|
+
type: "number",
|
|
45
|
+
description:
|
|
46
|
+
"Raw trades to fetch before aggregation (default: 100, max: 1000). " +
|
|
47
|
+
"More trades = deeper history but slower response.",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
required: ["market_id"],
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
23
54
|
export function register(server: McpServer, client: BudaClient, _cache: MemoryCache): void {
|
|
24
55
|
server.tool(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"recent trade history (up to 100 trades). Buda does not provide a native candlestick endpoint; " +
|
|
28
|
-
"candles are aggregated client-side from raw trades. Use the 'period' parameter to control " +
|
|
29
|
-
"candle size (1h, 4h, or 1d).",
|
|
56
|
+
toolSchema.name,
|
|
57
|
+
toolSchema.description,
|
|
30
58
|
{
|
|
31
59
|
market_id: z
|
|
32
60
|
.string()
|
|
@@ -39,12 +67,23 @@ export function register(server: McpServer, client: BudaClient, _cache: MemoryCa
|
|
|
39
67
|
.number()
|
|
40
68
|
.int()
|
|
41
69
|
.min(1)
|
|
42
|
-
.max(
|
|
70
|
+
.max(1000)
|
|
43
71
|
.optional()
|
|
44
|
-
.describe(
|
|
72
|
+
.describe(
|
|
73
|
+
"Raw trades to fetch before aggregation (default: 100, max: 1000). " +
|
|
74
|
+
"More trades = deeper history but slower response.",
|
|
75
|
+
),
|
|
45
76
|
},
|
|
46
77
|
async ({ market_id, period, limit }) => {
|
|
47
78
|
try {
|
|
79
|
+
const validationError = validateMarketId(market_id);
|
|
80
|
+
if (validationError) {
|
|
81
|
+
return {
|
|
82
|
+
content: [{ type: "text", text: JSON.stringify({ error: validationError, code: "INVALID_MARKET_ID" }) }],
|
|
83
|
+
isError: true,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
48
87
|
const id = market_id.toLowerCase();
|
|
49
88
|
const tradesLimit = limit ?? 100;
|
|
50
89
|
|
|
@@ -108,7 +147,10 @@ export function register(server: McpServer, client: BudaClient, _cache: MemoryCa
|
|
|
108
147
|
market_id: market_id.toUpperCase(),
|
|
109
148
|
period,
|
|
110
149
|
candle_count: candles.length,
|
|
111
|
-
|
|
150
|
+
trades_fetched: entries.length,
|
|
151
|
+
note:
|
|
152
|
+
"Candles derived from raw trade history. Candle timestamps are UTC bucket boundaries. " +
|
|
153
|
+
"Increase 'limit' (max 1000) for deeper history.",
|
|
112
154
|
candles,
|
|
113
155
|
};
|
|
114
156
|
|
package/src/tools/spread.ts
CHANGED
|
@@ -2,13 +2,30 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { BudaClient, BudaApiError } from "../client.js";
|
|
4
4
|
import { MemoryCache, CACHE_TTL } from "../cache.js";
|
|
5
|
+
import { validateMarketId } from "../validation.js";
|
|
5
6
|
import type { TickerResponse } from "../types.js";
|
|
6
7
|
|
|
8
|
+
export const toolSchema = {
|
|
9
|
+
name: "get_spread",
|
|
10
|
+
description:
|
|
11
|
+
"Calculate the bid/ask spread for a Buda.com market. " +
|
|
12
|
+
"Returns the best bid, best ask, absolute spread, and spread as a percentage of the ask price.",
|
|
13
|
+
inputSchema: {
|
|
14
|
+
type: "object" as const,
|
|
15
|
+
properties: {
|
|
16
|
+
market_id: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "Market ID (e.g. 'BTC-CLP', 'ETH-BTC', 'BTC-COP').",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
required: ["market_id"],
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
7
25
|
export function register(server: McpServer, client: BudaClient, cache: MemoryCache): void {
|
|
8
26
|
server.tool(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"Returns the best bid, best ask, absolute spread, and spread as a percentage of the ask price.",
|
|
27
|
+
toolSchema.name,
|
|
28
|
+
toolSchema.description,
|
|
12
29
|
{
|
|
13
30
|
market_id: z
|
|
14
31
|
.string()
|
|
@@ -16,6 +33,14 @@ export function register(server: McpServer, client: BudaClient, cache: MemoryCac
|
|
|
16
33
|
},
|
|
17
34
|
async ({ market_id }) => {
|
|
18
35
|
try {
|
|
36
|
+
const validationError = validateMarketId(market_id);
|
|
37
|
+
if (validationError) {
|
|
38
|
+
return {
|
|
39
|
+
content: [{ type: "text", text: JSON.stringify({ error: validationError, code: "INVALID_MARKET_ID" }) }],
|
|
40
|
+
isError: true,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
19
44
|
const id = market_id.toLowerCase();
|
|
20
45
|
const data = await cache.getOrFetch<TickerResponse>(
|
|
21
46
|
`ticker:${id}`,
|