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

This version

1.1

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.tar.gz (47.2 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-py3-none-any.whl (78.1 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for investing_algorithm_framework-1.1.tar.gz
Algorithm Hash digest
SHA256 d006cd0998dab0c7ce4ad2ad1b4554ada453c467eb3ed2b2d08bc7f819396dc7
MD5 78cc2a0ba0c838b0b6e9d4ae4920e440
BLAKE2b-256 e7b0369b4281e7096865fc96967251e30e7161448ebb53eba6d994c57ac402b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for investing_algorithm_framework-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ab674ee9540a7783d53dea72fd11c5bcb0d8f046fe1e25e1fd0da693de48662e
MD5 e70768869cd808eaebc4e20d610a9867
BLAKE2b-256 922448a0252f62317440f1ba44a376b55b045234b49ab117be38bf6322b25aeb

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