POST
/api/tradesSubmit a trade after executing on Polymarket.
Requires X-API-Key header. The trade is automatically linked to your account.
Request Body
| Field | Type | Description |
|---|---|---|
token_id* | string | CLOB token ID for the outcome (from Gamma Markets API) |
market_id* | string | Polymarket condition ID |
outcome* | string | "YES" or "NO" |
position_type* | "buy" | "sell" | Trade direction |
amount* | number | Number of shares (positive) |
price* | number | Price per share (0-1) |
timestamp* | string | ISO 8601 datetime |
market_question | string | Market title (optional) |
* Required
Example
bash
curl -X POST https://api.bag.trading/api/trades \
-H "Content-Type: application/json" \
-H "X-API-Key: bag_k_abc123..." \
-d '{
"token_id": "71321045863083957739706457695227500962945469455128092834349296933983316442994",
"market_id": "0x1234567890abcdef...",
"outcome": "YES",
"position_type": "buy",
"amount": 150.5,
"price": 0.72,
"timestamp": "2024-01-15T14:30:00Z"
}'Response
201 Created
json
{
"success": true,
"trade_id": "660e8400-e29b-41d4-a716-446655440001",
"trade": {
"id": "660e8400-e29b-41d4-a716-446655440001",
"token_id": "71321045863083957739706457695227500962945469455128092834349296933983316442994",
"market_id": "0x1234567890abcdef...",
"outcome": "YES",
"position_type": "buy",
"amount": 150.5,
"price": 0.72,
"timestamp": "2024-01-15T14:30:00Z",
"reported_at": "2024-01-15T14:30:05Z"
}
}Errors
401 Unauthorized
json
{ "error": "Missing API key. Include X-API-Key header." }400 Bad Request
json
{
"error": "Invalid trade data",
"details": [{ "field": "price", "message": "Price must be between 0 and 1" }]
}