while25
Write your own trading strategies, chart indicators and dashboards in plain Python, and run them inside the While25 trading platform.
What you can build
| What it is | Example | |
|---|---|---|
| Strategy | Code that places orders when your rules say so | Buy when the price closes above last month's high |
| Indicator | A line, histogram or zone drawn on the chart | Your own moving average or oscillator |
| Monitor | Code that watches the market and alerts you | Tell me when my stock falls 3% in a day |
| App | A panel of your own in the platform | A dashboard of your positions and P&L |
You write a Python class. While25 feeds it prices, sends its orders to your broker, and draws what it produces.
Install
pip install while25
Python 3.11 or newer. The package has no dependencies, so you can write and test your code on any computer. To run it against live markets, use the While25 desktop app.
A strategy in 10 lines
import while25
from while25 import Strategy, on
class BuyTheDip(Strategy):
id = "buy_the_dip"
label = "Buy the dip"
@on.bar("EQ:US:AAPL", "1D") # runs once a day, when the bar closes
def on_day(self, ctx, bar):
if bar["close"] < bar["open"] * 0.97: # fell 3% today
while25.buy("EQ:US:AAPL", 10)
Open the Code Editor in While25, paste it, and press Run. The platform shows the strategy as armed and lists every order it sends.
An indicator
import math
import while25
from while25 import Indicator, Plot
from while25.inputs import Int
class MyAverage(Indicator):
id = "my_average"
label = "My average"
overlay = True # draw it on the price chart
inputs = [Int("length", default=20, minimum=2)] # the user can change it
plots = [Plot("avg", color="#e0a34a", width=2)]
warmup = 20
def compute(self, ctx):
n = while25.params["length"]
closes = [r["close"] for r in while25.bars]
self.times = [r["time"] for r in while25.bars]
avg = [math.nan] * len(closes)
for i in range(n - 1, len(closes)):
avg[i] = sum(closes[i - n + 1:i + 1]) / n
return {"avg": avg}
Run it once in the Code Editor and it appears in the chart's indicator menu, with its settings in the same dialog as the built-in indicators.
Test it without the platform
Your strategy is an ordinary class, so pytest can run it. while25.use()
swaps the platform for a fake you control:
import while25
def test_it_buys_after_a_big_fall():
sent = []
class FakeOrders:
def buy(self, symbol, qty, **kw): sent.append((symbol, qty))
class FakePlatform:
params = {}
orders = FakeOrders()
fake = FakePlatform()
with while25.use(fake):
BuyTheDip().on_day(fake, {"open": 100.0, "close": 95.0})
assert sent == [("EQ:US:AAPL", 10)]
Learn more
The guide covers everything, one topic at a time:
- When your code runs: every tick, each closed bar, on a timer, on news
- Market data: history, live prices, news, index members
- Orders: market, limit, stop, bracket and trailing orders
- Positions and funds
- Options, combos and futures
- Indicators and monitors, including asking the AI
- Panels and dashboards
- Backtests, and backtesting without peeking ahead
- Limits and what the SDK does not do
Ready-to-run code is in examples/.
Contributing
Bug reports and ideas are welcome in Issues. Run the tests with:
pip install -r requirements-dev.txt
pytest
License
Metadata
Release files for while25 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| while25-0.1.1.tar.gz | 452.9 kB | Without provenance | Details for while25-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| while25-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for while25-0.1.1-py3-none-any.whl |
Total release size: 881.5 kB
Release files / while25-0.1.1.tar.gz
| Download URL | while25-0.1.1.tar.gz |
|---|---|
| Size | 452.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bbd76e108530a068936e7e5ce1c9c2e477e55be4b78bdc6b04583f723b32dfc4
|
|
BLAKE2b-256 checksum How to use checksums |
4747e6119da1e9cec02b9f53b983c221901882af1d148bc76f94c439d8fe0794
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.0
|
Release files / while25-0.1.1-py3-none-any.whl
| Download URL | while25-0.1.1-py3-none-any.whl |
|---|---|
| Size | 428.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f0f31f2e3dd9a2955483e5677c480355776b7e04abc09c688d9efcef9f48abcf
|
|
BLAKE2b-256 checksum How to use checksums |
df707689506cdce97a2ef8702da971383f6d8e22941be644fef44dad9843fac9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.0
|
Security for while25 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.