Skip to content
← All articles
Article

Python library for MarketWatch virtual trading

Listen to the audio story

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

Transcript

Ava: What if you could run a stock-trading game from a Python script, with no real money at stake? That's what Antoine's small package, marketwatch, lets you do.

Andrew: A stock game? Like paper trading?

Ava: Exactly. MarketWatch runs a virtual stock game, and Antoine wanted to automate the chores in it. So he published a client on PyPI. Install it with pip, log in with your username and password, and you can list your games, check a price like Apple's, and more.

Andrew: What can it actually do?

Ava: It covers watchlists, where you create, list and update symbols. It reads games and their settings. It shows your portfolio, with positions and pending orders. It places buys and sells inside the game's rules. And it can fetch the leaderboard for a game.

Andrew: Why not just poke the site with curl?

Ava: Because the game uses session cookies, game rules and leaderboards that change with the semester. A thin Python wrapper handles that in one place. Think of it as a remote control for the site: one login, then many buttons.

Andrew: And the design is intentionally small.

Ava: Right. It's a class-based client, so one login serves many calls in a script. Each endpoint gets its own explicit method, which makes the code easy to search. There's no database layer and no strategy engine, just HTTP shaped like the site. Strategies belong in your own repo.

Andrew: Why did he want it documented?

Ava: So teammates have a clear surface: here's how you list games, instead of passing around a script that breaks. The docs live on GitHub Pages, with the login details covered.

Andrew: Where does it fit with his other work?

Ava: It pairs naturally with his backtesting projects. BatchBacktesting runs strategies on historical data, and this client lets you try ideas inside a live game, handy for small bots and screening.

Andrew: So the takeaway is a tidy wrapper that turns a game into something scriptable.

Ava: That's it. The write-up has the links to PyPI, the docs and the source on GitHub.

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.