|
| 1 | +--- |
| 2 | +title: buildOrder |
| 3 | +description: Build an order payload without submitting it. Hosted returns EIP-712 typed data to sign locally. |
| 4 | +--- |
| 5 | + |
| 6 | +<Tabs> |
| 7 | + <Tab title="Hosted (recommended)"> |
| 8 | + <Note> |
| 9 | + The hosted path routes to `POST trade.pmxt.dev/v0/trade/build-order` and is |
| 10 | + the default when `pmxt_api_key` is set. Returns a `built_order_id` plus EIP-712 |
| 11 | + typed data the wallet must sign before calling |
| 12 | + [`submitOrder`](/api-reference/submitOrder). Pass catalog UUIDs |
| 13 | + (`market_id`, `outcome_id`), not venue-native ids. See |
| 14 | + [hosted trading](/concepts/hosted-trading) for the end-to-end flow. |
| 15 | + Get a key at [pmxt.dev/dashboard](https://pmxt.dev/dashboard). |
| 16 | + </Note> |
| 17 | + |
| 18 | + <CodeGroup> |
| 19 | + ```python Python |
| 20 | + import pmxt |
| 21 | + |
| 22 | + client = pmxt.Polymarket( |
| 23 | + pmxt_api_key="YOUR_PMXT_API_KEY", |
| 24 | + wallet_address="0xYourWallet", |
| 25 | + private_key="0x...", |
| 26 | + ) |
| 27 | + built = client.build_order( |
| 28 | + market_id="12345678-1234-1234-1234-123456789abc", |
| 29 | + outcome_id="abcdef01-2345-6789-abcd-ef0123456789", |
| 30 | + side="buy", |
| 31 | + type="limit", |
| 32 | + amount=10, |
| 33 | + price=0.55, |
| 34 | + ) |
| 35 | + print(built.expiry, built.raw) |
| 36 | + # Sign + submit later with client.submit_order(built). |
| 37 | + ``` |
| 38 | + |
| 39 | + ```javascript TypeScript |
| 40 | + import { Polymarket } from "pmxtjs"; |
| 41 | + |
| 42 | + const client = new Polymarket({ |
| 43 | + pmxtApiKey: "YOUR_PMXT_API_KEY", |
| 44 | + walletAddress: "0xYourWallet", |
| 45 | + privateKey: "0x...", |
| 46 | + }); |
| 47 | + |
| 48 | + const built = await client.buildOrder({ |
| 49 | + marketId: "12345678-1234-1234-1234-123456789abc", |
| 50 | + outcomeId: "abcdef01-2345-6789-abcd-ef0123456789", |
| 51 | + side: "buy", |
| 52 | + type: "limit", |
| 53 | + amount: 10, |
| 54 | + price: 0.55, |
| 55 | + }); |
| 56 | + console.log(built.expiry, built.raw); |
| 57 | + // Sign + submit later with client.submitOrder(built). |
| 58 | + ``` |
| 59 | + |
| 60 | + ```bash curl |
| 61 | + curl -X POST "https://trade.pmxt.dev/v0/trade/build-order" \ |
| 62 | + -H "Authorization: Bearer $PMXT_API_KEY" \ |
| 63 | + -H "Content-Type: application/json" \ |
| 64 | + -d '{ |
| 65 | + "market_id": "12345678-1234-1234-1234-123456789abc", |
| 66 | + "outcome_id": "abcdef01-2345-6789-abcd-ef0123456789", |
| 67 | + "side": "buy", |
| 68 | + "order_type": "limit", |
| 69 | + "amount": 10, |
| 70 | + "denom": "shares", |
| 71 | + "price": 0.55, |
| 72 | + "user_address": "0xYourWallet" |
| 73 | + }' |
| 74 | + ``` |
| 75 | + </CodeGroup> |
| 76 | + </Tab> |
| 77 | + |
| 78 | + <Tab title="Self-hosted"> |
| 79 | + <Note> |
| 80 | + The self-hosted path uses the local sidecar at |
| 81 | + `POST localhost:3847/api/{exchange}/buildOrder`. Returns the venue-native |
| 82 | + signed order or request body for inspection or deferred submission via |
| 83 | + [`submitOrder`](/api-reference/submitOrder). See |
| 84 | + [Self-hosted](/guides/self-hosted) for setup. |
| 85 | + </Note> |
| 86 | + |
| 87 | + <CodeGroup> |
| 88 | + ```python Python |
| 89 | + import pmxt |
| 90 | + |
| 91 | + client = pmxt.Polymarket( |
| 92 | + api_key="YOUR_VENUE_API_KEY", |
| 93 | + api_secret="YOUR_VENUE_API_SECRET", |
| 94 | + passphrase="YOUR_PASSPHRASE", |
| 95 | + private_key="YOUR_PRIVATE_KEY", |
| 96 | + proxy_address="YOUR_PROXY_ADDRESS", |
| 97 | + ) |
| 98 | + built = client.build_order( |
| 99 | + market_id="12345", |
| 100 | + outcome_id="67890", |
| 101 | + side="buy", |
| 102 | + type="limit", |
| 103 | + amount=10, |
| 104 | + price=0.55, |
| 105 | + ) |
| 106 | + print(built.exchange, built.raw) |
| 107 | + ``` |
| 108 | + |
| 109 | + ```javascript TypeScript |
| 110 | + import { Polymarket } from "pmxtjs"; |
| 111 | + |
| 112 | + const client = new Polymarket({ |
| 113 | + apiKey: "YOUR_VENUE_API_KEY", |
| 114 | + apiSecret: "YOUR_VENUE_API_SECRET", |
| 115 | + passphrase: "YOUR_PASSPHRASE", |
| 116 | + privateKey: "YOUR_PRIVATE_KEY", |
| 117 | + proxyAddress: "YOUR_PROXY_ADDRESS", |
| 118 | + }); |
| 119 | + |
| 120 | + const built = await client.buildOrder({ |
| 121 | + marketId: "12345", |
| 122 | + outcomeId: "67890", |
| 123 | + side: "buy", |
| 124 | + type: "limit", |
| 125 | + amount: 10, |
| 126 | + price: 0.55, |
| 127 | + }); |
| 128 | + console.log(built.exchange, built.raw); |
| 129 | + ``` |
| 130 | + |
| 131 | + ```bash curl |
| 132 | + curl -X POST "http://localhost:3847/api/polymarket/buildOrder" \ |
| 133 | + -H "Content-Type: application/json" \ |
| 134 | + -d '{"args":[{"marketId":"12345","outcomeId":"67890","side":"buy","type":"limit","amount":10,"price":0.55}]}' |
| 135 | + ``` |
| 136 | + </CodeGroup> |
| 137 | + </Tab> |
| 138 | +</Tabs> |
0 commit comments