Skip to main content

A framework for creating an investment algorithm

Project description

Build Tests Downloads Current Version

Sponsors

logicfunds

Investing Algorithm Framework

The Investing Algorithm Framework is a python framework for building investment algorithms. It encourages rapid development and clean, pragmatic code design.

The framework provides you with all the components you need to create an investing algorithm (data providing, portfolio management, order execution, etc..). Also, it has various deployment options, such as web server, stateless, etc..

Example

The following algorithm connects to binance and buys BTC every 5 seconds. It also exposes an REST API that allows you to interact with the algorithm.

import pathlib
from datetime import datetime, timedelta

from investing_algorithm_framework import create_app, PortfolioConfiguration, \
    RESOURCE_DIRECTORY, TimeUnit, TradingTimeFrame, TradingDataType, OrderSide

app = create_app({RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()})
app.add_portfolio_configuration(
    PortfolioConfiguration(
        market="binance",
        api_key="xxxxxx",
        secret_key="xxxxxx",
        trading_symbol="USDT"
    )
)


@app.strategy(
    time_unit=TimeUnit.SECOND, # Algorithm will be executed every 5 seconds
    interval=5,
    market="binance", # Will retrieve trading data from binance
    symbols=["BTC/USDT", "ETH/USDT", ["DOT/USDT"]], # Symbols must be in the format of TARGET/TRADE symbol (e.g. BTC/USDT)
    trading_data_types=[TradingDataType.OHLCV, TradingDataType.TICKER, TradingDataType.ORDER_BOOK],
    trading_time_frame_start_date=datetime.utcnow() - timedelta(days=1), # Will retrieve data from the last 24 hours
    trading_time_frame=TradingTimeFrame.ONE_MINUTE # Will retrieve data on 1m interval (OHLCV)
)
def perform_strategy(algorithm, market_data):
    print(algorithm.get_allocated())
    print(algorithm.get_unallocated())
    print(market_data)
    algorithm.create_limit_order(
        target_symbol="BTC", 
        side=OrderSide.BUY,
        price=market_data["TICKER"]["BTC/USDT"]["BID"], 
        amount_target_symbol=0.00001
    )


if __name__ == "__main__":
    app.run()

You can find more examples here folder.

Broker/Exchange configuration

The framework has by default support for ccxt. This should allow you to connect to a lot of brokers/exchanges.

from investing_algorithm_framework import App, PortfolioConfiguration
app = App()
app.add_portfolio_configuration(
    PortfolioConfiguration(
        market="bitvavo", 
        api_key="xxxx", 
        secret_key="xxxx", 
        track_from="01/01/2022",
        trading_symbol="EUR"
    )
)

Download

You can download the framework with pypi.

pip install investing-algorithm-framework

Disclaimer

If you use this framework for your investments, do not risk money which you are afraid to lose, until you have clear understanding how the framework works. We can't stress this enough:

BEFORE YOU START USING MONEY WITH THE FRAMEWORK, MAKE SURE THAT YOU TESTED YOUR COMPONENTS THOROUGHLY. USE THE SOFTWARE AT YOUR OWN RISK. THE AUTHORS AND ALL AFFILIATES ASSUME NO RESPONSIBILITY FOR YOUR INVESTMENT RESULTS.

Also, make sure that you read the source code of any plugin you use or implementation of an algorithm made with this framework.

For further information regarding usage and licensing we recommend going to the licensing page at the website.

Documentation

All the documentation can be found online at the documentation webstie

In most cases, you'll probably never have to change code on this repo directly if you are building your algorithm/bot. But if you do, check out the contributing page at the website.

If you'd like to chat with investing-algorithm-framework users and developers, join us on Slack or join us on reddit

Acknowledgements

We want to thank all contributors to this project. A full list of all the people that contributed to the project can be found here

Bugs / Issues

If you discover a bug in the framework, please search our issue tracker first. If it hasn't been reported, please create a new issue.

Feel like the framework is missing a feature? We welcome your pull requests!

Note before starting any major new feature work, please open an issue describing what you are planning to do. This will ensure that interested parties can give valuable feedback on the feature, and let others know that you are working on it.

Important: Always create your feature or hotfix against the develop branch, not master.

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

investing_algorithm_framework-1.1.2.tar.gz (47.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

investing_algorithm_framework-1.1.2-py3-none-any.whl (78.2 kB view details)

Uploaded Python 3

File details

Details for the file investing_algorithm_framework-1.1.2.tar.gz.

File metadata

File hashes

Hashes for investing_algorithm_framework-1.1.2.tar.gz
Algorithm Hash digest
SHA256 97391584c8564b3b8b962b678105617bc8de07346670caca875c1eee96560783
MD5 6e405dad3d3ab348a8d5a58eb1394a21
BLAKE2b-256 72521b59aeaa738e6c9e1685d3e0d9f39de56b6afc189265c7e31fa163ca9983

See more details on using hashes here.

File details

Details for the file investing_algorithm_framework-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for investing_algorithm_framework-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 335af7f907e35219a76de52dcc9e947e3fb0bffa66b29e5100a7ad1285695722
MD5 4ca012d8415f8738aa592655f7e317be
BLAKE2b-256 f5c58264ca7e71dc3fc7e261880dc14064a632cfebe1df41f95653fc33d3534e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page