Regarding the future of VPX — Read our announcement →
vancouverpx
← Back to Markets

API Documentation

REST API reference for the Vancouver Prediction Exchange

Build a Trading Bot

This guide builds a small market-making bot: every minute it reads the order book of each open market, takes the midpoint as fair value, and bids a couple of cents under it on both YES and NO. It uses four endpoints and fits on one screen.

1. Get an API key

Sign in and create a key on the Developer Settings page. The bot trades from your account, so it can only spend your unlocked cash.

2. Run the bot

Each loop cancels every open order on the account (so give the bot its own account) with Cancel All Orders, lists open markets with Get Markets, reads each order book, and quotes with Place Order. Buying YES at mid − 2 and NO at 100 − mid − 2 quotes both sides without holding any shares, and the two bids never match each other.

import time
import requests

API_KEY = "your_api_key"
BASE_URL = "https://www.vancouverpx.ca/api/v1"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
EDGE = 2       # cents under fair value
QUANTITY = 10  # shares per quote

def call(method, path, **kwargs):
    response = requests.request(method, BASE_URL + path, headers=HEADERS, **kwargs)
    response.raise_for_status()
    return response.json()

def fair_value(market_id):
    book = call("GET", "/market/order-book", params={"marketId": market_id})
    bids, asks = book["orderBookYes"]["bids"], book["orderBookYes"]["asks"]
    if not bids or not asks:
        return None
    return (bids[0]["price"] + asks[0]["price"]) / 2

while True:
    call("POST", "/cancel-everything")
    for market in call("GET", "/markets", params={"status": "OPEN"})["markets"]:
        mid = fair_value(market["id"])
        if mid is None:
            continue
        for outcome, price in (("YES", mid - EDGE), ("NO", 100 - mid - EDGE)):
            price = round(price)
            if not 1 <= price <= 99:
                continue
            try:
                call("POST", "/order", json={
                    "marketId": market["id"], "side": "BUY",
                    "outcome": outcome, "price": price, "quantity": QUANTITY,
                })
            except requests.HTTPError as error:
                print(market["question"], outcome, error.response.text)
    time.sleep(60)

3. Make it yours

  • Replace the midpoint with your own model of fair value; that is where the edge is.
  • Check your positions and skew quotes to avoid piling into one side.
  • Read Market Integrity before quoting tight: resting orders get picked off when news breaks.

Generating a client or wiring the API into an AI agent? The full API is described as an OpenAPI spec.

Build a Prediction Market Trading Bot | VPX API Docs