# Trading

## Trading and wallet operations

> Handles all trading actions (swap, balance inquiries, withdrawals, key export). The specific operation is selected via the \`action\` query parameter. All actions require authentication.<br>

```json
{"openapi":"3.0.3","info":{"title":"Indexify API","version":"0.1.12-beta"},"servers":[{"url":"https://api.indexify.finance","description":"Production"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-KEY","description":"API key with the `ix_` prefix. You can generate an API Key by navigating to Settings -> API Key in the web app. Pass it in the `X-API-KEY` header on every request."}},"schemas":{"Error":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}}}},"paths":{"/api/txn.php":{"post":{"tags":["Trading"],"summary":"Trading and wallet operations","operationId":"tradingOperations","description":"Handles all trading actions (swap, balance inquiries, withdrawals, key export). The specific operation is selected via the `action` query parameter. All actions require authentication.\n","parameters":[{"name":"action","in":"query","required":true,"schema":{"type":"string","enum":["swap","rebalance","balance","usdc_balance","total_balance","address","withdraw_usdc","export_key"]},"description":"The trading action to perform."}],"requestBody":{"required":false,"content":{"application/json":{"schema":{"oneOf":[{"title":"SwapRequest","type":"object","required":["stack_id","amount","cue"],"properties":{"stack_id":{"type":"integer","description":"ID of the stack to trade."},"amount":{"type":"number","description":"For buys (cue=fromUSDC): USDC amount to spend. For sells (cue=toUSDC): percentage of holdings to sell (1-100).\n"},"cue":{"type":"string","enum":["fromUSDC","toUSDC"],"description":"Direction of the swap."}}},{"title":"RebalanceRequest","type":"object","required":["stack_id"],"properties":{"stack_id":{"type":"integer","description":"ID of the stack to rebalance holdings for."}}},{"title":"WithdrawUsdcRequest","type":"object","required":["address","amount","verification_code"],"properties":{"address":{"type":"string","description":"Destination wallet address."},"amount":{"type":"number","description":"USDC amount to withdraw."},"verification_code":{"type":"string","description":"SMS verification code."}}},{"title":"ExportKeyRequest","type":"object","required":["verification_code","has_acknowledged_risk"],"properties":{"verification_code":{"type":"string","description":"SMS verification code."},"has_acknowledged_risk":{"type":"boolean","enum":[true],"description":"Must be true to confirm risk acknowledgment."}}}]}}}},"responses":{"200":{"description":"Successful response. Shape depends on action.","content":{"application/json":{"schema":{"oneOf":[{"title":"SwapResponse","type":"object","properties":{"order_id":{"type":"string","description":"Unique identifier for the created order."}}},{"title":"RebalanceResponse","type":"object","properties":{"rebalance_id":{"type":"string","description":"Unique identifier for the rebalance operation."},"sell_order_id":{"type":"string","description":"Order ID for the sell phase."},"buy_order_id":{"type":"string","description":"Order ID for buy-only rebalance (when no sells needed)."},"status":{"type":"string","enum":["SELLING","BUYING"],"description":"Current rebalance phase."},"sells_count":{"type":"integer","description":"Number of sell swaps initiated."},"buys_count":{"type":"integer","description":"Number of buy swaps planned."},"total_portfolio_value_usdc":{"type":"number","description":"Total portfolio value in USDC at rebalance time."},"allocation_version":{"type":"integer","description":"Target allocation version number."}}},{"title":"BalanceResponse","type":"array","items":{"type":"object","properties":{"mint":{"type":"string","description":"Token mint address."},"amount":{"type":"number","description":"Token balance as a number."},"amountString":{"type":"string","description":"Token balance as a string."},"decimals":{"type":"integer","description":"Token decimal places."}}}},{"title":"UsdcBalanceResponse","type":"object","properties":{"balance":{"type":"number","description":"USDC balance."}}},{"title":"TotalBalanceResponse","type":"object","properties":{"total_balance":{"type":"string","description":"Total portfolio balance in USDC."}}},{"title":"AddressResponse","type":"object","properties":{"pubkey":{"type":"string","description":"Wallet public key."}}},{"title":"WithdrawUsdcResponse","type":"object","description":"Transaction details for the withdrawal."},{"title":"ExportKeyResponse","type":"object","properties":{"byte_array":{"type":"array","items":{"type":"integer"},"description":"Private key as byte array."},"base_58":{"type":"string","description":"Private key in Base58 encoding."}}}]}}}},"400":{"description":"Bad request (missing fields, invalid parameters, insufficient balance, etc.).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Stack not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"409":{"description":"Conflict (rebalance already in progress).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal server error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## Order management

> Provides order details, partial order handling, retry, sell-all, and retry chain lookups. All actions require authentication and an \`order\_id\` in the request body.<br>

```json
{"openapi":"3.0.3","info":{"title":"Indexify API","version":"0.1.12-beta"},"servers":[{"url":"https://api.indexify.finance","description":"Production"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-KEY","description":"API key with the `ix_` prefix. You can generate an API Key by navigating to Settings -> API Key in the web app. Pass it in the `X-API-KEY` header on every request."}},"schemas":{"Error":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}}}},"paths":{"/api/orders.php":{"post":{"tags":["Trading"],"summary":"Order management","description":"Provides order details, partial order handling, retry, sell-all, and retry chain lookups. All actions require authentication and an `order_id` in the request body.\n","operationId":"manageOrder","parameters":[{"name":"action","in":"query","required":false,"schema":{"type":"string","enum":["details","status","partial_details","acknowledge","retry","sell_all","retry_chain"],"default":"details"},"description":"The order action to perform. Defaults to `details`."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"oneOf":[{"title":"OrderIdRequest","type":"object","required":["order_id"],"properties":{"order_id":{"type":"string","description":"Unique order identifier."}}},{"title":"RetryRequest","type":"object","required":["order_id"],"properties":{"order_id":{"type":"string","description":"Unique order identifier."},"slippage":{"type":"integer","minimum":1,"maximum":51,"description":"Custom slippage tolerance for the retry (optional)."}}}]}}}},"responses":{"200":{"description":"Successful response. Shape depends on action.","content":{"application/json":{"schema":{"oneOf":[{"title":"OrderDetailsResponse","type":"object","properties":{"order":{"type":"object","properties":{"order_id":{"type":"string"},"status":{"type":"string","enum":["PENDING","SUCCESS","FAILED","PARTIAL"]},"type":{"type":"string","enum":["fromUSDC","toUSDC"]},"created_at":{"type":"string"},"partial_completion_action":{"type":"string","nullable":true}}},"transactions":{"type":"array","items":{"type":"object","properties":{"order_id":{"type":"string"},"success":{"type":"boolean"},"txn_hash":{"type":"string","nullable":true}}}},"transaction_count":{"type":"integer"}}},{"title":"PartialDetailsResponse","type":"object","properties":{"order_id":{"type":"string"},"order_info":{"type":"object","description":"Detailed order metadata."},"stack_info":{"type":"object","properties":{"id":{"type":"integer"},"stack_name":{"type":"string"},"slug":{"type":"string"}}},"successful_tokens":{"type":"array","items":{"type":"object"}},"failed_tokens":{"type":"array","items":{"type":"object"}},"summary":{"type":"object","properties":{"total_tokens_in_stack":{"type":"integer"},"successful_token_count":{"type":"integer"},"failed_token_count":{"type":"integer"},"success_rate":{"type":"number"}}},"available_actions":{"type":"object","properties":{"acknowledge":{"type":"boolean"},"retry":{"type":"boolean"},"sell_all":{"type":"boolean"}}}}},{"title":"AcknowledgeResponse","type":"object","properties":{"success":{"type":"boolean"},"message":{"type":"string"},"order_id":{"type":"string"}}},{"title":"RetryResponse","type":"object","properties":{"order_id":{"type":"string"},"stack_id":{"type":"integer"},"parent_order_id":{"type":"string"},"retry_attempt":{"type":"integer"},"failed_tokens_attempted":{"type":"integer"},"status":{"type":"string"}}},{"title":"SellAllResponse","type":"object","properties":{"order_id":{"type":"string"},"stack_id":{"type":"integer"}}},{"title":"RetryChainResponse","type":"object","properties":{"order_id":{"type":"string"},"retry_chain":{"type":"array","items":{"type":"object","properties":{"order_id":{"type":"string"},"parent_order_id":{"type":"string","nullable":true},"retry_attempt":{"type":"integer"},"status":{"type":"string","enum":["PENDING","SUCCESS","FAILED","PARTIAL"]},"type":{"type":"string","enum":["fromUSDC","toUSDC"]},"created_at":{"type":"string"},"partial_completion_action":{"type":"string","nullable":true}}}},"total_attempts":{"type":"integer"}}}]}}}},"400":{"description":"Bad request (missing order_id, invalid slippage, invalid action, etc.).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Order not found or not owned by the authenticated user.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal server error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## List authenticated user's orders

> Returns a paginated list of all orders for the authenticated user.

```json
{"openapi":"3.0.3","info":{"title":"Indexify API","version":"0.1.12-beta"},"servers":[{"url":"https://api.indexify.finance","description":"Production"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-KEY","description":"API key with the `ix_` prefix. You can generate an API Key by navigating to Settings -> API Key in the web app. Pass it in the `X-API-KEY` header on every request."}},"schemas":{"Error":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}}}},"paths":{"/api/user_orders.php":{"post":{"tags":["Trading"],"summary":"List authenticated user's orders","description":"Returns a paginated list of all orders for the authenticated user.","operationId":"listUserOrders","parameters":[{"name":"offset","in":"query","required":false,"schema":{"type":"integer","default":0,"minimum":0},"description":"Pagination offset."},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","default":100,"minimum":1,"maximum":100},"description":"Number of orders to return."}],"responses":{"200":{"description":"Paginated list of user orders.","content":{"application/json":{"schema":{"type":"object","properties":{"orders":{"type":"array","items":{"type":"object","properties":{"order_id":{"type":"string"},"stack_id":{"type":"integer"},"type":{"type":"string","enum":["fromUSDC","toUSDC"]},"status":{"type":"string","enum":["PENDING","SUCCESS","FAILED","PARTIAL"]},"created_at":{"type":"string"},"parent_order_id":{"type":"string","nullable":true},"retry_attempt":{"type":"integer","nullable":true},"partial_completion_action":{"type":"string","nullable":true},"stack_name":{"type":"string","nullable":true},"stack_symbol":{"type":"string","nullable":true}}}},"pagination":{"type":"object","properties":{"offset":{"type":"integer"},"limit":{"type":"integer"},"total_count":{"type":"integer"},"has_more":{"type":"boolean"},"has_previous":{"type":"boolean"},"page":{"type":"integer"},"per_page":{"type":"integer"},"total_pages":{"type":"integer"}}}}}}}},"400":{"description":"Invalid pagination parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal server error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## List outstanding partial orders for a stack

> Returns a paginated list of the authenticated user's outstanding partial orders (status=PARTIAL, partial\_completion\_action=pending) for a given stack.<br>

```json
{"openapi":"3.0.3","info":{"title":"Indexify API","version":"0.1.12-beta"},"servers":[{"url":"https://api.indexify.finance","description":"Production"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-KEY","description":"API key with the `ix_` prefix. You can generate an API Key by navigating to Settings -> API Key in the web app. Pass it in the `X-API-KEY` header on every request."}},"schemas":{"Error":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}}}},"paths":{"/api/stack_partial_orders.php":{"post":{"tags":["Trading"],"summary":"List outstanding partial orders for a stack","description":"Returns a paginated list of the authenticated user's outstanding partial orders (status=PARTIAL, partial_completion_action=pending) for a given stack.\n","operationId":"listStackPartialOrders","parameters":[{"name":"stack_id","in":"query","required":true,"schema":{"type":"integer"},"description":"ID of the stack to query."},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","default":0,"minimum":0},"description":"Pagination offset."},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","default":100,"minimum":1,"maximum":100},"description":"Number of orders to return."}],"responses":{"200":{"description":"Paginated list of outstanding partial orders.","content":{"application/json":{"schema":{"type":"object","properties":{"stack":{"type":"object","properties":{"id":{"type":"integer"},"stack_name":{"type":"string"},"stack_token_name":{"type":"string"}}},"outstanding_partial_orders":{"type":"array","items":{"type":"object","properties":{"order_id":{"type":"string"},"user_id":{"type":"integer"},"stack_id":{"type":"integer"},"type":{"type":"string"},"status":{"type":"string"},"usdc_amount":{"type":"number"},"creator_fee":{"type":"number"},"platform_fee":{"type":"number"},"expected_amount":{"type":"number","nullable":true},"created_at":{"type":"string"},"parent_order_id":{"type":"string","nullable":true},"retry_attempt":{"type":"integer","nullable":true},"partial_completion_action":{"type":"string"},"username":{"type":"string","nullable":true}}}},"pagination":{"type":"object","properties":{"offset":{"type":"integer"},"limit":{"type":"integer"},"total_count":{"type":"integer"},"has_more":{"type":"boolean"},"has_previous":{"type":"boolean"},"page":{"type":"integer"},"per_page":{"type":"integer"},"total_pages":{"type":"integer"}}}}}}}},"400":{"description":"Missing or invalid stack_id, invalid pagination parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Stack not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal server error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## Transaction history

> Retrieve the authenticated user's transaction history, a single transaction detail, or a transaction summary. The specific operation is selected via the \`action\` query parameter.<br>

```json
{"openapi":"3.0.3","info":{"title":"Indexify API","version":"0.1.12-beta"},"servers":[{"url":"https://api.indexify.finance","description":"Production"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-KEY","description":"API key with the `ix_` prefix. You can generate an API Key by navigating to Settings -> API Key in the web app. Pass it in the `X-API-KEY` header on every request."}},"schemas":{"Error":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}}}},"paths":{"/api/transaction_history.php":{"get":{"tags":["Trading"],"summary":"Transaction history","description":"Retrieve the authenticated user's transaction history, a single transaction detail, or a transaction summary. The specific operation is selected via the `action` query parameter.\n","operationId":"getTransactionHistory","parameters":[{"name":"action","in":"query","required":false,"schema":{"type":"string","enum":["list","detail","summary"],"default":"list"},"description":"The history action to perform."},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","default":0,"minimum":0},"description":"Pagination offset (action=list only)."},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","default":20,"minimum":1,"maximum":100},"description":"Number of transactions to return (action=list only)."},{"name":"type","in":"query","required":false,"schema":{"type":"string","enum":["buy","sell","deposit","withdrawal"]},"description":"Filter by transaction type (action=list only)."},{"name":"status","in":"query","required":false,"schema":{"type":"string","enum":["PENDING","PROCESSING","SUCCESS","FAILED","PARTIAL"]},"description":"Filter by transaction status (action=list only)."},{"name":"stack_id","in":"query","required":false,"schema":{"type":"integer"},"description":"Filter by stack ID (action=list only). Cannot be combined with token_address."},{"name":"token_address","in":"query","required":false,"schema":{"type":"string"},"description":"Filter by token address (action=list only). Cannot be combined with stack_id."},{"name":"order_id","in":"query","required":false,"schema":{"type":"string"},"description":"Order ID to look up (action=detail only, required for detail)."}],"responses":{"200":{"description":"Successful response. Shape depends on action.","content":{"application/json":{"schema":{"oneOf":[{"title":"TransactionListResponse","type":"object","properties":{"transactions":{"type":"array","items":{"type":"object","properties":{"order_id":{"type":"string"},"stack_id":{"type":"integer","nullable":true},"transaction_type":{"type":"string","enum":["buy","sell","deposit","withdrawal"]},"status":{"type":"string","enum":["PENDING","PROCESSING","SUCCESS","FAILED","PARTIAL"]},"usdc_amount":{"type":"number"},"expected_amount":{"type":"number","nullable":true},"sell_percentage":{"type":"number","nullable":true},"slippage":{"type":"number","nullable":true},"creator_fee":{"type":"number","nullable":true},"platform_fee":{"type":"number","nullable":true},"created_at":{"type":"string"},"updated_at":{"type":"string","nullable":true},"parent_order_id":{"type":"string","nullable":true},"retry_attempt":{"type":"integer","nullable":true},"partial_completion_action":{"type":"string","nullable":true},"is_company_stack":{"type":"boolean"},"asset":{"type":"object","nullable":true,"properties":{"type":{"type":"string"},"name":{"type":"string"},"slug":{"type":"string","nullable":true},"symbol":{"type":"string","nullable":true},"address":{"type":"string","nullable":true},"image_url":{"type":"string","nullable":true},"archived":{"type":"boolean"}}},"tokens":{"type":"array","items":{"type":"object"}},"transaction_hash":{"type":"string","nullable":true},"from_wallet":{"type":"string","nullable":true,"description":"Present for deposits/withdrawals only."},"to_wallet":{"type":"string","nullable":true,"description":"Present for deposits/withdrawals only."},"block_slot":{"type":"integer","nullable":true,"description":"Present for deposits/withdrawals only."}}}},"pagination":{"type":"object","properties":{"offset":{"type":"integer"},"limit":{"type":"integer"},"total_count":{"type":"integer"},"has_more":{"type":"boolean"},"has_previous":{"type":"boolean"},"page":{"type":"integer"},"total_pages":{"type":"integer"}}}}},{"title":"TransactionDetailResponse","type":"object","properties":{"transaction":{"type":"object","description":"Same fields as list items, plus a `token_transactions` array with per-token breakdown.\n","properties":{"order_id":{"type":"string"},"token_transactions":{"type":"array","items":{"type":"object","properties":{"token_id":{"type":"integer"},"name":{"type":"string"},"symbol":{"type":"string"},"address":{"type":"string"},"image_url":{"type":"string","nullable":true},"amount":{"type":"number"},"usdc_paid":{"type":"number"},"decimals":{"type":"integer"},"archived":{"type":"boolean"}}}}}}}},{"title":"TransactionSummaryResponse","type":"object","properties":{"summary":{"type":"object","properties":{"total_transactions":{"type":"integer"},"total_buys":{"type":"integer"},"total_sells":{"type":"integer"},"total_deposits":{"type":"integer"},"total_withdrawals":{"type":"integer"},"successful_transactions":{"type":"integer"},"failed_transactions":{"type":"integer"},"pending_transactions":{"type":"integer"}}}}}]}}}},"400":{"description":"Bad request (invalid filters, missing order_id for detail, conflicting filters).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Transaction not found (action=detail).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"405":{"description":"Method not allowed (only GET is accepted).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## Fee calculations and bounds

> Calculate trading fees, retrieve minimum buy amount, or get creator fee bounds. No authentication required.<br>

```json
{"openapi":"3.0.3","info":{"title":"Indexify API","version":"0.1.12-beta"},"servers":[{"url":"https://api.indexify.finance","description":"Production"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-KEY","description":"API key with the `ix_` prefix. You can generate an API Key by navigating to Settings -> API Key in the web app. Pass it in the `X-API-KEY` header on every request."}},"schemas":{"Error":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}}}},"paths":{"/api/fee.php":{"post":{"tags":["Trading"],"summary":"Fee calculations and bounds","description":"Calculate trading fees, retrieve minimum buy amount, or get creator fee bounds. No authentication required.\n","operationId":"feeOperations","parameters":[{"name":"action","in":"query","required":true,"schema":{"type":"string","enum":["calculate","min_buy","creator_fee_bounds"]},"description":"The fee action to perform."}],"requestBody":{"required":false,"content":{"application/json":{"schema":{"oneOf":[{"title":"CalculateFeeRequest","type":"object","required":["amount","stack_id"],"properties":{"amount":{"type":"number","description":"USDC amount to calculate fees for."},"stack_id":{"type":"integer","description":"ID of the stack being traded."}}}]}}}},"responses":{"200":{"description":"Successful response. Shape depends on action.","content":{"application/json":{"schema":{"oneOf":[{"title":"CalculateFeeResponse","type":"object","properties":{"fee_display":{"type":"string","description":"Human-readable fee string (e.g. \"~$1.50 fee\")."},"estimated_blockchain_fees_saved":{"type":"string","description":"Estimated blockchain fees saved (e.g. \"$2.40\")."}}},{"title":"MinBuyResponse","type":"object","properties":{"min_buy":{"type":"number","description":"Minimum buy amount in micro-USDC."}}},{"title":"CreatorFeeBoundsResponse","type":"object","properties":{"min":{"type":"number","description":"Minimum creator fee percentage."},"max":{"type":"number","description":"Maximum creator fee percentage."},"default":{"type":"number","description":"Default creator fee percentage."}}}]}}}},"400":{"description":"Bad request (missing amount, invalid stack ID, amount below minimum).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal server error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```
