|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import { tradeApi } from "./services/trading.js"; |
| 4 | + |
| 5 | +/** |
| 6 | + * Script to place a market order on Polymarket |
| 7 | + * |
| 8 | + * This script demonstrates how to place a BUY market order |
| 9 | + * with specific parameters. |
| 10 | + */ |
| 11 | +async function placeMarketOrder() { |
| 12 | + try { |
| 13 | + console.log("🚀 Placing market order..."); |
| 14 | + |
| 15 | + // Market order parameters |
| 16 | + const params = { |
| 17 | + side: "BUY" as const, |
| 18 | + tokenId: |
| 19 | + "60487116984468020978247225474488676749601001829886755968952521846780452448915", |
| 20 | + amount: 1, // For BUY orders, this is the dollar amount ($USD) to spend |
| 21 | + }; |
| 22 | + |
| 23 | + console.log("📋 Order parameters:", JSON.stringify(params, null, 2)); |
| 24 | + |
| 25 | + // Execute the market order |
| 26 | + const result = await tradeApi.placeMarketOrder(params); |
| 27 | + |
| 28 | + console.log("✅ Market order placed successfully!"); |
| 29 | + console.log("📊 Result:", JSON.stringify(result, null, 2)); |
| 30 | + |
| 31 | + return result; |
| 32 | + } catch (error) { |
| 33 | + console.error("❌ Error placing market order:", error); |
| 34 | + |
| 35 | + // Check if it's an approval error |
| 36 | + if (error && typeof error === "object" && "message" in error) { |
| 37 | + console.error("Error details:", error.message); |
| 38 | + } |
| 39 | + |
| 40 | + throw error; |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +// Run the script |
| 45 | +placeMarketOrder() |
| 46 | + .then(() => { |
| 47 | + console.log("🎉 Script completed successfully"); |
| 48 | + process.exit(0); |
| 49 | + }) |
| 50 | + .catch((error) => { |
| 51 | + console.error("💥 Script failed:", error); |
| 52 | + process.exit(1); |
| 53 | + }); |
0 commit comments