gainium-mcp 2.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Gainium
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # gainium-mcp
2
+
3
+ An MCP (Model Context Protocol) server for [Gainium](https://gainium.io) — the crypto trading bot platform. Lets AI assistants manage your bots, deals, balances, and more through a standard MCP interface.
4
+
5
+ ## Quick Start
6
+
7
+ ### 1. Get your API keys
8
+
9
+ Go to [Gainium API Settings](https://app.gainium.io/app/api) and create an API key pair.
10
+
11
+ ### 2. Add to your MCP client
12
+
13
+ Add this to your MCP configuration (VS Code, Claude Desktop, etc.):
14
+
15
+ ```json
16
+ {
17
+ "gainium-mcp": {
18
+ "command": "npx",
19
+ "args": ["-y", "gainium-mcp"],
20
+ "env": {
21
+ "GAINIUM_API_KEY": "<your-api-key>",
22
+ "GAINIUM_API_SECRET": "<your-api-secret>"
23
+ }
24
+ }
25
+ }
26
+ ```
27
+
28
+ That's it. The server starts automatically when your AI assistant needs it.
29
+
30
+ ### Environment Variables
31
+
32
+ | Variable | Required | Default | Description |
33
+ |---|---|---|---|
34
+ | `GAINIUM_API_KEY` | Yes | — | Your Gainium API public key |
35
+ | `GAINIUM_API_SECRET` | Yes | — | Your Gainium API secret |
36
+ | `GAINIUM_API_BASE_URL` | No | `https://api.gainium.io` | API base URL |
37
+
38
+ ## Available Tools (31)
39
+
40
+ ### Bots — Read
41
+
42
+ | Tool | Description |
43
+ |---|---|
44
+ | `get_dca_bots` | List DCA bots with field selection and filters |
45
+ | `get_combo_bots` | List Combo bots with field selection and filters |
46
+ | `get_grid_bots` | List Grid bots with field selection and filters |
47
+
48
+ ### Bots — Create
49
+
50
+ | Tool | Description |
51
+ |---|---|
52
+ | `create_dca_bot` | Create a new DCA bot |
53
+ | `create_combo_bot` | Create a new Combo bot |
54
+ | `create_grid_bot` | Create a new Grid bot |
55
+
56
+ ### Bots — Update & Clone
57
+
58
+ | Tool | Description |
59
+ |---|---|
60
+ | `update_dca_bot` | Update DCA bot settings |
61
+ | `update_combo_bot` | Update Combo bot settings |
62
+ | `clone_dca_bot` | Clone a DCA bot with optional overrides |
63
+ | `clone_combo_bot` | Clone a Combo bot with optional overrides |
64
+
65
+ ### Bots — Lifecycle
66
+
67
+ | Tool | Description |
68
+ |---|---|
69
+ | `start_bot` | Start a bot |
70
+ | `stop_bot` | Stop a running bot |
71
+ | `archive_bot` | Archive a stopped bot |
72
+ | `restore_bot` | Restore an archived bot |
73
+ | `change_bot_pairs` | Change trading pairs for a bot |
74
+
75
+ ### Deals
76
+
77
+ | Tool | Description |
78
+ |---|---|
79
+ | `get_deals` | List deals with filters (type, status, botId) |
80
+ | `create_terminal_deal` | Create a one-time terminal deal |
81
+ | `update_dca_deal` | Update active DCA deal settings |
82
+ | `update_combo_deal` | Update active Combo deal settings |
83
+ | `start_deal` | Start a new deal for a bot |
84
+ | `close_deal` | Close an active deal |
85
+ | `add_funds` | Add funds to a deal |
86
+ | `reduce_funds` | Reduce funds from a deal |
87
+
88
+ ### User & Account
89
+
90
+ | Tool | Description |
91
+ |---|---|
92
+ | `get_balances` | Get balances across exchanges |
93
+ | `get_user_exchanges` | List connected exchange accounts |
94
+ | `get_global_variables` | List global variables |
95
+ | `create_global_variable` | Create a global variable |
96
+ | `update_global_variable` | Update a global variable |
97
+ | `delete_global_variable` | Delete a global variable |
98
+
99
+ ### General
100
+
101
+ | Tool | Description |
102
+ |---|---|
103
+ | `get_supported_exchanges` | List supported exchanges |
104
+ | `get_screener` | Crypto screener with market metrics |
105
+
106
+ ## Field Selection
107
+
108
+ All GET endpoints support the `fields` parameter for efficient payloads:
109
+
110
+ - **Presets**: `minimal`, `standard` (default), `extended`, `full`
111
+ - **Custom**: comma-separated dot-notation fields (e.g. `_id,uuid,settings.name,profit.total`)
112
+
113
+ Using `minimal` reduces payload size by ~85%.
114
+
115
+ ## API Permissions
116
+
117
+ - **Read-only key**: Use `get_*` tools (bots, deals, balances, screener)
118
+ - **Write key**: All tools including create, update, start, stop, archive
119
+
120
+ ## Development
121
+
122
+ ```bash
123
+ # Clone and install
124
+ git clone https://github.com/nicogainium/gainium-mcp.git
125
+ cd gainium-mcp
126
+ npm install
127
+
128
+ # Build
129
+ npm run build
130
+
131
+ # Run locally (for testing)
132
+ export GAINIUM_API_KEY=your_key
133
+ export GAINIUM_API_SECRET=your_secret
134
+ node dist/server.js
135
+ ```
136
+
137
+ ## Architecture
138
+
139
+ ```
140
+ gainium-mcp/
141
+ ├── src/
142
+ │ ├── server.ts # MCP server + tool definitions (stdio transport)
143
+ │ └── gainium-client.ts # HMAC-authenticated HTTP client for Gainium API v2
144
+ ├── dist/ # Compiled output (published to npm)
145
+ ├── package.json
146
+ ├── tsconfig.json
147
+ └── README.md
148
+ ```
149
+
150
+ ## License
151
+
152
+ MIT
@@ -0,0 +1,77 @@
1
+ import * as crypto from "crypto";
2
+ export class GainiumClient {
3
+ baseUrl;
4
+ apiKey;
5
+ apiSecret;
6
+ constructor(baseUrl, apiKey, apiSecret) {
7
+ this.baseUrl = baseUrl;
8
+ this.apiKey = apiKey;
9
+ this.apiSecret = apiSecret;
10
+ }
11
+ async request(method, endpoint, options) {
12
+ // Build query string
13
+ const params = new URLSearchParams();
14
+ if (options?.query) {
15
+ for (const [key, value] of Object.entries(options.query)) {
16
+ if (value === undefined || value === null || value === "")
17
+ continue;
18
+ if (Array.isArray(value)) {
19
+ for (const v of value) {
20
+ params.append(key, v);
21
+ }
22
+ }
23
+ else {
24
+ params.append(key, String(value));
25
+ }
26
+ }
27
+ }
28
+ const queryString = params.toString() ? `?${params.toString()}` : "";
29
+ const fullEndpoint = endpoint + queryString;
30
+ const url = `${this.baseUrl}${fullEndpoint}`;
31
+ const timestamp = Date.now();
32
+ const bodyStr = options?.body && method !== "GET" ? JSON.stringify(options.body) : "";
33
+ // Signature: HMAC-SHA256 of {body + method + endpoint + timestamp}
34
+ const prehash = bodyStr + method + fullEndpoint + timestamp;
35
+ const signature = crypto
36
+ .createHmac("sha256", this.apiSecret)
37
+ .update(prehash)
38
+ .digest("base64");
39
+ console.error(`[Gainium API] ${method} ${fullEndpoint}`);
40
+ const fetchOptions = {
41
+ method,
42
+ headers: {
43
+ "Content-Type": "application/json",
44
+ token: this.apiKey,
45
+ time: timestamp.toString(),
46
+ signature: signature,
47
+ },
48
+ };
49
+ if (bodyStr) {
50
+ fetchOptions.body = bodyStr;
51
+ }
52
+ const response = await fetch(url, fetchOptions);
53
+ if (!response.ok) {
54
+ const errorText = await response.text();
55
+ let parsed;
56
+ try {
57
+ parsed = JSON.parse(errorText);
58
+ }
59
+ catch {
60
+ throw new Error(`Gainium API error ${response.status}: ${errorText}`);
61
+ }
62
+ if (parsed?.reason) {
63
+ throw new Error(`Gainium API error: ${parsed.reason}`);
64
+ }
65
+ throw new Error(`Gainium API error ${response.status}: ${response.statusText}`);
66
+ }
67
+ const data = (await response.json());
68
+ if (data.status === "NOTOK") {
69
+ const errMsg = data.reason || "API request failed";
70
+ const details = data.errors
71
+ ? ` Details: ${JSON.stringify(data.errors)}`
72
+ : "";
73
+ throw new Error(errMsg + details);
74
+ }
75
+ return data;
76
+ }
77
+ }