Usage
# Spend a specific USDC amount
result = client.market_buy(token_id="your-token-id", usdc_amount=50)
# Or buy a specific number of shares
result = client.market_buy(token_id="your-token-id", shares=100)
Market orders execute immediately at the best available prices. Use usdc_amount to spend a fixed amount, or shares to buy a specific quantity.
Parameters
The outcome token ID to buy.
USDC amount to spend. Preferred - gives you precise control over cost.
Number of shares to buy. Will be converted to USDC using the current market price.
Provide either usdc_amount OR shares, not both.
Response
Order status (typically FILLED or CANCELLED for market orders).
Warning message, if any (e.g., partial fill due to liquidity).
Order execution latency in milliseconds.
Examples
Spend a fixed USDC amount
from polyhush import PolyhushClient
client = PolyhushClient(api_key="your-api-key")
# Spend exactly $50 on shares at market price
result = client.market_buy(
token_id="12345678901234567890",
usdc_amount=50
)
print(f"Order: {result['order_id']}")
print(f"Status: {result['status']}")
Buy a specific number of shares
# Buy 100 shares at market price
result = client.market_buy(
token_id="12345678901234567890",
shares=100
)
print(f"Bought shares, order: {result['order_id']}")
Response
{
"order_id": "ord_mkt123",
"status": "FILLED",
"message": "Market order filled",
"latency_ms": 52
}
How It Works
Market buy orders use the FAK (Fill And Kill) order type:
- The order is placed at a high price to ensure it fills
- It matches against existing sell orders on the book
- Whatever fills immediately is executed
- Any unfilled portion is cancelled
Using usdc_amount is recommended because:
- You know exactly how much you’re spending
- No need to calculate shares based on fluctuating prices
- Better for budgeting and risk management
Slippage Considerations
Market orders may experience slippage if:
- The order is large relative to available liquidity
- The market is volatile
- There’s a wide bid-ask spread
For large orders, consider using limit orders (buy()) to control your execution price.