Skip to content

fix: verify and correct new operator behavior#43

Merged
bearmug merged 1 commit into
mainfrom
fix/operator-verification
Mar 17, 2026
Merged

fix: verify and correct new operator behavior#43
bearmug merged 1 commit into
mainfrom
fix/operator-verification

Conversation

@bearmug

@bearmug bearmug commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR verifies each of the 6 new operators end-to-end against the live TradingView scanner API and fixes the issues found.

Findings

Operator API Status Issue
empty"empty" Works None — right: undefined correctly dropped by JSON.stringify
not_empty"nempty" Works None
above_percent"above%" Wrong format documented API requires [field_name, percent_float] — e.g. ["SMA200", 10] — NOT [percent, field]. Sending [10, "SMA200"] returns "type of percent must be float64" error
below_percent"below%" Wrong format documented Same as above
has Works on set-type fields Only works on array/set fields like typespecs; returns "Unsupported string operation has" on string fields like sector
has_none_of Works on set-type fields Same caveat as has

Changes

src/api/types.ts

  • Widen ScreenStocksInput.filter[].value type to include [string, number] tuple (for above_percent/below_percent)
  • Make value optional at the type level (runtime validation in validateAndConvertFilters already handles the empty/not_empty special case)

src/index.ts

  • Add all 6 new operators to the enum in every tool schema (screen_stocks, screen_forex, screen_crypto, screen_etf) — they were missing, so AI assistants using these tools had no way to discover them
  • Update value field descriptions and examples to show the correct [field_name, percent] format for above_percent/below_percent and the array format for has/has_none_of

src/tests/screen.test.ts

  • Add 10 new unit tests covering all 6 operators (conversion correctness, no-value behavior for empty/not_empty, value-required enforcement for other operators)
  • Update validOperators list to include above_percent, below_percent, has, has_none_of (4 of the 6 new ones — empty/not_empty tested separately since they don't require a value)
  • Test count: 84 → 94, all passing

Test plan

  • npm run build passes (TypeScript clean)
  • npm test — 94 tests, 0 failures
  • Live API verified: empty/nempty return correct results (3 stocks vs 2235 stocks with dividend filter)
  • Live API verified: above% with ["SMA200", 10.5] returns stocks with close > SMA200 * 1.105
  • Live API verified: below% with ["SMA200", 10.5] returns 2078 large-caps below their SMA200 by 10.5%
  • Live API verified: has with typespecs + ["common"] returns 206 results
  • Live API verified: has_none_of with typespecs + ["preferred"] returns 290 results
  • Live API verified: existing operators (in_range, greater, crosses_above) still work correctly

- Fix above_percent/below_percent value format: API requires [field_name, percent_float]
  order (e.g. ["SMA200", 10]), not [percent, field_name] as the naive reading suggested.
  Verified via live API: [10, "SMA200"] returns "type of percent must be float64" error
  while ["SMA200", 10.5] works correctly.
- Clarify has/has_none_of operators: work on set/array-type fields (e.g. typespecs),
  not string fields (sector, exchange) — string fields return "Unsupported string operation".
- Widen ScreenStocksInput.value type to include [string, number] tuple for percent operators
  and make value optional (empty/not_empty are already validated at runtime).
- Add all 6 new operators to the MCP tool schema enums in index.ts for all 4 tools
  (screen_stocks, screen_forex, screen_crypto, screen_etf) with correct usage examples.
- Add 10 new unit tests covering all 6 new operators: conversion correctness, no-value
  behavior for empty/not_empty, and value-required enforcement for other new operators.
  Test count: 84 → 94, all passing.
@bearmug bearmug merged commit 2694063 into main Mar 17, 2026
2 checks passed
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