Repository navigation
Add example: external signal feed polled by a BackgroundWorker (kalshi-predictit-arb) - #866
Open
mastertyrone wants to merge 12 commits into
Open
mastertyrone wants to merge 12 commits into
mastertyrone wants to merge 12 commits into
Conversation
The feed labels rows with "event"; "pair" is the older name. The example strategy now keys and logs on event, falls back to pair, and skips rows that have neither, so no blank or "None" labels. The offline sample fixture now uses the live row shape (event, kalshi, predictit, best_direction, stats, fetched_at) with fictional values and is still marked as sample data. Adds tests for event-first, pair fallback, rows with neither skipped, and the fixture shape.
The feed labels rows with "event"; "pair" is the older name. The example strategy now keys and logs on event, falls back to pair, and skips rows that have neither, so no blank or "None" labels. The offline sample fixture now uses the live row shape (event, kalshi, predictit, best_direction, stats, fetched_at) with fictional values and is still marked as sample data. Adds tests for event-first, pair fallback, rows with neither skipped, and the fixture shape.
The feed labels rows with "event"; "pair" is the older name. The example strategy now keys and logs on event, falls back to pair, and skips rows that have neither, so no blank or "None" labels. The offline sample fixture now uses the live row shape (event, kalshi, predictit, best_direction, stats, fetched_at) with fictional values and is still marked as sample data. Adds tests for event-first, pair fallback, rows with neither skipped, and the fixture shape.
The feed labels rows with "event"; "pair" is the older name. The example strategy now keys and logs on event, falls back to pair, and skips rows that have neither, so no blank or "None" labels. The offline sample fixture now uses the live row shape (event, kalshi, predictit, best_direction, stats, fetched_at) with fictional values and is still marked as sample data. Adds tests for event-first, pair fallback, rows with neither skipped, and the fixture shape.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What the feed computes (server-side; nothing below is reimplemented in flumine):
ceil(7·P·(1−P))¢ per leg.executable=trueonly at ≥1¢ net.Why it's here as a flumine example: it shows a pattern that works for any external signal feed, whatever the source:
examples/workers/arbfeed.py:poll_arb_feedruns in aBackgroundWorkerand pushes results ontohandler_queueas aCustomEvent. The callback runs on the main thread and writes signals intostrategy.context. This is the same approach asworkers/inplayservice.py.examples/strategies/arbsignal.py:ArbSignalStrategy.check_market_bookonly returns True while a fresh executable signal meetscontext["min_net_yield_c"].process_market_booklogs each new signal. It places no orders.examples/workers/arbscanner.py: a small client for the feed.X402_WALLET_KEYis set. It then:exact/ Base USDC / 0 < amount ≤max_usd_per_call(default $0.02);TransferWithAuthorizationwith eth-account'sencode_typed_data;PAYMENT-SIGNATURE, and retries once.examples/example-arbfeed.py: a runnable script usingFlumine+SimulatedClient.examples/resources/kalshi_predictit_arb_sample.json: fictional data, labelled as sample in the file.tests/test_example_arbfeed.py: 34 tests usingunittest.mock, with no network calls. They cover:Account.create()address);encode_typed_dataproduces the same signature as a hand-rolled EIP-712 hash;accepts;Limits:
CustomEvent→ context. Thecheck_market_bookgating is covered by the unit tests. For real markets, swap in aBetfairClientand a stream, as intennisexample.py.requirements.txt. Without it, 17 of the 30 new tests skip, which is what will happen in this repo's CI.Size: 6 new files, +878 lines. No existing files are changed.
Checks (run locally):
python -m unittest discover -s testspasses 1086 tests (1052 before).coverage run -m unittest discoverpasses.black==26.5.1 . --checkis clean.Run:
cd examples && PYTHONPATH=.. python example-arbfeed.py # offline, sample data
Happy to drop the test file, trim the client, or move files if you'd prefer a different layout.