CryptoLion back-testing library
Project description
CryptoLion
CryptoLion is a lightweight Python library for backtesting and running cryptocurrency trading strategies locally.
Installation
Build and publish a new release:
# Clean previous builds
tm rm -rf build/ dist/
# Build distributions
tm python -m build
# (Optional) Upload to TestPyPI for testing
tm twine upload --repository testpypi dist/*
# Publish to PyPI
export TWINE_USERNAME="__token__"
export TWINE_PASSWORD="<your-pypi-token>"
tm twine upload dist/*
Data Acquisition
Load your own OHLCV data into a pandas DataFrame with a datetime index and a close column. Examples:
Binance (python-binance)
from binance.client import Client
import pandas as pd
client = Client(api_key, api_secret)
klines = client.get_historical_klines(
"BTCUSDT", Client.KLINE_INTERVAL_1DAY,
"1 Jan 2020", "1 Jan 2021"
)
df = pd.DataFrame(klines, columns=[
"open_time", "open", "high", "low", "close", "volume",
"close_time", "quote_asset_volume", "num_trades",
"taker_buy_base_asset_volume", "taker_buy_quote_asset_volume", "ignore"
])
df["Date"] = pd.to_datetime(df["open_time"], unit="ms")
df.set_index("Date", inplace=True)
data = df[["close", "volume"]].astype(float)
Yahoo Finance (yfinance)
import yfinance as yf
data = yf.download("BTC-USD", start="2020-01-01", end="2021-01-01")
Quickstart Example
import pandas as pd
from cryptolion.strategies.ultra import MACrossoverStrategy
from cryptolion.engine import StrategyEngine
# Load OHLCV data (datetime index with 'close' column)
# e.g. data = pd.read_csv('data/BTC_USD.csv', parse_dates=['Date'], index_col='Date')
data = pd.read_csv('data/BTC_USD.csv', parse_dates=['Date'], index_col='Date')
# Initialize engine and run backtest
en = StrategyEngine()
en.run(data, strategy=MACrossoverStrategy(fast=10, slow=50), fee=0.001)
# Retrieve equity curve
equity = en.equity
# Display results
print(equity)
print(equity.describe())
Bumping Version (v0.1.2)
-
Update version in:
pyproject.tomlsrc/cryptolion/__init__.pyset to0.1.2.
-
Commit & tag:
git add pyproject.toml src/cryptolion/__init__.py git commit -m "chore: bump version to v0.1.2" git tag v0.1.2 git push origin main --tags
-
Build & publish:
rm -rf build/ dist/ python -m build export TWINE_USERNAME="__token__" export TWINE_PASSWORD="<your-pypi-token>" twine upload dist/*
-
Verify on PyPI:
Publishing Troubleshooting
"HTTPError: 403 Forbidden – Invalid or non‑existent authentication information"
-
New token, correct scope: Generate a fresh Publish projects API token on PyPI (it will start with
pypi-). Delete or revoke old ones. -
Separate exports: In Bash/Z‑sh put each export on its own line or separate with
;— for example:export TWINE_USERNAME="__token__" export TWINE_PASSWORD="pypi-XXXXXXXXXXXX"
-
No angle‑brackets or extra quotes around the token.
-
Verify variables are set:
echo $TWINE_USERNAME; echo ${#TWINE_PASSWORD}(should print__token__and a non‑zero length). -
No duplicate version: A 400 with File already exists means that exact version is already on PyPI — bump
versionin bothpyproject.tomlandsrc/cryptolion/__init__.py. -
No inline
#comments on the same line as thetwine uploadcommand. Place comments on a new line (or escape the#) so they aren’t treated as part of the filename pattern. -
Separate token for Test PyPI: the production token from pypi.org will not work on test.pypi.org. Log in to https://test.pypi.org/manage/account/, create a new API token, and export it as
TWINE_PASSWORDwhen you upload to Test PyPI. -
Test first:
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
If TestPyPI succeeds, the credentials are fine.
Persistent credentials via ~/.pypirc
Instead of exporting TWINE_USERNAME and TWINE_PASSWORD every time you publish, create a config file in your home directory:
[pypi]
username = __token__
password = pypi-<your-production-token>
[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__
password = pypi-<your-testpypi-token>
Security tip: keep this file private —
chmod 600 ~/.pypirc— and never commit real tokens to version control or chat.
With this file in place you can simply run:
python -m build
# Test upload first
twine upload --repository testpypi dist/*
# Then production
twine upload dist/*
Contributing
For bug reports or feature requests, please open an issue on GitHub:
https://github.com/phoenixsenses/cryptolion
Pull requests are welcome!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cryptolion-0.1.2.tar.gz.
File metadata
- Download URL: cryptolion-0.1.2.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d386465fed91ac38590a81f7ed2eb5d557216fd4a4c528b153bde03176dec26
|
|
| MD5 |
b4a8b009fde1075072a1908842f806a0
|
|
| BLAKE2b-256 |
a2e0d1e24ec9eefe7faf1679d9b33b963fccfde0bf8243e6b26696c22374cff5
|
File details
Details for the file cryptolion-0.1.2-py3-none-any.whl.
File metadata
- Download URL: cryptolion-0.1.2-py3-none-any.whl
- Upload date:
- Size: 27.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd1134a392c5eb9f62dd421c9b42c25095f0e6d00d4ac27ca4fb3ebad2eaaa5b
|
|
| MD5 |
306082e3c8887b031dd8d4772dd39d00
|
|
| BLAKE2b-256 |
79b40bbd76311b1b3f83ced79c43b0bad05a2fbdbd172edf6b203864ca03190a
|