Skip to content
← All articles
Article

Python library for MarketWatch virtual trading

Listen to the audio story

A Python client for a stock game · 1:57 · AI-written script, synthetic voices

Transcript

Ava: Imagine a stock-trading game where you want a script to check your portfolio every morning. The site has no official API. What do you do?

Andrew: Scrape it and hope?

Ava: More or less, but tidily. Antoine wanted to automate chores in MarketWatch's virtual stock game. It's paper trading, not a real broker. So he shipped a small Python package on PyPI called marketwatch.

Andrew: What does it cover?

Ava: Watchlists, listing games and reading their settings, positions and pending orders, buying and selling inside the game rules, and the leaderboard. You log in once with a class, then make many calls in a script.

Andrew: Why not just use curl scripts in a notebook?

Ava: Two reasons. The game has session cookies, rules and leaderboards that change with the semester. And he wanted something documented for teammates. A shared gist rots the moment the HTML form changes. The package is intentionally small: no database layer, no strategy engine, just HTTP shaped like the site.

Andrew: Any design choices worth noting?

Ava: One explicit method per endpoint, so it's easy to search when MarketWatch changes a path. Docs on GitHub Pages, because the PyPI description is too short for login edge cases. And no bundled strategies, so the library stays neutral.

Andrew: How do you use it?

Ava: Install it with pip, create the client with a username and password, then call something like get games or get price for a ticker.

Andrew: And the warnings?

Ava: Honest ones. It's an unofficial API, so pin versions and expect breakage. Automation may conflict with the site's terms, so it's for learning, not abuse. And paper gains don't validate a strategy.

Andrew: So who's it for?

Ava: Small bots and screening inside the game. Not high-frequency trading, not brokerage. The full write-up links the docs and the source.

MarketWatch Python client — package branding
Table of contents

I wanted to automate chores in MarketWatch’s virtual stock game (paper trading, not a real broker). marketwatch[1] on PyPI is the small client I shipped — watchlists, game state, portfolio, orders, leaderboard.

1. Why build this

Course and side projects already used BatchBacktesting on historical data — see experimentation with indicators. MarketWatch’s game is a different beast: session cookies, game rules, and leaderboards that change with the semester. A thin Python wrapper beat curl scripts in a notebook.

I also wanted a documented surface for teammates: “here is how you list games” beats sharing a gist that rots when the HTML form changes. The package is intentionally small — no ORM, no strategy engine — just HTTP shaped like the site.

2. Design choices

ChoiceReason
Class-based clientOne login, many calls in a script
Explicit methods per endpointEasier to grep when MarketWatch changes a path
Docs on GitHub PagesPyPI description alone is too short for auth edge cases
No bundled strategiesKeeps the library neutral; strategies belong in your repo

4. What it can do

AreaMethods (see docs for signatures)
WatchlistsCreate, list, update symbols
GamesList games, read settings
PortfolioPositions, pending orders
TradingBuy / sell inside game rules
SocialLeaderboard for a game

Useful for small bots and screening inside the game — not HFT, not brokerage.

5. Quick start

pip install marketwatch
from marketwatch import MarketWatch

mw = MarketWatch("your_username", "your_password")
mw.get_games()
mw.get_price("AAPL")

Login edge cases (2FA absent, session expiry) are documented on the site — read before cron-scheduling anything.

6. Limits and responsibility

  • Unofficial API — HTML/JSON endpoints can change; pin versions and expect breakage.
  • Terms of use — automation may conflict with MarketWatch rules; use for learning, not abuse.
  • Not financial advice — paper gains do not validate a strategy; pair with honest backtests on separate data.

For research-style batch runs on many tickers, see multiple indicators backtesting and Monte Carlo risk bands.

Questions or bugs: GitHub issues[3].

References

  1. marketwatch. (). [Web page] pypi.org.
  2. antoinebou12.github.io/marketwatch. (). [Web page] antoinebou12.github.io.
  3. antoinebou12. (). marketwatch. [Software repository] github.com.

References use this article’s publication date.