Skip to main content

Rapidly build & deploy cross-exchange trading bots

Project description



💨 Rapidly build and deploy quantitative models for stocks and crypto 🚀




Blankly is an elegant python library for interacting with many crypto and stock exchanges for automated portfolios in a consistent way. Blankly offers a powerful feature-set, optimized for speed and ease of use.

We're bridging the gap between local development systems & live APIs by building a framework which allows backtesting, paper trading, sandbox testing, and live cross-exchange deployment without modifying a single line of trading logic.

Check out our website and our docs.

Getting Started

Installation

  1. First install Blankly using pip. Blankly is hosted on PyPi.
$ pip install blankly
  1. Next, just run:
$ blankly init

This will run our setup script in the current terminal working directory. The command will create the files keys.json, settings.json, backtest.json, deploy.json and an example script called bot.py.

  1. From there, insert your API keys from your exchange into the generated keys.json file.

More information can be found on our docs

Directory format

The working directory format should have at least these files:

Project
   |-bot.py
   |-keys.json
   |-settings.json

If you don't want to use our init command, you can find the same files in the examples folder under settings.json and keys.json

Additional Info

Make sure you're using a supported version of python. The module is currently tested on these versions:

  • Python 3.7+

For more info, and ways to do more advanced things, check out our getting started docs.

Example Use

We have a pre-built cookbook examples that implement strategies such as RSI, MACD, and the Golden Cross found in our examples.

We have made Blankly extremely easy to integrate with any existing models and price events to make it super easy to switch.

import blankly
from blankly import StrategyState


def price_event(price, symbol, state: StrategyState):
    """ This function will give an updated price every 15 seconds from our definition below """
    state.variables['history'].append(price)
    rsi = blankly.indicators.rsi(state.variables['history'])
    if rsi[-1] < 30:
        # Dollar cost average buy
        state.interface.market_order(symbol, side='buy', funds=10)
    elif rsi[-1] > 70:
        # Dollar cost average sell
        state.interface.market_order(symbol, side='sell', funds=10)


def init(symbol, state: StrategyState):
    # Download price data to give context to the algo
    state.variables['history'] = state.interface.history(symbol, to='1y', return_as='list')['open']


if __name__ == "__main__":
    # Authenticate coinbase pro strategy
    coinbase_pro = blankly.CoinbasePro()

    # Use our strategy helper on coinbase pro
    coinbase_strategy = blankly.Strategy(coinbase_pro)

    # Run the price event function every time we check for a new price - by default that is 15 seconds
    coinbase_strategy.add_price_event(price_event, symbol='BTC-USD', resolution='30m', init=init)

    # Start the strategy. This will begin each of the price event ticks
    coinbase_strategy.start()
    # Or backtest using this
    # coinbase_strategy.backtest(to='1y', initial_values={'USD': 100000, 'BTC': 2})

Supported Exchanges

Exchange REST Support Ticker Websocket Order Book Interface
Coinbase Pro 🟢 🟢 🟢 🟢
Binance 🟢 🟢 🟢 🟢
Alpaca 🟢 🟢 🟢 🟢
OANDA 🟡 🟡 🟡 🟡

🟢 = working

🟡 = in development, some or most features are working

🔴 = planned but not yet in development

  • Interface calls take ~300 µs extra to homogenize the exchange data.

Bugs

Please report any bugs or issues on the GitHub's Issues page.

Disclaimer

Trading is risky. We are not responsible for losses incurred using this software, software fitness for any particular purpose, or responsibility for any issues or bugs. This is free software.

Contributing

If you would like to support the project, pull requests are welcome. You can also contribute just by telling us what you think of Blankly: https://forms.gle/4oAjG9MKRTYKX2hP9

Licensing

Blankly is distributed under the LGPL License. See the LICENSE for more details.

New updates every day 💪.

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

blankly-1.7.0b0.tar.gz (111.4 kB view hashes)

Uploaded Source

Built Distribution

blankly-1.7.0b0-py3-none-any.whl (185.1 kB view hashes)

Uploaded Python 3

Supported by

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