Week 4: Data APIs, Static Sites, and GitHub Actions#
Week 3 left two pieces of HW 2 unfinished: the vendor its futures come from,
and the website its results go to. This week takes both, and then the
machinery that will run them without you. Databento first, as a modern data
API: a key per project, a cost you can check before you pay it, and the same
request made from a Python SDK or as a raw HTTP call. Then the math behind
CME’s FedWatch tool. Then the web itself: what a static HTML page is, how
GitHub Pages serves a folder of them, and why the folder doit builds stays
out of main. We keep it out by hand, with a gh-pages branch, and the
chore of doing that is the case for GitHub Actions, which we read through
the workflow that has graded every push since HW 1.
Announcements#
HW 1 is due tonight, at the start of class.
HW 2 is due next Tuesday, October 27. Questions at the start of class, and the FedWatch half is tonight’s first item.
HW 3 launches next week, due Tuesday, November 10, in week 7. Tonight introduces it; your private copy is created the week it launches.
Project assignments go out Wednesday morning. The preference survey closes tonight at 11:59 pm. Consultations start this week and run through week 7; if your group has not booked its consultation, do it now.
Databento API keys. HW 3 uses the key you set up for HW 2, and asks you to store it as a GitHub Actions secret. Everything we pull is on the CME Globex feed (
GLBX.MDP3) and free under the course license.
Objectives#
Pull data from a vendor’s API with a key kept in
.env, say why a key per project helps with access and metering, and check what a query costs before running it: Databento and Pulling Market Data From Databento.Say what an SDK adds on top of a raw HTTP API, and make the same request both ways.
Explain how fed funds futures prices imply the probability of a rate move at the next FOMC meeting.
Explain what a static website is, and publish a folder of HTML with GitHub Pages: Publishing to GitHub Pages.
Say why a pipeline’s built output stays out of
main, and keep agh-pagesbranch by hand.Read a GitHub Actions workflow: its triggers, including a
cronschedule, its permissions, its jobs and their conditions, its runners, its steps, and its secrets: Cron Jobs.
Agenda Item 1: Databento, a Modern Data API#
Databento, with the
databento/ examples
in the in-class repository, which are also a notebook:
Pulling Market Data From Databento.
A key per project. WRDS authenticates you with a password kept in
.pgpass. Databento issues API keys, as many as you like: one per project, so each can be revoked on its own and each project’s usage can be metered separately. The key lives in.env, never in the code.A subscription, or pay as you go. The course’s subscription covers CME Globex history with no download limit, but no live feed. A personal account pays by the gigabyte instead.
metadata.get_costprices any query for free before you run it, which makes a cost guard possible: stop unless the estimate is zero.Schemas. One parameter decides whether a request returns trades, daily bars, the exchange’s settlement statistics, or the full order book.
An SDK, and the raw API under it. The Python client wraps an HTTP API. The same request made with
curlon the command line, or withrequests.postin Python, returns the same data, which is what lets any language talk to the service.An aside: LSEG Datastream on WRDS, for continuous futures series, the decision of how to roll from one contract to the next, and the tools for finding a series’ code.
Agenda Item 2: FedWatch#
HW 2 is due in a week. Then the half of it that week 3 did not reach. Open the CME FedWatch tool. A 30-Day Fed Funds futures contract settles at 100 minus the month’s average effective fed funds rate, so its price is the market’s forecast of that average. Split the month at the FOMC meeting: the days before it sit at today’s rate, and the days after it at either today’s rate or a new one. With two outcomes on the table, stay or move by 25 basis points, the price pins down the probability of the move.
Agenda Item 3: Static Sites and GitHub Pages#
What an HTML page is. A text file with a head and a body: headers, paragraphs, lists, and links. Pages that link to each other by relative paths are a website, and nothing about them needs a server: open one from your disk and the browser renders it. A dynamic site runs code on a server for every visitor; a static one does not.
Publishing a folder.
chartbook docs buildwrites every page of a project’s site intodocs/. Any host that serves files can publish it. GitHub Pages serves a branch’s root or itsdocs/folder. Done live: a new public repository with the HW 2 site copied in, and Pages turned on..nojekyll. Pages was built for Jekyll sites, and an empty.nojekyllfile says this one is plain HTML.
Agenda Item 4: Keeping Output Out of main#
Serving docs/ from main fails, because docs/ is in .gitignore, and it
should be. main is for source code. A rebuilt site is hundreds of files
nobody reads, many of them change on every rebuild even when nothing
meaningful did, and committing them each time bloats the history.
A
gh-pagesbranch, by hand. Branch frommain, removedocs/from that branch’s.gitignore, commit the site, push the branch, and point Pages at it.Keeping it current. After each change to
main, rebasegh-pagesonto it, rebuild, amend the site’s commit, and force-push. The branch stays two commits ahead ofmainand never accumulates history. A force-push overwrites the remote, which is safe only on a branch no one else works on.Every one of those steps is manual, which is the case for automating them. In week 5 a workflow does it, and HW 3 hands you that workflow.
Agenda Item 5: GitHub Actions, Read from the Autograder#
Open .github/workflows/tests.yml in your HW repository, the workflow that
has graded every push since HW 1. Turning on Pages added a second workflow,
pages build and deployment, which GitHub wrote for you.
on: what starts a workflow. Every push, the Run workflow button (workflow_dispatch), or a schedule written in cron syntax, always in UTC.permissions,jobs, andif: what the workflow may change, the jobs it runs, themselves a small DAG, and when a job is skipped. The grader skips the instructor’s pushes and the first commit of a new copy.runs-on: where a job runs. GitHub’s hosted runners are small virtual machines, created and destroyed for every run, with free minutes for public repositories. The grader runs on a self-hosted runner instead: a Mac mini that keeps the course’s cached data.steps: each oneusesa published action, such asactions/checkout, orruns commands in a shell. The grader’s steps build the environment, find the cached data, runpytest, and turn the results into a score.Secrets: a repository secret (Settings > Secrets and variables > Actions) reaches a step through
env:and${{ secrets.NAME }}, and the pipeline reads it from the environment just as it reads.envlocally. Databento’s key works this way. WRDS’s.pgpasswould not, on a runner rebuilt for every run.
Agenda Item 6: Where CI/CD Lives#
Every open-source package runs workflows like these. Open pandas’ Actions tab: tests on every pull request, so nothing regresses, and builds published continuously, nightly ones included. That is continuous integration and continuous deployment. Packaging and its CI come back in week 8.
Final Projects#
Assignments go out Wednesday morning. Each group books one consultation in weeks 4 through 7. The rubric requires every pull request to be reviewed by a teammate; the pull-request workflow is covered in week 7.
Looking ahead to Week 5#
Week 5 automates what this week did by hand: a live monitor that a workflow
updates every day, deployed in class, then the math of HW 3. It also catches
up on what this week did not reach: modules and packages, and uv.