Giter Site home page Giter Site logo

crypto_bot's Introduction

Crypto Bot

Simple bot to automate crypto trades. Has full account integration via the Coinbase Pro API, with the ability to track account balances and place trades via a Coinbase Pro API key. Market data is managed with numpy and pandas, and requests is used to send HTTP requests to the API. Unit tests implemented using pytest and requests-mock. API keys managed using dotenv.

Disclaimer

This project is for educational purposes, and I am not responsible for any financial losses incurred during use of this bot.

Installation

This project uses pip and setuptools for package management. To install, first clone the repository. If you do not have pip, you must first install it (see instructions here). Setup.py defines an installation routine for the crypto-bot package. Initialize it by running pip install -e .. This will additionally install the latest version of all required libraries. If you wish to download a more strictly versioned set of dependencies (i.e. for production purposes), you can run pip install -r requirements.txt.

Usage

After installing the crypto-bot package, you must create an account and API key via the Coinbase Pro UI. I would recommend creating a sandbox API key first, for testing and demo purposes. Next, create a .env file with 3 line-separated environment variables (API_SECRET, API_KEY, API_PASS) declared as follows: API_SECRET=XXX.

The bot script command executed in the root directory will start running the trading bot. The bot will continue indefinitely until manually stopped. There is limited UI feedback provided via terminal to track the bot's activity.

In order to switch from the Coinbase Pro sandbox environment to the production environment, change the api_url constant in the bot/__main__.py file. The time.sleep statement at the bottom of that file determines how often market data is pulled from the API. It is currently configured to poll the API every second to allow for expedited debugging, but you may want to increase the interval for a more realistic trading experience.

Analysis

The bot's trading strategy revolves around the MACD indicator, which consists of the MACD line (difference between the 12 and 26 day price EMA) and a signal line (9 day EMA of the MACD line). When the MACD crosses above the signal line, the bot will attempt to open a long position in DOGE. When the MACD crosses below the signal and DOGE is currently held, the bot will attempt to sell all held DOGE as long as the current bid price is above the cost basis + fees. By doing this, the bot should theoretically never sell at a loss. In order to test this strategy, I created a simplified implementation that manipulated DOGEEUR 1 minute data from Feb 2020 to Feb 2021. Backtesting revealed an annualized return of about 444% for this time frame, but it should be noted that 2020 was certainly a bull market for crypto. Below is a visualization of this backtesting process created using matplotlib.

Backtesting

Testing

The package contains a set of unit tests for utility functions. In order to run them, use the pytest command in the root directory. These unit tests are not meant to be comprehensive, but test both successful and failing cases for most package utility functions.

License

Licensed under MIT license. Copyright (c) 2021 Christopher Nathan.

crypto_bot's People

Contributors

christophernathan avatar uzzysan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.