Prediction market trading on Polymarket
import { Polymarket } from './Polymarket.js'; const poly = Polymarket({ provider, ctfExchange: CTF_EXCHANGE_ADDRESS, }); // Get market info const market = await poly.getMarket(conditionId); console.log('Outcomes:', market.outcomes); console.log('Prices:', market.prices); // Buy outcome tokens await poly.buy({ conditionId, outcomeIndex: 0, // YES amount: parseUnits('100', 6), // 100 USDC minOutcomeTokens: parseEther('150'), signer, });
// Place limit order await poly.placeLimitOrder({ conditionId, outcomeIndex: 0, side: 'BUY', price: 0.65, // 65 cents size: parseUnits('100', 6), signer, }); // Cancel order await poly.cancelOrder({ orderId, signer });
// Redeem winning outcome tokens after resolution await poly.redeemPositions({ conditionId, indexSets: [1], // Outcome 0 won signer, });
Was this page helpful?