@farazirfan/costar-server-executor 1.7.20 → 1.7.21
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/web-server.d.ts.map +1 -1
- package/dist/web-server.js +99 -0
- package/dist/web-server.js.map +1 -1
- package/package.json +1 -1
- package/public/index.html +203 -0
- package/skills/coinbase/LEARNING.md +117 -0
- package/skills/coinbase/SKILL.md +217 -0
- package/skills/coinbase/references/api-reference.md +124 -0
- package/skills/coinbase/references/order-types.md +150 -0
- package/skills/coinbase/references/products.md +93 -0
- package/skills/coinbase/scripts/coinbase-trade.ts +274 -0
- package/skills/trading/SKILL.md +2 -4
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: coinbase
|
|
3
|
+
description: "Execute real trades on Coinbase Advanced Trade. Supports market, limit, stop-limit, and bracket orders for crypto. Handles account balances, order management, price data, portfolio tracking, and fee estimation. Use when the user wants to buy/sell crypto, check balances, place orders, manage positions, or do anything on Coinbase."
|
|
4
|
+
metadata:
|
|
5
|
+
emoji: "🪙"
|
|
6
|
+
requires:
|
|
7
|
+
env: ["COINBASE_API_KEY", "COINBASE_API_SECRET"]
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Coinbase Trading Executor
|
|
11
|
+
|
|
12
|
+
You can execute real trades on Coinbase using the Advanced Trade API. This is real money — be precise, confirm with the user, and never skip risk checks.
|
|
13
|
+
|
|
14
|
+
## CRITICAL: Always Read LEARNING.md First
|
|
15
|
+
|
|
16
|
+
**Before ANY Coinbase action, read [LEARNING.md](LEARNING.md).** It contains API quirks you've discovered, order patterns that work, mistakes to avoid, and fee insights from real trades.
|
|
17
|
+
|
|
18
|
+
## Authentication
|
|
19
|
+
|
|
20
|
+
The user's Coinbase API credentials are available as environment variables:
|
|
21
|
+
- `COINBASE_API_KEY` — format: `organizations/{org_id}/apiKeys/{key_id}`
|
|
22
|
+
- `COINBASE_API_SECRET` — EC private key in PEM format
|
|
23
|
+
|
|
24
|
+
These use **CDP (Coinbase Developer Platform) keys** with **ES256 JWT** authentication. The `coinbase-api` npm package handles JWT generation internally.
|
|
25
|
+
|
|
26
|
+
## Setup
|
|
27
|
+
|
|
28
|
+
Before first use, ensure the SDK is installed in the workspace:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm list coinbase-api 2>/dev/null || npm install coinbase-api
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## How to Execute Trades
|
|
35
|
+
|
|
36
|
+
All Coinbase operations use TypeScript/JavaScript scripts via `execute_code` or shell commands. Use the `coinbase-api` package:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { CBAdvancedTradeClient } from 'coinbase-api';
|
|
40
|
+
|
|
41
|
+
const client = new CBAdvancedTradeClient({
|
|
42
|
+
apiKey: process.env.COINBASE_API_KEY,
|
|
43
|
+
apiSecret: process.env.COINBASE_API_SECRET,
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Execution Workflow
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
- [ ] Step 1: Read LEARNING.md
|
|
51
|
+
- [ ] Step 2: Verify balances and account status
|
|
52
|
+
- [ ] Step 3: Get current price and market data
|
|
53
|
+
- [ ] Step 4: Preview the order (estimate fees/slippage)
|
|
54
|
+
- [ ] Step 5: Execute the order
|
|
55
|
+
- [ ] Step 6: Verify order fill and record result
|
|
56
|
+
- [ ] Step 7: Update LEARNING.md
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Step 2: Check Balances
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const accounts = await client.getAccounts();
|
|
63
|
+
for (const acct of accounts.accounts) {
|
|
64
|
+
if (parseFloat(acct.available_balance.value) > 0) {
|
|
65
|
+
console.log(`${acct.currency}: ${acct.available_balance.value}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Step 3: Get Price Data
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
// Current price
|
|
74
|
+
const product = await client.getProduct({ product_id: 'BTC-USD' });
|
|
75
|
+
console.log(`Price: $${product.price}, 24h change: ${product.price_percentage_change_24h}%`);
|
|
76
|
+
|
|
77
|
+
// Best bid/ask spread
|
|
78
|
+
const spread = await client.getBestBidAsk({ product_ids: ['BTC-USD'] });
|
|
79
|
+
|
|
80
|
+
// OHLCV candles (last 24h, 1-hour granularity)
|
|
81
|
+
const candles = await client.getProductCandles({
|
|
82
|
+
product_id: 'BTC-USD',
|
|
83
|
+
start: String(Math.floor(Date.now() / 1000) - 86400),
|
|
84
|
+
end: String(Math.floor(Date.now() / 1000)),
|
|
85
|
+
granularity: 'ONE_HOUR',
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Step 4: Preview Order
|
|
90
|
+
|
|
91
|
+
**Always preview before executing.** This shows estimated fees and slippage:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const preview = await client.previewOrder({
|
|
95
|
+
product_id: 'BTC-USD',
|
|
96
|
+
side: 'BUY',
|
|
97
|
+
order_configuration: {
|
|
98
|
+
market_market_ioc: { quote_size: '100.00' },
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
// Shows: quote_size, base_size, best_bid, best_ask, total_fees, slippage
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Step 5: Place Orders
|
|
105
|
+
|
|
106
|
+
See [references/order-types.md](references/order-types.md) for all order types and configurations.
|
|
107
|
+
|
|
108
|
+
**Market Buy** (spend $X of quote currency):
|
|
109
|
+
```typescript
|
|
110
|
+
const order = await client.submitOrder({
|
|
111
|
+
client_order_id: crypto.randomUUID(),
|
|
112
|
+
product_id: 'BTC-USD',
|
|
113
|
+
side: 'BUY',
|
|
114
|
+
order_configuration: {
|
|
115
|
+
market_market_ioc: { quote_size: '100.00' }, // spend $100
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**Market Sell** (sell X units of base asset):
|
|
121
|
+
```typescript
|
|
122
|
+
const order = await client.submitOrder({
|
|
123
|
+
client_order_id: crypto.randomUUID(),
|
|
124
|
+
product_id: 'BTC-USD',
|
|
125
|
+
side: 'SELL',
|
|
126
|
+
order_configuration: {
|
|
127
|
+
market_market_ioc: { base_size: '0.001' }, // sell 0.001 BTC
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Limit Buy** (Good Till Cancel):
|
|
133
|
+
```typescript
|
|
134
|
+
const order = await client.submitOrder({
|
|
135
|
+
client_order_id: crypto.randomUUID(),
|
|
136
|
+
product_id: 'BTC-USD',
|
|
137
|
+
side: 'BUY',
|
|
138
|
+
order_configuration: {
|
|
139
|
+
limit_limit_gtc: {
|
|
140
|
+
base_size: '0.001',
|
|
141
|
+
limit_price: '95000.00',
|
|
142
|
+
post_only: false,
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Step 6: Verify Order
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
// Check response immediately
|
|
152
|
+
if (order.success) {
|
|
153
|
+
const orderId = order.success_response.order_id;
|
|
154
|
+
// Get fill details
|
|
155
|
+
const status = await client.getOrder({ order_id: orderId });
|
|
156
|
+
console.log(`Status: ${status.status}, Filled: ${status.filled_size} @ ${status.average_filled_price}`);
|
|
157
|
+
} else {
|
|
158
|
+
console.error(`Order failed: ${order.error_response.message}`);
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**IMPORTANT:** Coinbase returns HTTP 200 even on order failure. Always check `order.success === true`.
|
|
163
|
+
|
|
164
|
+
### Step 7: Update LEARNING.md
|
|
165
|
+
|
|
166
|
+
After every trade, record: asset, side, type, size, fill price, fees, outcome, and any API quirks encountered.
|
|
167
|
+
|
|
168
|
+
## Order Management
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
// List open orders
|
|
172
|
+
const orders = await client.getOrders({ order_status: ['OPEN', 'PENDING'] });
|
|
173
|
+
|
|
174
|
+
// Cancel specific orders
|
|
175
|
+
const cancel = await client.cancelOrders({ order_ids: ['order-id-here'] });
|
|
176
|
+
|
|
177
|
+
// Get fills (trade executions)
|
|
178
|
+
const fills = await client.getFills({ order_id: 'order-id-here' });
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Portfolio & Fees
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
// Portfolio breakdown
|
|
185
|
+
const portfolios = await client.getPortfolios({});
|
|
186
|
+
const breakdown = await client.getPortfolioBreakdown({ portfolio_id: portfolios.portfolios[0].uuid });
|
|
187
|
+
|
|
188
|
+
// Fee tier info
|
|
189
|
+
const fees = await client.getTransactionSummary({});
|
|
190
|
+
// Shows: fee_tier, total_volume, maker_fee_rate, taker_fee_rate
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Critical Rules
|
|
194
|
+
|
|
195
|
+
1. **ALWAYS preview orders before executing** — know the fees and slippage
|
|
196
|
+
2. **All values are STRINGS** — `"100.00"` not `100`. The API rejects numbers.
|
|
197
|
+
3. **client_order_id must be unique** — always use `crypto.randomUUID()`
|
|
198
|
+
4. **Check `order.success`** — HTTP 200 doesn't mean order succeeded
|
|
199
|
+
5. **Product ID format** — always `BASE-QUOTE` e.g. `BTC-USD`, `ETH-USD`, `SOL-USD`
|
|
200
|
+
6. **Minimum order sizes vary** — check product details before ordering
|
|
201
|
+
7. **Rate limits** — ~10 requests/second for private endpoints
|
|
202
|
+
8. **Never place orders in a loop without delays** — respect rate limits
|
|
203
|
+
9. **Log everything in LEARNING.md** — every trade, every error, every quirk
|
|
204
|
+
|
|
205
|
+
## Reference Files
|
|
206
|
+
|
|
207
|
+
- [references/order-types.md](references/order-types.md) — All order configurations with examples
|
|
208
|
+
- [references/api-reference.md](references/api-reference.md) — Complete API endpoint list
|
|
209
|
+
- [references/products.md](references/products.md) — Common trading pairs and their details
|
|
210
|
+
|
|
211
|
+
## Self-Evolution
|
|
212
|
+
|
|
213
|
+
You can modify any file in this skill:
|
|
214
|
+
- Found an API quirk? Update LEARNING.md and references
|
|
215
|
+
- Built a reusable script? Save it in `scripts/`
|
|
216
|
+
- Discovered a better workflow? Update this SKILL.md
|
|
217
|
+
- New order type pattern? Add to `references/order-types.md`
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# Coinbase Advanced Trade API Reference
|
|
2
|
+
|
|
3
|
+
> Agent-editable. Add notes and quirks as you discover them.
|
|
4
|
+
> Last updated: Initial version
|
|
5
|
+
|
|
6
|
+
## Base URL
|
|
7
|
+
|
|
8
|
+
`https://api.coinbase.com/api/v3/brokerage/`
|
|
9
|
+
|
|
10
|
+
## SDK Methods (coinbase-api package)
|
|
11
|
+
|
|
12
|
+
### Accounts & Balances
|
|
13
|
+
|
|
14
|
+
| Method | Description |
|
|
15
|
+
|--------|-------------|
|
|
16
|
+
| `client.getAccounts()` | List all accounts with balances |
|
|
17
|
+
| `client.getAccount({ account_id })` | Get specific account |
|
|
18
|
+
|
|
19
|
+
### Market Data
|
|
20
|
+
|
|
21
|
+
| Method | Description |
|
|
22
|
+
|--------|-------------|
|
|
23
|
+
| `client.getProducts({})` | List all trading pairs |
|
|
24
|
+
| `client.getProduct({ product_id })` | Get product details + current price |
|
|
25
|
+
| `client.getProductCandles({ product_id, start, end, granularity })` | OHLCV candle data |
|
|
26
|
+
| `client.getProductBook({ product_id, limit })` | Order book depth |
|
|
27
|
+
| `client.getBestBidAsk({ product_ids: [...] })` | Best bid/ask spread |
|
|
28
|
+
| `client.getMarketTrades({ product_id, limit })` | Recent market trades |
|
|
29
|
+
|
|
30
|
+
### Orders
|
|
31
|
+
|
|
32
|
+
| Method | Description |
|
|
33
|
+
|--------|-------------|
|
|
34
|
+
| `client.submitOrder({ ... })` | Place an order |
|
|
35
|
+
| `client.previewOrder({ ... })` | Preview order (estimate fees/slippage) |
|
|
36
|
+
| `client.getOrder({ order_id })` | Get order details |
|
|
37
|
+
| `client.getOrders({ order_status, product_id, ... })` | List orders with filters |
|
|
38
|
+
| `client.cancelOrders({ order_ids: [...] })` | Cancel one or more orders |
|
|
39
|
+
| `client.getFills({ order_id, product_id, ... })` | Get trade fills |
|
|
40
|
+
|
|
41
|
+
### Portfolios
|
|
42
|
+
|
|
43
|
+
| Method | Description |
|
|
44
|
+
|--------|-------------|
|
|
45
|
+
| `client.getPortfolios({})` | List portfolios |
|
|
46
|
+
| `client.getPortfolioBreakdown({ portfolio_id })` | Detailed breakdown with positions |
|
|
47
|
+
|
|
48
|
+
### Fees
|
|
49
|
+
|
|
50
|
+
| Method | Description |
|
|
51
|
+
|--------|-------------|
|
|
52
|
+
| `client.getTransactionSummary({})` | Fee tier, volume, maker/taker rates |
|
|
53
|
+
|
|
54
|
+
## Candle Granularity Options
|
|
55
|
+
|
|
56
|
+
| Value | Period |
|
|
57
|
+
|-------|--------|
|
|
58
|
+
| `ONE_MINUTE` | 1 min |
|
|
59
|
+
| `FIVE_MINUTE` | 5 min |
|
|
60
|
+
| `FIFTEEN_MINUTE` | 15 min |
|
|
61
|
+
| `THIRTY_MINUTE` | 30 min |
|
|
62
|
+
| `ONE_HOUR` | 1 hr |
|
|
63
|
+
| `TWO_HOUR` | 2 hr |
|
|
64
|
+
| `SIX_HOUR` | 6 hr |
|
|
65
|
+
| `ONE_DAY` | 1 day |
|
|
66
|
+
|
|
67
|
+
## Candle Timestamps
|
|
68
|
+
|
|
69
|
+
- `start` and `end` are **Unix timestamps in seconds** (as strings)
|
|
70
|
+
- Example: last 24 hours
|
|
71
|
+
```typescript
|
|
72
|
+
start: String(Math.floor(Date.now() / 1000) - 86400),
|
|
73
|
+
end: String(Math.floor(Date.now() / 1000)),
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Rate Limits
|
|
77
|
+
|
|
78
|
+
| Type | Limit |
|
|
79
|
+
|------|-------|
|
|
80
|
+
| Private endpoints | ~10 requests/second |
|
|
81
|
+
| Private endpoints | ~5,000 requests/hour |
|
|
82
|
+
| Public endpoints | ~10,000 requests/hour |
|
|
83
|
+
|
|
84
|
+
Public endpoints have 1-second cache. Use WebSocket for real-time data.
|
|
85
|
+
|
|
86
|
+
## Error Handling
|
|
87
|
+
|
|
88
|
+
The API returns HTTP 200 for most responses, including failures. Always check:
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
if (order.success) {
|
|
92
|
+
// order.success_response.order_id
|
|
93
|
+
} else {
|
|
94
|
+
// order.error_response.error, order.error_response.message
|
|
95
|
+
// Common: INSUFFICIENT_FUND, INVALID_LIMIT_PRICE_POST_ONLY, UNKNOWN_FAILURE_REASON
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Common Error Codes
|
|
100
|
+
|
|
101
|
+
| Error | Meaning | Fix |
|
|
102
|
+
|-------|---------|-----|
|
|
103
|
+
| `INSUFFICIENT_FUND` | Not enough balance | Check available balance first |
|
|
104
|
+
| `INVALID_LIMIT_PRICE_POST_ONLY` | Post-only order would immediately fill | Adjust price or set `post_only: false` |
|
|
105
|
+
| `UNKNOWN_FAILURE_REASON` | Generic failure | Check order params, product status |
|
|
106
|
+
| `UNSUPPORTED_ORDER_CONFIGURATION` | Invalid order config | Check order type and required fields |
|
|
107
|
+
| `INVALID_PRODUCT_ID` | Product doesn't exist | Verify product_id with `getProducts()` |
|
|
108
|
+
|
|
109
|
+
## WebSocket Channels (Real-Time)
|
|
110
|
+
|
|
111
|
+
| Channel | Auth | Description |
|
|
112
|
+
|---------|------|-------------|
|
|
113
|
+
| `ticker` | Public | Real-time price per trade |
|
|
114
|
+
| `ticker_batch` | Public | Batched price updates |
|
|
115
|
+
| `level2` | Public | Order book updates |
|
|
116
|
+
| `market_trades` | Public | Trade executions |
|
|
117
|
+
| `candles` | Public | OHLCV updates |
|
|
118
|
+
| `status` | Public | Product status changes |
|
|
119
|
+
| `user` | Private | Your order fills and updates |
|
|
120
|
+
| `heartbeats` | Public | Connection keepalive |
|
|
121
|
+
|
|
122
|
+
WebSocket endpoints:
|
|
123
|
+
- Market data: `wss://advanced-trade-ws.coinbase.com`
|
|
124
|
+
- User data: `wss://advanced-trade-ws-user.coinbase.com`
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Coinbase Order Types — Complete Reference
|
|
2
|
+
|
|
3
|
+
> Agent-editable. Update with patterns and quirks discovered from real trading.
|
|
4
|
+
> Last updated: Initial version
|
|
5
|
+
|
|
6
|
+
## Order Configuration Keys
|
|
7
|
+
|
|
8
|
+
Every order uses `order_configuration` with exactly ONE of these keys:
|
|
9
|
+
|
|
10
|
+
### Market Orders (Immediate Execution)
|
|
11
|
+
|
|
12
|
+
**`market_market_ioc`** — Market Immediate-or-Cancel (most common)
|
|
13
|
+
```typescript
|
|
14
|
+
// Buy by dollar amount (quote currency)
|
|
15
|
+
order_configuration: {
|
|
16
|
+
market_market_ioc: { quote_size: '100.00' } // spend $100
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Sell by quantity (base currency)
|
|
20
|
+
order_configuration: {
|
|
21
|
+
market_market_ioc: { base_size: '0.5' } // sell 0.5 ETH
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
- Use `quote_size` for BUY (how much USD to spend)
|
|
25
|
+
- Use `base_size` for SELL (how many units to sell)
|
|
26
|
+
- Can use `base_size` for BUY too (buy exact amount of asset)
|
|
27
|
+
|
|
28
|
+
### Limit Orders
|
|
29
|
+
|
|
30
|
+
**`limit_limit_gtc`** — Good Till Cancelled
|
|
31
|
+
```typescript
|
|
32
|
+
order_configuration: {
|
|
33
|
+
limit_limit_gtc: {
|
|
34
|
+
base_size: '0.001',
|
|
35
|
+
limit_price: '95000.00',
|
|
36
|
+
post_only: false, // true = maker only (lower fees)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**`limit_limit_gtd`** — Good Till Date (expires)
|
|
42
|
+
```typescript
|
|
43
|
+
order_configuration: {
|
|
44
|
+
limit_limit_gtd: {
|
|
45
|
+
base_size: '0.001',
|
|
46
|
+
limit_price: '95000.00',
|
|
47
|
+
end_time: '2026-03-01T00:00:00Z', // RFC3339
|
|
48
|
+
post_only: false,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**`limit_limit_fok`** — Fill or Kill (all or nothing)
|
|
54
|
+
```typescript
|
|
55
|
+
order_configuration: {
|
|
56
|
+
limit_limit_fok: {
|
|
57
|
+
base_size: '0.001',
|
|
58
|
+
limit_price: '95000.00',
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Stop-Limit Orders
|
|
64
|
+
|
|
65
|
+
**`stop_limit_stop_limit_gtc`** — Stop-Limit GTC
|
|
66
|
+
```typescript
|
|
67
|
+
// Stop-loss sell: triggers when price drops to stop_price
|
|
68
|
+
order_configuration: {
|
|
69
|
+
stop_limit_stop_limit_gtc: {
|
|
70
|
+
base_size: '0.001',
|
|
71
|
+
limit_price: '93000.00', // limit order price after trigger
|
|
72
|
+
stop_price: '94000.00', // trigger price
|
|
73
|
+
stop_direction: 'STOP_DIRECTION_STOP_DOWN', // triggers when price goes DOWN
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Stop-buy: triggers when price rises to stop_price
|
|
78
|
+
order_configuration: {
|
|
79
|
+
stop_limit_stop_limit_gtc: {
|
|
80
|
+
base_size: '0.001',
|
|
81
|
+
limit_price: '101000.00',
|
|
82
|
+
stop_price: '100000.00',
|
|
83
|
+
stop_direction: 'STOP_DIRECTION_STOP_UP',
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**`stop_limit_stop_limit_gtd`** — Stop-Limit with expiry (same fields + `end_time`)
|
|
89
|
+
|
|
90
|
+
### Bracket Orders (Entry + Take-Profit + Stop-Loss)
|
|
91
|
+
|
|
92
|
+
**`trigger_bracket_gtc`** — Bracket GTC
|
|
93
|
+
```typescript
|
|
94
|
+
order_configuration: {
|
|
95
|
+
trigger_bracket_gtc: {
|
|
96
|
+
base_size: '0.001',
|
|
97
|
+
limit_price: '105000.00', // take-profit price
|
|
98
|
+
stop_trigger_price: '93000.00', // stop-loss trigger
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**`trigger_bracket_gtd`** — Bracket with expiry (same fields + `end_time`)
|
|
104
|
+
|
|
105
|
+
### Smart Order Router
|
|
106
|
+
|
|
107
|
+
**`sor_limit_ioc`** — SOR Limit IOC (routes across venues for best price)
|
|
108
|
+
```typescript
|
|
109
|
+
order_configuration: {
|
|
110
|
+
sor_limit_ioc: {
|
|
111
|
+
base_size: '0.001',
|
|
112
|
+
limit_price: '100000.00',
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Stop Direction Values
|
|
118
|
+
|
|
119
|
+
| Value | Meaning | Use Case |
|
|
120
|
+
|-------|---------|----------|
|
|
121
|
+
| `STOP_DIRECTION_STOP_DOWN` | Trigger when price drops below stop | Stop-loss for long positions |
|
|
122
|
+
| `STOP_DIRECTION_STOP_UP` | Trigger when price rises above stop | Stop-loss for shorts, breakout buys |
|
|
123
|
+
|
|
124
|
+
## Order Sides
|
|
125
|
+
|
|
126
|
+
| Side | Meaning |
|
|
127
|
+
|------|---------|
|
|
128
|
+
| `BUY` | Buy base currency, spend quote currency |
|
|
129
|
+
| `SELL` | Sell base currency, receive quote currency |
|
|
130
|
+
|
|
131
|
+
## Order Statuses
|
|
132
|
+
|
|
133
|
+
| Status | Meaning |
|
|
134
|
+
|--------|---------|
|
|
135
|
+
| `PENDING` | Order received, not yet on book |
|
|
136
|
+
| `OPEN` | Active on order book |
|
|
137
|
+
| `FILLED` | Completely filled |
|
|
138
|
+
| `CANCELLED` | Cancelled by user or system |
|
|
139
|
+
| `EXPIRED` | GTD order expired |
|
|
140
|
+
| `FAILED` | Order rejected |
|
|
141
|
+
| `UNKNOWN_ORDER_STATUS` | Unknown |
|
|
142
|
+
|
|
143
|
+
## Key Gotchas
|
|
144
|
+
|
|
145
|
+
1. **All numeric values must be strings**: `"100.00"` not `100`
|
|
146
|
+
2. **Market buys use `quote_size`** (dollar amount), **market sells use `base_size`** (quantity)
|
|
147
|
+
3. **HTTP 200 doesn't mean success**: Always check `response.success === true`
|
|
148
|
+
4. **Duplicate `client_order_id`**: Returns existing order, doesn't create new one
|
|
149
|
+
5. **`post_only: true`**: Ensures you're a maker (lower fees) but order may be rejected if it would immediately fill
|
|
150
|
+
6. **Minimum order sizes**: Vary by product. Check `base_min_size` in product details.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Coinbase Trading Products
|
|
2
|
+
|
|
3
|
+
> Agent-editable. Add notes about products as you trade them.
|
|
4
|
+
> Last updated: Initial version
|
|
5
|
+
|
|
6
|
+
## Product ID Format
|
|
7
|
+
|
|
8
|
+
Always `{BASE}-{QUOTE}`, e.g. `BTC-USD`, `ETH-USD`
|
|
9
|
+
|
|
10
|
+
## Common Trading Pairs
|
|
11
|
+
|
|
12
|
+
### Major Crypto (High Liquidity)
|
|
13
|
+
|
|
14
|
+
| Product ID | Base | Quote | Notes |
|
|
15
|
+
|-----------|------|-------|-------|
|
|
16
|
+
| `BTC-USD` | Bitcoin | USD | Most liquid, tightest spreads |
|
|
17
|
+
| `ETH-USD` | Ethereum | USD | Second most liquid |
|
|
18
|
+
| `SOL-USD` | Solana | USD | High volatility |
|
|
19
|
+
| `DOGE-USD` | Dogecoin | USD | Meme coin, volatile |
|
|
20
|
+
| `XRP-USD` | Ripple | USD | |
|
|
21
|
+
| `ADA-USD` | Cardano | USD | |
|
|
22
|
+
| `AVAX-USD` | Avalanche | USD | |
|
|
23
|
+
| `LINK-USD` | Chainlink | USD | |
|
|
24
|
+
| `DOT-USD` | Polkadot | USD | |
|
|
25
|
+
| `MATIC-USD` | Polygon | USD | |
|
|
26
|
+
| `UNI-USD` | Uniswap | USD | |
|
|
27
|
+
| `LTC-USD` | Litecoin | USD | |
|
|
28
|
+
|
|
29
|
+
### Stablecoins
|
|
30
|
+
|
|
31
|
+
| Product ID | Base | Quote | Notes |
|
|
32
|
+
|-----------|------|-------|-------|
|
|
33
|
+
| `USDT-USD` | Tether | USD | |
|
|
34
|
+
| `BTC-USDT` | Bitcoin | Tether | |
|
|
35
|
+
| `ETH-USDT` | Ethereum | Tether | |
|
|
36
|
+
|
|
37
|
+
### Crypto-to-Crypto
|
|
38
|
+
|
|
39
|
+
| Product ID | Base | Quote | Notes |
|
|
40
|
+
|-----------|------|-------|-------|
|
|
41
|
+
| `ETH-BTC` | Ethereum | Bitcoin | ETH/BTC ratio trading |
|
|
42
|
+
| `SOL-BTC` | Solana | Bitcoin | |
|
|
43
|
+
|
|
44
|
+
## Discovering Products
|
|
45
|
+
|
|
46
|
+
Always verify product availability before trading:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
// List all products
|
|
50
|
+
const products = await client.getProducts({});
|
|
51
|
+
|
|
52
|
+
// Filter for USD pairs
|
|
53
|
+
const usdPairs = products.products.filter(p => p.quote_currency_id === 'USD');
|
|
54
|
+
|
|
55
|
+
// Get specific product details
|
|
56
|
+
const btc = await client.getProduct({ product_id: 'BTC-USD' });
|
|
57
|
+
// Returns: price, volume_24h, price_percentage_change_24h,
|
|
58
|
+
// base_min_size, base_max_size, quote_min_size, quote_increment, etc.
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Key Product Fields
|
|
62
|
+
|
|
63
|
+
| Field | Description | Important For |
|
|
64
|
+
|-------|-------------|---------------|
|
|
65
|
+
| `price` | Current price | All orders |
|
|
66
|
+
| `base_min_size` | Minimum base order size | Validating order size |
|
|
67
|
+
| `base_max_size` | Maximum base order size | Validating order size |
|
|
68
|
+
| `quote_min_size` | Minimum quote order size | Market buy minimum |
|
|
69
|
+
| `quote_increment` | Price precision | Formatting limit prices |
|
|
70
|
+
| `base_increment` | Size precision | Formatting order sizes |
|
|
71
|
+
| `status` | Product trading status | Check before ordering |
|
|
72
|
+
| `trading_disabled` | Whether trading is halted | Check before ordering |
|
|
73
|
+
| `volume_24h` | 24-hour trading volume | Liquidity assessment |
|
|
74
|
+
|
|
75
|
+
## Pre-Trade Checklist
|
|
76
|
+
|
|
77
|
+
Before placing any order on a product:
|
|
78
|
+
|
|
79
|
+
1. **Verify product exists**: `getProduct({ product_id })`
|
|
80
|
+
2. **Check `trading_disabled !== true`**
|
|
81
|
+
3. **Check `status === 'online'`**
|
|
82
|
+
4. **Verify order size >= `base_min_size`** (for base_size orders)
|
|
83
|
+
5. **Verify order size >= `quote_min_size`** (for quote_size orders)
|
|
84
|
+
6. **Round to correct precision** using `base_increment` / `quote_increment`
|
|
85
|
+
|
|
86
|
+
## Product Notes from Trading
|
|
87
|
+
|
|
88
|
+
*(Add observations as you trade different pairs)*
|
|
89
|
+
<!--
|
|
90
|
+
- [DATE] PRODUCT: observation about spreads, liquidity, or behavior
|
|
91
|
+
Example:
|
|
92
|
+
- [2026-02-14] BTC-USD: Spreads widen significantly during weekends. Avoid large market orders Sat/Sun.
|
|
93
|
+
-->
|