mirror of
https://github.com/GMGNAI/gmgn-skills.git
synced 2026-07-28 09:17:45 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3551bc3a25 | |||
| 8448787176 | |||
| 04389b98f0 | |||
| 2949ea7de3 | |||
| 4dde77c481 | |||
| 02d497df92 | |||
| 48a06cd9b4 | |||
| 9e90bb9c07 | |||
| 31fababfd8 | |||
| 6833ff19cd | |||
| ccf3dc1c23 | |||
| 3c1ffdd7eb | |||
| 10d9c592d2 | |||
| ff3f52f3d8 | |||
| 1ea71149d9 | |||
| ca3c640afc | |||
| 2073b5fdaf | |||
| fce314b9ab | |||
| dbe3eec697 |
@@ -42,6 +42,14 @@ Data across SOL / BSC / Base is live on every query. Supports multi-parameter cu
|
||||
- Market orders, limit orders, and strategy orders (take-profit / stop-loss) in a single command.
|
||||
- Sell by position percentage (`--percent 50`) without calculating exact amounts.
|
||||
|
||||
| Order Type | Description |
|
||||
|------------|-------------|
|
||||
| Market Order | Instant execution at current market price |
|
||||
| Limit Order | Trigger buy or sell at a specified price |
|
||||
| Take-Profit / Stop-Loss | Fixed-price exit conditions attached to a swap |
|
||||
| Trailing Take-Profit / Trailing Stop-Loss | Tracks price peak; fires after a specified drawdown % — rides momentum while protecting gains |
|
||||
| Multi-Wallet Batch Trading | Buy with multiple wallets simultaneously, each with its own take-profit / stop-loss / trailing take-profit / trailing stop-loss orders |
|
||||
|
||||
### 3. More comprehensive token data
|
||||
|
||||
No more scraping web pages or getting blocked by Cloudflare. Query all the professional analytics needed for high-frequency Meme token trading, with high concurrency in real time (including but not limited to):
|
||||
@@ -158,7 +166,7 @@ echo 'GMGN_API_KEY=<user_api_key>' > ~/.config/gmgn/.env
|
||||
chmod 600 ~/.config/gmgn/.env
|
||||
```
|
||||
|
||||
If the user also needs swap capability, append the private key:
|
||||
If the user also needs swap or order capability, append the private key:
|
||||
|
||||
```bash
|
||||
# Append private key (use the PEM content from Step 3)
|
||||
@@ -500,7 +508,7 @@ gmgn-cli track smartmoney --limit 100 --raw
|
||||
gmgn-cli track smartmoney --chain sol --side sell --limit 50 --raw
|
||||
```
|
||||
|
||||
### Swap (requires private key)
|
||||
### Swap / Quote / Query
|
||||
|
||||
```bash
|
||||
# Submit swap with fixed slippage
|
||||
@@ -539,10 +547,21 @@ gmgn-cli order quote \
|
||||
--amount 1000000 \
|
||||
--slippage 0.01
|
||||
|
||||
# Quotes use critical auth and require GMGN_PRIVATE_KEY on every chain
|
||||
gmgn-cli order quote \
|
||||
--chain bsc \
|
||||
--from <wallet-address> \
|
||||
--input-token <input-token-addr> \
|
||||
--output-token <output-token-addr> \
|
||||
--amount 1000000000000000000 \
|
||||
--slippage 0.01
|
||||
|
||||
# Query order
|
||||
gmgn-cli order get --chain sol --order-id <order-id>
|
||||
```
|
||||
|
||||
> `order quote` uses critical auth on `sol` / `bsc` / `base` and requires `GMGN_PRIVATE_KEY`.
|
||||
|
||||
### Swap with Take-Profit / Stop-Loss Orders (requires private key)
|
||||
|
||||
**`hold_amount` mode** — each condition order fires based on current holdings at trigger time:
|
||||
|
||||
+21
-3
@@ -45,6 +45,14 @@ SOL / BSC / Base 多链数据每次查询均为实时,支持多参数个性化
|
||||
- 单条命令支持市价单、限价单、策略单(止盈 / 止损)。
|
||||
- 支持按仓位比例卖出(`--percent 50`),无需手动计算数量。
|
||||
|
||||
| 订单类型 | 说明 |
|
||||
|----------|------|
|
||||
| 市价单 | 以当前市价即时成交 |
|
||||
| 限价单 | 设定触发价格,到价买入或卖出 |
|
||||
| 止盈 / 止损 | 随买单附带固定价格的退出条件 |
|
||||
| 追踪止盈 / 追踪止损 | 跟踪价格峰值,回撤达到指定比例后触发,吃满行情同时保护收益 |
|
||||
| 多钱包批量交易 | 多个钱包同时买入,每个钱包分别创建对应的止盈 / 止损 / 追踪止盈 / 追踪止损订单 |
|
||||
|
||||
### 3. 特色数据更全
|
||||
|
||||
不用再爬网页,不会被Claudeflare拦截,现在就可以快速/多并发实时查询多链的 Meme 代币高频交易所需的所有专业分析指标数据 (包括不限于):
|
||||
@@ -164,7 +172,7 @@ echo 'GMGN_API_KEY=<user_api_key>' > ~/.config/gmgn/.env
|
||||
chmod 600 ~/.config/gmgn/.env
|
||||
```
|
||||
|
||||
如果用户需要 swap 能力,追加私钥:
|
||||
如果用户需要 swap 或 order 能力,追加私钥:
|
||||
|
||||
```bash
|
||||
# 追加私钥(使用第 3 步输出的 PEM 内容)
|
||||
@@ -443,7 +451,6 @@ solana 上的 <token_address> 安全吗,值得买入吗?
|
||||
完整参数说明:[docs/cli-usage.md](docs/cli-usage.md)。所有命令均支持 `--raw` 输出单行 JSON(方便 `jq` 等工具处理)。
|
||||
|
||||
### Token
|
||||
|
||||
```bash
|
||||
# 基本信息 + 实时价格
|
||||
gmgn-cli token info --chain sol --address <addr>
|
||||
@@ -532,7 +539,7 @@ gmgn-cli track smartmoney --limit 100 --raw
|
||||
gmgn-cli track smartmoney --chain sol --side sell --limit 50 --raw
|
||||
```
|
||||
|
||||
### Swap(需要私钥)
|
||||
### Swap / Quote / Query
|
||||
|
||||
```bash
|
||||
# 提交兑换(固定滑点)
|
||||
@@ -571,10 +578,21 @@ gmgn-cli order quote \
|
||||
--amount 1000000 \
|
||||
--slippage 0.01
|
||||
|
||||
# 所有链上的 quote 都走关键鉴权,需要 GMGN_PRIVATE_KEY
|
||||
gmgn-cli order quote \
|
||||
--chain bsc \
|
||||
--from <wallet-address> \
|
||||
--input-token <input-token-addr> \
|
||||
--output-token <output-token-addr> \
|
||||
--amount 1000000000000000000 \
|
||||
--slippage 0.01
|
||||
|
||||
# 查询订单状态
|
||||
gmgn-cli order get --chain sol --order-id <order-id>
|
||||
```
|
||||
|
||||
> `order quote` 在 `sol` / `bsc` / `base` 上都走关键鉴权,必须配置 `GMGN_PRIVATE_KEY`。
|
||||
|
||||
### 带止盈止损的 Swap(需要私钥)
|
||||
|
||||
**`hold_amount` 模式** — 按触发时的实际持仓比例卖出:
|
||||
|
||||
+2
-2
@@ -344,7 +344,7 @@ npx gmgn-cli portfolio smartmoney [--limit <n>] [--raw]
|
||||
|
||||
## order quote
|
||||
|
||||
Get a swap quote without submitting a transaction. Uses normal auth — no private key required.
|
||||
Get a swap quote without submitting a transaction. All supported quote chains use critical auth and require `GMGN_PRIVATE_KEY`.
|
||||
|
||||
```bash
|
||||
npx gmgn-cli order quote \
|
||||
@@ -359,7 +359,7 @@ npx gmgn-cli order quote \
|
||||
|
||||
| Option | Required | Description |
|
||||
|--------|----------|-------------|
|
||||
| `--chain` | Yes | `sol` / `bsc` / `base` |
|
||||
| `--chain` | Yes | `sol` / `bsc` / `base` (all require `GMGN_PRIVATE_KEY` for quote) |
|
||||
| `--from` | Yes | Wallet address (must match API Key binding) |
|
||||
| `--input-token` | Yes | Input token contract address |
|
||||
| `--output-token` | Yes | Output token contract address |
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "gmgn-cli",
|
||||
"version": "1.2.2",
|
||||
"version": "1.2.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "gmgn-cli",
|
||||
"version": "1.2.2",
|
||||
"version": "1.2.3",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"commander": "^12.1.0",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gmgn-cli",
|
||||
"version": "1.2.2",
|
||||
"version": "1.2.3",
|
||||
"description": "GMGN OpenAPI CLI — call GMGN market, token, portfolio and swap APIs from the command line",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
@@ -167,7 +167,7 @@ Token creation is **asynchronous**. If the initial `cooking create` response sho
|
||||
```bash
|
||||
gmgn-cli order get --chain <chain> --order-id <order_id>
|
||||
```
|
||||
2. The new token's contract / mint address is in the **`output_token`** field of the `order get` response — it is NOT returned by `cooking create` directly.
|
||||
2. The new token's contract / mint address is in the **`report.output_token`** field of the `order get` response (only present when `state = 30` and `status = "successful"`) — it is NOT returned by `cooking create` directly.
|
||||
3. Stop polling once `status` is `confirmed`, `failed`, or `expired`.
|
||||
4. On `confirmed`: display `output_token` as the token address and include the block explorer link.
|
||||
5. On `failed` / `expired`: report the `error_status` and do not retry automatically.
|
||||
|
||||
@@ -212,6 +212,29 @@ The response is an object (or array for batch). Key fields:
|
||||
| `sell_count` | Number of sell transactions |
|
||||
| `pnl` | Profit/loss ratio = `realized_profit / total_cost` |
|
||||
|
||||
The response also includes a `common` object when available (absent if the upstream identity service is unavailable):
|
||||
|
||||
| Field | Description |
|
||||
|-------|-------------|
|
||||
| `common.avatar` | Wallet avatar URL |
|
||||
| `common.name` | Display name |
|
||||
| `common.ens` | ENS domain (EVM chains only) |
|
||||
| `common.tag` | Primary wallet tag |
|
||||
| `common.tags` | All wallet tags (e.g. `["smart_money"]`) |
|
||||
| `common.twitter_username` | Twitter handle |
|
||||
| `common.twitter_name` | Twitter display name |
|
||||
| `common.followers_count` | Twitter follower count |
|
||||
| `common.is_blue_verified` | Twitter blue-verified badge |
|
||||
| `common.follow_count` | Number of GMGN users following this wallet |
|
||||
| `common.remark_count` | Number of GMGN users who have remarked this wallet |
|
||||
| `common.created_token_count` | Tokens created by this wallet |
|
||||
| `common.created_at` | Wallet creation time (Unix seconds) — records when the first funding transaction arrived; use this as the wallet's age indicator |
|
||||
| `common.fund_from` | Funding source label |
|
||||
| `common.fund_from_address` | Address that funded this wallet |
|
||||
| `common.fund_amount` | Funding amount |
|
||||
|
||||
Use `common.tags` and `common.twitter_username` when building a wallet profile narrative. If `common` is absent in the response, omit identity fields silently — do not report it as an error.
|
||||
|
||||
**Do NOT guess field names not listed here.** If a field appears in the response but is not in this table, do not interpret it without reading the raw output first.
|
||||
|
||||
## Output Format
|
||||
@@ -251,9 +274,10 @@ Win Rate: {winrate × 100}%
|
||||
Total Spent: ${total_cost}
|
||||
Buys / Sells: {buy_count} / {sell_count}
|
||||
PnL Ratio: {pnl}x
|
||||
[Identity: {common.name or common.twitter_username} | Tags: {common.tags}]
|
||||
```
|
||||
|
||||
For batch queries (multiple wallets), present one summary block per wallet.
|
||||
Show the `[Identity: ...]` line only if `common` is present in the response. For batch queries (multiple wallets), present one summary block per wallet.
|
||||
|
||||
## Notes
|
||||
|
||||
|
||||
+55
-28
@@ -12,7 +12,7 @@ metadata:
|
||||
|
||||
**⚠️ IPv6 NOT SUPPORTED: If you get a `401` or `403` error and credentials look correct, check for IPv6 immediately: (1) list all network interfaces and their IPv6 addresses — run `ifconfig | grep inet6` (macOS) or `ip addr show | grep inet6` (Linux); (2) send a test request to `https://ipv6.icanhazip.com` — if the response is an IPv6 address, outbound traffic is going via IPv6. Tell the user immediately: "Please disable IPv6 on your network interface — gmgn-cli commands only work over IPv4."**
|
||||
|
||||
Use the `gmgn-cli` tool to submit a token swap or query an existing order. **Requires private key** (`GMGN_PRIVATE_KEY` in `.env`).
|
||||
Use the `gmgn-cli` tool to submit a token swap or query an existing order. `GMGN_API_KEY` is always required. `GMGN_PRIVATE_KEY` is required for critical-auth commands such as `swap` and all `order` subcommands, including `order quote`.
|
||||
|
||||
## Core Concepts
|
||||
|
||||
@@ -26,11 +26,11 @@ Use the `gmgn-cli` tool to submit a token swap or query an existing order. **Req
|
||||
|
||||
- **Anti-MEV** — MEV (Miner/Maximal Extractable Value) refers to frontrunning and sandwich attacks where bots exploit pending transactions. `--anti-mev` routes the transaction through protected channels to reduce this risk. **Recommended: always enable.** Default: on.
|
||||
|
||||
- **Critical auth** — `swap` requires both `GMGN_API_KEY` and `GMGN_PRIVATE_KEY`. The private key never leaves the machine — the CLI uses it only for local signing and sends only the resulting signature. Normal commands (like `order quote`) use API Key alone.
|
||||
- **Critical auth** — `swap` and all `order` subcommands require both `GMGN_API_KEY` and `GMGN_PRIVATE_KEY`. The private key never leaves the machine — the CLI uses it only for local signing and sends only the resulting signature.
|
||||
|
||||
- **`order_id` / `status`** — After submitting a swap, the response includes an `order_id`. Use `order get --order-id` to poll for final status. Possible values: `pending` → `processed` → `confirmed` (success) or `failed` / `expired`. Do not report success until status is `confirmed`.
|
||||
|
||||
- **`filled_input_amount` / `filled_output_amount`** — Actual amounts consumed/received, in smallest unit. Convert to human-readable using token decimals before displaying to the user.
|
||||
- **`report.input_amount` / `report.output_amount`** — Actual amounts consumed/received, in smallest unit. Only present when `state = 30` and `status = "successful"`. Convert to human-readable using `report.input_token_decimals` / `report.output_token_decimals` before displaying to the user.
|
||||
|
||||
## Financial Risk Notice
|
||||
|
||||
@@ -46,7 +46,7 @@ Use the `gmgn-cli` tool to submit a token swap or query an existing order. **Req
|
||||
| Sub-command | Description |
|
||||
|-------------|-------------|
|
||||
| `swap` | Submit a token swap |
|
||||
| `order quote` | Get a swap quote (no transaction submitted) |
|
||||
| `order quote` | Get a swap quote (no transaction submitted; requires critical auth) |
|
||||
| `order get` | Query order status |
|
||||
| `order strategy create` | Create a limit/strategy order (requires private key) |
|
||||
| `order strategy list` | List strategy orders (requires private key) |
|
||||
@@ -70,7 +70,7 @@ Currency tokens are the base/native assets of each chain. They are used to buy o
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Both `GMGN_API_KEY` and `GMGN_PRIVATE_KEY` must be configured in `~/.config/gmgn/.env`. The private key must correspond to the wallet bound to the API Key.
|
||||
`GMGN_API_KEY` must be configured in `~/.config/gmgn/.env`. `GMGN_PRIVATE_KEY` is additionally required for `swap` and all `order` subcommands. The private key must correspond to the wallet bound to the API Key.
|
||||
|
||||
- `gmgn-cli` installed globally — if missing, run: `npm install -g gmgn-cli`
|
||||
|
||||
@@ -165,7 +165,7 @@ gmgn-cli swap \
|
||||
|
||||
## `order quote` Usage
|
||||
|
||||
Get an estimated output amount before submitting a swap. Uses normal auth — no private key required.
|
||||
Get an estimated output amount before submitting a swap. All supported quote chains use critical auth and require `GMGN_PRIVATE_KEY`.
|
||||
|
||||
```bash
|
||||
gmgn-cli order quote \
|
||||
@@ -273,26 +273,47 @@ gmgn-cli swap \
|
||||
|
||||
> `buy_amount`: each take-profit sells 50% of the **original** bought amount. Stop-loss sells 100% of the original bought amount.
|
||||
|
||||
## `swap` Response Fields
|
||||
## `swap` / `order get` Response Fields
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `order_id` | string | Order ID for follow-up queries |
|
||||
| `hash` | string | Transaction hash |
|
||||
| `status` | string | Order status: `pending` / `processed` / `confirmed` / `failed` / `expired` |
|
||||
| `error_code` | string | Error code on failure |
|
||||
| `error_status` | string | Error description on failure |
|
||||
| `input_token` | string | Input token contract address |
|
||||
| `output_token` | string | Output token contract address |
|
||||
| `filled_input_amount` | string | Actual input consumed (smallest unit); empty if not filled |
|
||||
| `filled_output_amount` | string | Actual output received (smallest unit); empty if not filled |
|
||||
| Field | Type | Description |
|
||||
| ------------------- | ------ | ---- |
|
||||
| `order_id` | string | Order ID for follow-up queries |
|
||||
| `hash` | string | Transaction hash |
|
||||
| `status` | string | Order status: `pending` / `processed` / `confirmed` / `failed` / `expired` |
|
||||
| `error_code` | string | Error code on failure |
|
||||
| `error_status` | string | Error description on failure |
|
||||
| `strategy_order_id` | string | Strategy order ID; only present when `--condition-orders` was passed and strategy creation succeeded (best-effort) |
|
||||
| `report` | object | Execution report; only present when `state = 30` and `status = "successful"`. See Report Fields below. |
|
||||
|
||||
### Report Fields (present only when `status = "successful"`)
|
||||
|
||||
| Field | Type | Description |
|
||||
| ----------------------- | ------- | ---- |
|
||||
| `input_token` | string | Input token contract address |
|
||||
| `input_token_decimals` | integer | Input token decimal places |
|
||||
| `swap_mode` | string | Swap mode: `ExactIn` / `ExactOut` |
|
||||
| `input_amount` | string | Actual input consumed (smallest unit) |
|
||||
| `output_token` | string | Output token contract address |
|
||||
| `output_token_decimals` | integer | Output token decimal places |
|
||||
| `output_amount` | string | Actual output received (smallest unit) |
|
||||
| `quote_token` | string | Quote token contract address |
|
||||
| `quote_decimals` | integer | Quote token decimal places |
|
||||
| `quote_amount` | string | Quote amount (smallest unit) |
|
||||
| `base_token` | string | Base token contract address |
|
||||
| `base_decimals` | integer | Base token decimal places |
|
||||
| `base_amount` | string | Base token amount (smallest unit) |
|
||||
| `price` | string | Execution price (quote/base token) |
|
||||
| `price_usd` | string | Execution price in USD |
|
||||
| `height` | integer | Block height of execution |
|
||||
| `order_height` | integer | Block height when order was placed |
|
||||
| `gas_native` | string | Gas fee in native token |
|
||||
| `gas_usd` | string | Gas fee in USD |
|
||||
|
||||
## Output Format
|
||||
|
||||
### Pre-swap Confirmation
|
||||
|
||||
Before displaying the confirmation, run `order quote` to get the estimated output (uses normal auth — no private key required):
|
||||
Before displaying the confirmation, run `order quote` to get the estimated output (requires critical auth and `GMGN_PRIVATE_KEY` on every supported quote chain):
|
||||
|
||||
```bash
|
||||
gmgn-cli order quote \
|
||||
@@ -334,13 +355,13 @@ After a confirmed swap, display:
|
||||
```
|
||||
✅ Swap Confirmed
|
||||
|
||||
Spent: {filled_input_amount in human units} {input symbol}
|
||||
Received: {filled_output_amount in human units} {output symbol}
|
||||
Spent: {report.input_amount in human units} {input symbol}
|
||||
Received: {report.output_amount in human units} {output symbol}
|
||||
Tx: {explorer link for hash}
|
||||
Order ID: {order_id}
|
||||
```
|
||||
|
||||
Convert `filled_input_amount` and `filled_output_amount` from smallest unit using token decimals before displaying.
|
||||
Convert `report.input_amount` and `report.output_amount` from smallest unit using `report.input_token_decimals` and `report.output_token_decimals` before displaying.
|
||||
|
||||
## `order strategy create` Parameters
|
||||
|
||||
@@ -380,7 +401,7 @@ Convert `filled_input_amount` and `filled_output_amount` from smallest unit usin
|
||||
| `--chain` | Yes | `sol` / `bsc` / `base` |
|
||||
| `--type` | No | `open` (default) / `history` |
|
||||
| `--from` | No | Filter by wallet address |
|
||||
| `--group-tag` | No | Filter by order group: `LimitOrder` (limit orders only) / `STMix` (mixed strategy orders: take-profit, stop-loss, trailing take-profit, trailing stop-loss) |
|
||||
| `--group-tag` | Yes | Filter by order group: `LimitOrder` (limit orders only) / `STMix` (mixed strategy orders: take-profit, stop-loss, trailing take-profit, trailing stop-loss) |
|
||||
| `--base-token` | No | Filter by token address |
|
||||
| `--page-token` | No | Pagination cursor from previous response |
|
||||
| `--limit` | No | Results per page (default 10 for history) |
|
||||
@@ -430,11 +451,17 @@ gmgn-cli order strategy create \
|
||||
--amount-in-percent 100 \
|
||||
--slippage 0.01
|
||||
|
||||
# List open strategy orders
|
||||
gmgn-cli order strategy list --chain sol
|
||||
# List open condition orders (profit_stop / loss_stop / trace types) — use STMix
|
||||
gmgn-cli order strategy list --chain sol --group-tag STMix
|
||||
|
||||
# List history orders with pagination
|
||||
gmgn-cli order strategy list --chain sol --type history --limit 20
|
||||
# List open limit orders (buy_low / buy_high / stop_loss / take_profit) — use LimitOrder
|
||||
gmgn-cli order strategy list --chain sol --group-tag LimitOrder
|
||||
|
||||
# List condition order history with pagination
|
||||
gmgn-cli order strategy list --chain sol --group-tag STMix --type history --limit 20
|
||||
|
||||
# Filter by token
|
||||
gmgn-cli order strategy list --chain sol --group-tag STMix --base-token <token_address>
|
||||
|
||||
# Cancel a strategy order
|
||||
gmgn-cli order strategy cancel \
|
||||
@@ -496,7 +523,7 @@ For full token research before swapping, see [`docs/workflow-token-research.md`]
|
||||
- **Percentage sell restriction** — `--percent` is ONLY valid when `input_token` is NOT a currency. Do NOT use `--percent` when `input_token` is SOL/BNB/ETH (native) or USDC. This includes: "sell 50% of my SOL", "use 30% of my BNB to buy X", "spend 50% of my USDC on X" — all unsupported. Explain the restriction to the user and ask for an explicit absolute amount instead.
|
||||
- **Chain-wallet compatibility** — SOL addresses are incompatible with EVM chains (bsc/base). Warn the user and abort if the address format does not match the chain.
|
||||
- **Credential sensitivity** — `GMGN_API_KEY` and `GMGN_PRIVATE_KEY` can directly execute trades on the linked wallet. Never log, display, or expose these values.
|
||||
- **Order polling** — After a swap, if `status` is not yet `confirmed` / `failed` / `expired`, poll with `order get` up to 3 times at 5-second intervals before reporting a timeout. Once confirmed, display the trade result using `filled_input_amount` and `filled_output_amount` (convert from smallest unit using token decimals), e.g. "Spent 0.1 SOL → received 98.5 USDC" or "Sold 1000 TOKEN → received 0.08 SOL".
|
||||
- **Order polling** — After a swap, if `status` is not yet `confirmed` / `failed` / `expired`, poll with `order get` up to 3 times at 5-second intervals before reporting a timeout. Once confirmed, display the trade result using `report.input_amount` and `report.output_amount` (convert from smallest unit using `report.input_token_decimals` / `report.output_token_decimals`), e.g. "Spent 0.1 SOL → received 98.5 USDC" or "Sold 1000 TOKEN → received 0.08 SOL".
|
||||
- **Block explorer links** — After a successful swap, display a clickable explorer link for the returned `hash`:
|
||||
|
||||
| Chain | Explorer |
|
||||
|
||||
@@ -142,7 +142,7 @@ Recommended combinations for common use cases:
|
||||
|
||||
### `token info` — Key Fields
|
||||
|
||||
The response has four nested objects: `pool`, `link`, `stat`, `wallet_tags_stat`. Access fields with dot notation when parsing (e.g. `link.website`, `stat.top_10_holder_rate`).
|
||||
The response has five nested objects: `pool`, `dev`, `link`, `stat`, `wallet_tags_stat`. Access fields with dot notation when parsing (e.g. `link.website`, `stat.top_10_holder_rate`, `dev.creator_address`).
|
||||
|
||||
**Top-level Fields**
|
||||
|
||||
@@ -162,6 +162,15 @@ The response has four nested objects: `pool`, `link`, `stat`, `wallet_tags_stat`
|
||||
| `open_timestamp` | Time the token opened for trading (Unix seconds) |
|
||||
| `biggest_pool_address` | Address of the main liquidity pool |
|
||||
| `og` | Whether the token is flagged as an OG token (`true` / `false`) |
|
||||
| `launchpad` | Launchpad identifier (e.g. `pump`, `moonshot`) |
|
||||
| `launchpad_status` | Launchpad state: `0` = not opened, `1` = live, `2` = migrated |
|
||||
| `launchpad_progress` | Launchpad bonding-curve progress (0–1) |
|
||||
| `launchpad_platform` | Launchpad platform name |
|
||||
| `migrated_pool` | Pool address after migration |
|
||||
| `migration_market_cap` | Market cap at migration time (USD, float) |
|
||||
| `migration_market_cap_quote` | Quote currency for `migration_market_cap` |
|
||||
| `ath_price` | All-time-high price (USD, float) |
|
||||
| `locked_ratio` | Ratio of supply locked (0–1, float) |
|
||||
|
||||
**`pool` Object** — Main liquidity pool details
|
||||
|
||||
@@ -179,6 +188,38 @@ The response has four nested objects: `pool`, `link`, `stat`, `wallet_tags_stat`
|
||||
| `pool.fee_ratio` | Pool trading fee ratio (e.g. `0.1` = 0.1%) |
|
||||
| `pool.creation_timestamp` | Pool creation time (Unix seconds) |
|
||||
|
||||
**`dev` Object** — Token creator / developer info
|
||||
|
||||
| Field | Description |
|
||||
|-------|-------------|
|
||||
| `dev.creator_address` | Creator wallet address |
|
||||
| `dev.creator_token_balance` | Creator's current token balance |
|
||||
| `dev.creator_token_status` | Creator holding status: `hold` (still holding) / `sell` (sold/exited) |
|
||||
| `dev.top_10_holder_rate` | Ratio of supply held by top 10 wallets (0–1) |
|
||||
| `dev.twitter_name_change_history` | Array of past Twitter username changes (each entry has `twitter_username`, `rename_timestamp`) |
|
||||
| `dev.dexscr_ad` | Creator bought a DEXScreener ad: `1` = yes, `0` = no |
|
||||
| `dev.dexscr_update_link` | Creator updated DEXScreener socials/links: `1` = yes, `0` = no |
|
||||
| `dev.dexscr_boost_fee` | Creator used DEXScreener Boost: `1` = yes, `0` = no |
|
||||
| `dev.dexscr_trending_bar` | Token appeared in DEXScreener trending bar: `1` = yes, `0` = no |
|
||||
| `dev.dexscr_ad_ts` | Timestamp of DEXScreener ad purchase (Unix seconds) |
|
||||
| `dev.dexscr_update_link_ts` | Timestamp of DEXScreener link update (Unix seconds) |
|
||||
| `dev.dexscr_boost_ts` | Timestamp of DEXScreener Boost (Unix seconds) |
|
||||
| `dev.dexscr_trending_bar_ts` | Timestamp of DEXScreener trending bar appearance (Unix seconds) |
|
||||
| `dev.cto_flag` | Token has been Community Takeover'd (original dev abandoned): `1` = yes, `0` = no |
|
||||
| `dev.fund_from` | Address that funded the creator wallet |
|
||||
| `dev.fund_from_ts` | Timestamp of that funding event (Unix seconds) |
|
||||
| `dev.creator_open_count` | Number of tokens this creator has previously launched |
|
||||
| `dev.twitter_del_post_token_count` | Number of posts the creator deleted from Twitter |
|
||||
| `dev.twitter_create_token_count` | Number of tokens the creator has promoted on Twitter |
|
||||
| `dev.offchain` | Whether the token is an offchain token |
|
||||
| `dev.ath_token_info` | Creator's all-time-high token info object (optional); see sub-fields below |
|
||||
| `dev.ath_token_info.ath_token` | Contract address of the creator's best-performing token ever |
|
||||
| `dev.ath_token_info.ath_mc` | All-time-high market cap of that token (USD, string) |
|
||||
| `dev.ath_token_info.avatar` | Token logo URL |
|
||||
| `dev.ath_token_info.symbol` | Token symbol |
|
||||
| `dev.ath_token_info.name` | Token name |
|
||||
| `dev.ath_token_info.creation_timestamp` | Token creation time (Unix seconds) |
|
||||
|
||||
**`link` Object** — Social and explorer links
|
||||
|
||||
| Field | Description |
|
||||
@@ -212,6 +253,7 @@ The response has four nested objects: `pool`, `link`, `stat`, `wallet_tags_stat`
|
||||
| `stat.bot_degen_count` | Number of bot degen wallets |
|
||||
| `stat.bot_degen_rate` | Ratio of bot degen wallets |
|
||||
| `stat.fresh_wallet_rate` | Ratio of fresh/new wallets among holders |
|
||||
| `stat.private_vault_hold_rate` | Ratio held by private vault (vanish) addresses — displayed as "vanish" in GMGN UI (0–1) |
|
||||
|
||||
**`wallet_tags_stat` Object** — Wallet type breakdown
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* Auth modes:
|
||||
* Normal (market/token/portfolio): X-APIKEY + timestamp + client_id
|
||||
* Critical (swap/order): normal auth + X-Signature (private key signature)
|
||||
* Critical (swap and order routes): normal auth + X-Signature (private key signature)
|
||||
*/
|
||||
|
||||
import { buildAuthQuery, buildMessage, detectAlgorithm, sign } from "./signer.js";
|
||||
@@ -293,9 +293,8 @@ export class OpenApiClient {
|
||||
input_amount: string,
|
||||
slippage: number
|
||||
): Promise<unknown> {
|
||||
return this.normalRequest("GET", "/v1/trade/quote", {
|
||||
chain, from_address, input_token, output_token, input_amount, slippage,
|
||||
});
|
||||
const query = { chain, from_address, input_token, output_token, input_amount, slippage };
|
||||
return this.criticalRequest("GET", "/v1/trade/quote", query, null);
|
||||
}
|
||||
|
||||
// ---- Swap endpoints (critical auth) ----
|
||||
@@ -367,7 +366,7 @@ export class OpenApiClient {
|
||||
body: unknown
|
||||
): Promise<unknown> {
|
||||
if (!this.privateKeyPem) {
|
||||
throw new Error("GMGN_PRIVATE_KEY is required for swap/order commands");
|
||||
throw new Error("GMGN_PRIVATE_KEY is required for critical-auth commands (swap and all order commands)");
|
||||
}
|
||||
|
||||
return this.executePreparedRequest(() => {
|
||||
|
||||
@@ -75,8 +75,8 @@ export function registerSwapCommands(program: Command): void {
|
||||
|
||||
order
|
||||
.command("quote")
|
||||
.description("Get a swap quote without submitting a transaction")
|
||||
.requiredOption("--chain <chain>", "Chain: sol / bsc / base")
|
||||
.description("Get a swap quote without submitting a transaction (requires critical auth)")
|
||||
.requiredOption("--chain <chain>", "Chain: sol / bsc / base (requires GMGN_PRIVATE_KEY)")
|
||||
.requiredOption("--from <address>", "Wallet address (must match API Key binding)")
|
||||
.requiredOption("--input-token <address>", "Input token contract address")
|
||||
.requiredOption("--output-token <address>", "Output token contract address")
|
||||
@@ -89,7 +89,7 @@ export function registerSwapCommands(program: Command): void {
|
||||
validateAddress(opts.inputToken, opts.chain, "--input-token");
|
||||
validateAddress(opts.outputToken, opts.chain, "--output-token");
|
||||
validatePositiveInt(opts.amount, "--amount");
|
||||
const client = new OpenApiClient(getConfig());
|
||||
const client = new OpenApiClient(getConfig(true));
|
||||
const data = await client
|
||||
.quoteOrder(opts.chain, opts.from, opts.inputToken, opts.outputToken, opts.amount, opts.slippage)
|
||||
.catch(exitOnError);
|
||||
|
||||
+4
-2
@@ -14,11 +14,13 @@ export interface Config {
|
||||
}
|
||||
|
||||
let _config: Config | null = null;
|
||||
const PRIVATE_KEY_REQUIRED_MSG =
|
||||
"GMGN_PRIVATE_KEY is required for critical-auth commands (swap and all order commands)";
|
||||
|
||||
export function getConfig(requirePrivateKey = false): Config {
|
||||
if (_config) {
|
||||
if (requirePrivateKey && !_config.privateKeyPem) {
|
||||
die("GMGN_PRIVATE_KEY is required for swap/order commands");
|
||||
die(PRIVATE_KEY_REQUIRED_MSG);
|
||||
}
|
||||
return _config;
|
||||
}
|
||||
@@ -34,7 +36,7 @@ export function getConfig(requirePrivateKey = false): Config {
|
||||
// Support escaped newlines (e.g. from single-line .env values)
|
||||
privateKeyPem = privateKey.replace(/\\n/g, "\n");
|
||||
} else if (requirePrivateKey) {
|
||||
die("GMGN_PRIVATE_KEY is required for swap/order commands");
|
||||
die(PRIVATE_KEY_REQUIRED_MSG);
|
||||
}
|
||||
|
||||
const host = process.env.GMGN_HOST ?? "https://openapi.gmgn.ai";
|
||||
|
||||
Reference in New Issue
Block a user