Skip to content

Fix SignalsAPI.stake_get (KeyError on removed totalStake field)#2

Closed
lingster wants to merge 1 commit into
masterfrom
fix-signals-stake-get
Closed

Fix SignalsAPI.stake_get (KeyError on removed totalStake field)#2
lingster wants to merge 1 commit into
masterfrom
fix-signals-stake-get

Conversation

@lingster

Copy link
Copy Markdown
Owner

Problem

SignalsAPI.stake_get raised KeyError: 'totalStake' on every call:

data = self.public_user_profile(username)
return data['totalStake']

totalStake was once part of the profile query (added in c4451ec / 6a9819f)
but was dropped when the query was migrated to v2SignalsProfile and then
v3UserProfile. The field no longer exists on the V3UserProfile type at all,
so the lookup always failed.

Fix

Query the current stake field, stakeValue (type Nmr), directly within the
signals tournament and parse it to Decimal, returning None for models with
no stake (instead of raising):

query = '''
  query($model_name: String!, $tournament: Int) {
    v3UserProfile(model_name: $model_name, tournament: $tournament) {
      stakeValue
    }
  }
'''

Testing (red/green TDD)

  • New test_stake_get (asserts stakeValue is queried, totalStake is not,
    and the request is scoped to tournament 11) and test_stake_get_no_stake
    (null stake → None). Written failing first.
  • Full suite: 44 passed (live-API tests deselected); pyflakes clean.
  • Live check: SignalsAPI().stake_get("uuazed") now returns a real
    Decimal instead of raising; an unstaked model returns None.

🤖 Generated with Claude Code

stake_get read `data['totalStake']` from public_user_profile, but that field
was dropped from the profile query during the v2SignalsProfile/v3UserProfile
refactors (commits c4451ec/6a9819f added it; later refactors removed it).
`totalStake` no longer exists on the V3UserProfile type at all, so stake_get
raised KeyError for every call.

Query `stakeValue` (type Nmr) directly within the signals tournament and parse
it to Decimal, returning None when the model has no stake.

Verified against the live API: stake_get("uuazed") now returns the real stake
value instead of raising.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb6d6c21c7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread numerapi/signalsapi.py
Comment on lines +304 to +305
v3UserProfile(model_name: $model_name
tournament: $tournament) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Query the Signals profile endpoint

In a SignalsAPI call, the username identifies a Signals model; this class and the changelog map Signals profiles to v2SignalsProfile, while v3UserProfile is the Classic profile endpoint. For Signals-only model names this call will not find the model, and for names shared across tournaments it can return the Classic stake instead, so SignalsAPI().stake_get(...) still gives users the wrong result. Use the Signals profile stake field (nmrStaked) instead.

Useful? React with 👍 / 👎.

@lingster

Copy link
Copy Markdown
Owner Author

Superseded by upstream PR numerai#129.

@lingster lingster closed this Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant