Decentralized platforms are growing that allows users to bet on the outcomes of various events, including economic, political, and entertainment events. So far there are PolyMarket and Kalshi.
investors can use Polymarket in several ways:
- Market Prediction: By analyzing the betting activity and odds on Polymarket, investors can gauge market sentiment and expectations about certain events. This can help them make more informed decisions about their own investments.
- Hedging: Investors can use Polymarket to hedge against certain outcomes. For example, if an investor has a portfolio that would be negatively impacted by a particular election result, they could place a bet on Polymarket that would pay out if that result occurs, thus offsetting some of their potential losses.
- Speculation: Some investors might use Polymarket simply as a speculative tool, betting on outcomes they believe are likely in order to profit from the payouts.
- Diversification: Adding bets on Polymarket to an investment portfolio can provide diversification, as the performance of these bets might be uncorrelated with other asset classes like stocks and bonds.
Here’s an overview of the main endpoints they offer:
REST API Endpoints
- Market Data:
- Fetch all available markets
- Get detailed information about specific markets
- Retrieve market prices and trading volumes
- Order Book:
- View the current order book for a given market
- Place new orders
- Cancel existing orders
- User Data:
- Get user account information
- View user’s open orders and trade history
- Event Data:
- Retrieve information about events (which are collections of related markets)
- Get event resolution details
WebSocket API
Polymarket also offers WebSocket endpoints for real-time data:
- Market Updates:
- Live price updates
- Order book changes
- Trade Notifications:
- Real-time notifications for executed trades
Gamma Markets API
This API provides access to market structure and resolution data:
- Event and Market Structure:
- Fetch all events and their associated markets
- Get detailed market structure information
- Resolution Data:
- Access market resolution information
- Retrieve data used for resolving markets
Part time Larry has provided codes to grab data:
“So to get started with this, let’s check out the Polymarket API.
Gamma Markets – https://gamma-api.polymarket.com
https://polymarket.com/event/what-will-kamala-say-during-acceptance-speech?tid=1724353609658
An event is a set of markets. For example:
Event – What will Kamala Harris say during her acceptance speech?
- Market – We’re not going back (Yes/No)
- Market – Ceasefire (Yes/No)
- Market – Joy (Yes/No)
- Market – Inflation (Yes/No)
- Market – Donald Trump (Yes/No)
- Market – Monkeypox (Yes/No)
Sometimes there is only 1 market for an event.
Event – Will Beyonce attend the DNC?
Event – Will Taylor Swift attend the DNC?
So in this phase of our research, we would be using the Gamma API, which is a REST API, a web endpoint. We’re exploring the various bets or contracts that are available. And we can think about what we know about them, are there data sources we can explore or anything we can think of to try to beat the odds. Once we have explored these, we can use another API to see what other people are doing in real time. How are these Yes / No values moving second by second. During the speech, when does a value start spiking or plummeting.” and below is his colab codes:
import requests
r = requests.get("https://gamma-api.polymarket.com/events?closed=false")
response = r.json()
response
kamala_events = {}
for event in response:
if 'Kamala' in event['title']:
print(event)
kamala_events[event['id']] = event
for market in kamala_events['12088']['markets']:
if 'outcomePrices' in market and 'clobTokenIds' in market:
print(market['id'], market['question'], 'outcomePrices' in market and market['outcomePrices'])
print('clobTokenIds' in market and market['clobTokenIds'])
print('=====')
#streaming data
!pip install websockets -q
import json
import asyncio
import websockets
import datetime
url = 'wss://ws-subscriptions-clob.polymarket.com/ws/market'
last_time_pong = datetime.datetime.now()
msgs = []
kamala_trump_yes_token = "112691550711713354714525509796202337193505769808087674259394206524293080902258"
kamala_trump_no_token = "40934908860656143479579576067633881276941830984503767038689094076378988206631"
trump_win_election_yes = "21742633143463906290569050155826241533067272736897614950488156847949938836455"
trump_win_election_no = "48331043336612883890938759509493159234755048973500640148014422747788308965732"
async with websockets.connect(url) as websocket:
await websocket.send(json.dumps({"assets_ids":[kamala_trump_yes_token, kamala_trump_no_token],"type":"market"}))
while True:
m = await websocket.recv()
if m != "PONG":
last_time_pong = datetime.datetime.now()
d = json.loads(m)
print(d)
if last_time_pong + datetime.timedelta(seconds=10) < datetime.datetime.now():
await websocket.send("PING")
else:
msgs.append(d)