Skip to main content

Basic crypto trading API for developing trading bots with transparent access to Coinbase Pro, Binance, Kraken, and Bitfinex

Project description

Writing your own crypto-trade bot is easy now!

cryptrade is a project that offers a a high level abstraction of a crypto-currency trade API. It offers classes for:

  • Accounts, holding both fiat currency (EUR, USD, etc) as well as crypto currencies (BTH, ETH, etc)
  • Products, representing what you can actually trade on a crypto exchange, eg. BTC-EUR (buy BTC pay in EUR) or ETH-BTC (buy ETH pay in BTC)
  • Currencies, representing fiat and crypro currencies and their IDs used by exchanges
  • Orders, the actual trade (buying or selling) of crypto currency
  • Tickers, providing 'real-time' info on market-price and bid/ask prices

The (abstract) exchange interfaces provide the basic validations needed to successfully trade on an online exchange, make the necessary API calls, and handle the responses. To make the underlying exchange transparent, the API is provided using an Abstract Factory pattern.

On top of this, classes are provided for:

  • Ticker, Account, and Order monitoring (implemented using the Observer pattern)
  • Transactions, representing the total of buying/selling transactions
  • Logger, providing logging classes for logging to console, file, and through PushBullet. These classes are implemented as Singletons.

At this moment, the following crypto exchanges are supported:

The interfaces can be used in a synchronous manner, however they also include asynchronous interfaces so it is possible to make use of the asyncio package for cooperative multitasking using an event-loop.

Two sample programs are included:

  • cryptrade.py, a sample program that shows the usage of this package. It's operation can be directed using commandline parameters. It will trade according a very simple algorithm.
usage: cryptrade.py [-h] [-c {eur,btc}] [-d TRADE_DELTA] [-a TRADE_AMOUNT]
                    exchange currency

positional arguments:
  exchange              Exchange to trade on. Currently supported: coinbase,
                        binance, kraken, bitfinex
  currency              Currency to trade in: btc, eth, xrp, ltc, bch, ...

optional arguments:
  -h, --help            show this help message and exit
  -c CURRENCY, --currency CURRENCY
                        (Crypto) currency to use for buying.
  -d TRADE_DELTA, --delta TRADE_DELTA
                        Percentage (0.0 < trade < 100.0) by which market price
                        should change before making a trade (accepts
                        fractional numbers).
  -a TRADE_AMOUNT, --amount TRADE_AMOUNT
                        Initial amount to start trading with (btc>=0.001,
                        eth>=0.01, xrp>=1, ltc=0.1).
  • tickermonitor.py, shows how the asynchronous interfaces can be used by implementing a tickermonitor for all supported exchanges in parallel.

Make sure you provide your credentials (API key & secret) before using it. They should be stored in a json file like:

{
    "coinbase" : 
     {
        "api_key" : "your api key",
        "api_secret" : "your api secret",
        "api_pass" : "you api password"
    },
    "binance" :
    {
        "api_key" : "your api key",
        "api_secret" : "your api secret"
    },
    "kraken" :
    {
        "api_key" : "your api key",
        "api_secret" : "your api secret"
    },
    "bitfinex" :
    {
        "api_key" : "your api key",
        "api_secret" : "your api secret"
    },
    "pushbullet" :
    {
        "api_key" : "your api key"
    }
}

The cryptrade module contains the following packages:

  • logging (logging interfaces)
  • parameters (interfaces for dealing with -commandline- parameters)
  • exceptions (containing module-specific exceptions)
  • observers (containing base classes for observables and observers)
  • exchange_api (containing the abstract interface for trading)
  • monitor (containing monitoring classes using asyncio)
  • binance (containing concrete implementation for Binance)
  • bitfinex (containing concrete implementation for Bitfinex)
  • kraken (containing concrete implementation for Kraken)
  • coinbase (containing concrete implementation for Coinbase Pro)

This project uses the official python interface for binance.com as well as the 'unofficial' python interface for Coinbase Pro by Daniel Paquin, the official python interface for Kraken.com, and the official python interface from bitfinex.com.

Special requests or questions: send me a message!

Want to stimulate the ongoing development? Your BTCs are welcome! Send them to bitcoin:15pqCjD7pPPraGJ8T4yfbkrtFTBX8M4jyw

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cryptrade-1.103.tar.gz (13.9 kB view hashes)

Uploaded Source

Built Distribution

cryptrade-1.103-py3-none-any.whl (17.9 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