Giter Site home page Giter Site logo

ridekind / binance-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lexglu/binance-api

0.0 0.0 0.0 152 KB

Automated tool to collect candlestick data by symbol and interval from Binance API. Data visualisation UI with plotly

Shell 1.88% Python 85.70% HTML 9.59% Dockerfile 2.83%

binance-api's Introduction

Task description

Task 1

Write a script to collect data from Binance API for provided interval (can be 1d, 4h, 1h) and for provided symbol (BTCUSDT, ETHUSDT, etc.). Suggest a method of deploying such a script to collect relevant data in the interval of your choice (every 1D, 4H, 1H). Save data in csv format. Suggest format of saving data in a relational database.

Task 2

Write a simple Flask UI, which will display a page with candlestick data from task 1, using plotly as a module for output (since it works dynamically using js), and a piechart of market caps for 10 symbols of your choice.

Deployment

To run both scripts, you need to have Docker and Docker Compose installed on your machine. You can check if you have them installed by running the following commands:

docker -v
docker-compose -v

If you don't have them installed, please follow the instructions on the official Docker website: https://docs.docker.com/get-docker/

To run the solution, please follow the steps below:

  1. Clone the repository to your machine:
git clone https://github.com/LexGlu/binance-api.git
  1. Go to the project directory:
cd binance-api
  1. Create a config.py file in the app directory and add the API key from CoinMarketCap to it. You can get the API key from the official CoinMarketCap website: https://coinmarketcap.com/api/ (free plan is enough for this task). The file should look like this:
api_key='your_API_key'
  1. Run the following command:
docker-compose up -d
  1. Wait for the containers to be built and started. Please note that Python script get_kline_data.py will run on startup (to collect sample data from Binance API). You can check the status of the containers with the following command:
docker-compose ps
  1. When the containers are up and running, you can check Flask UI, which will display a page with candlesticks data and a piechart of market caps for top 10 tokens. It is available at http://localhost:8000. Pie chart is updated in a mock real-time mode (every 30 seconds for demonstration purposes). It is implemented using websockets (Flask-SocketIO library).

  2. You can check the data in the database using GUI for the database. It is available at http://localhost:8080. You can use credentials from the file .env to login to the database and check the data.

  3. To stop the containers, run the following command:

docker-compose down -v # -v flag is used to remove volumes as well (database data)

Solution description

Task 1

The script get_kline_data.py uses Binance API endpoint (https://api.binance.com/api/v3/klines) to collect data for provided interval and symbol. It saves the data in csv format and also saves it in the database (PostgreSQL). The database credentials are stored in the .env file and it runs in a separate container (see docker-compose.yml).

The script will run every hour using cron job. The cron job is defined in the crontab file.

Detailed logs are stored in the logs.txt file. Also logs of cron jobs are stored in the cron.log file.

The database schema is as follows:

  • 'open_time' - timestamp of the start of the candlestick (timestamp)
  • 'open_price' - price at the start of the candlestick (float)
  • 'high_price' - highest price during the candlestick (float)
  • 'low_price' - lowest price during the candlestick (float)
  • 'close_price' - price at the end of the candlestick (float)
  • 'volume' - volume during the candlestick (float)
  • 'close_time' - timestamp of the end of the candlestick (timestamp)
  • 'quote_asset_volume' - volume of the quote asset during the candlestick (float)
  • 'number_of_trades' - number of trades during the candlestick (int)
  • 'taker_buy_base_asset_volume' - volume of the base asset bought by taker during the candlestick (float)
  • 'taker_buy_quote_asset_volume' - volume of the quote asset bought by taker during the candlestick (float)

Task 2

The Flask UI is implemented in app.py. It uses the data from the database to display candlesticks. The candlesticks and piechart are implemented using plotly library. The UI is available at http://localhost:8000 (several charts are available, you can switch between them using the list in the top left corner). Gunicorn is used as a WSGI HTTP Server.

image1

binance-api's People

Contributors

lexglu 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.