Prediction Markets
发布时间:2026-09-18 | 浏览:1
Fetch live markets, stream prices, and place orders on event-based contracts via REST and WebSocket.
Make a Public REST Request
No API key required. Fetch live markets and copy an instrumentSymbol before writing a single line of trading code.
Copy an instrumentSymbol from an active, open contract. That value is what you pass to WebSocket streams and order requests. All prices and quantities are decimal strings.
Events, Contracts, and Outcomes
An event is the broader question. A contract is one tradable proposition expressed in YES space. Each contract supports YES and NO outcomes.
Buy YES if you think the contract proposition will resolve YES, or NO if you think it will resolve NO. The winning outcome pays $1.00 and the losing outcome pays $0.00. Price reflects the market's implied probability.
Know Which Identifier to Use
API responses include several ticker fields. Use instrumentSymbol verbatim, exactly as returned, for all WebSocket and order requests.
Place a Maker-Only Limit Order
Use WebSocket for active trading. Authentication happens during the WebSocket handshake, so create an account-scoped key with time-based nonces enabled before connecting.
Before your first live order, create an API key , read the current terms, and check GET /v1/prediction-markets/terms/status . If the latest terms are not accepted, call POST /v1/prediction-markets/terms/accept . BTC 5-minute contracts expire every 5 minutes, so fetch a current instrumentSymbol from GET /v1/prediction-markets/events before sending this request. Buying 1 contract of the YES outcome at $0.48 costs $0.48 ; that outcome pays $1.00 if the proposition resolves YES and $0.00 if it does not.
Gemini has a full demo environment, also called the sandbox, at api.sandbox.gemini.com . It requires a separate account . The WebSocket endpoint is wss://api.sandbox.gemini.com . Confirm that the product and operation are supported in the demo environment before testing.
WebSocket Trading
Stream prices, place orders, and receive fills over a single persistent WebSocket connection. Authenticated streams require upgrade headers. Browsers cannot set these, so use a backend or local client.
Set up credentials
Create an account-scoped API key and export it as environment variables. WebSocket authentication requires account-scoped keys with time-based nonces enabled. Keys without these settings will be rejected at connection time.
Fetch active market and stream prices
BTC 5-minute contracts expire every 5 minutes, so fetch the current symbol from REST before connecting. The code below resolves the active BTC05M contract, authenticates, and subscribes to {symbol} @bookTicker .
Subscribe and Place an Order
Accept Prediction Markets terms via REST before the first live order, then subscribe to orders@account and positions@account alongside the price stream. MOC accepts the order request, then cancels it if it would take liquidity. If it returns MakerOrCancelWouldTake , the price moved before the order could rest.
Handle Order Updates and Cancel
Cancel resting quotes before intentionally closing the connection with order.cancel_session . On unexpected disconnect, reconnect and query the REST active-orders and order-history endpoints for any open or accepted quotes before placing new ones.