All Projects → arthurk → bitfinex-ohlc-import

arthurk / bitfinex-ohlc-import

Licence: MIT License
Imports historical OHLC data from Bitfinex

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to bitfinex-ohlc-import

dukascopy-tools
✨ Download historical price tick data for Crypto, Stocks, ETFs, CFDs, Forex via CLI and Node.js ✨
Stars: ✭ 128 (+374.07%)
Mutual labels:  trading, backtesting, ohlc
TAcharts
Apply popular TA tools and charts to candlestick data with NumPy.
Stars: ✭ 131 (+385.19%)
Mutual labels:  trading, backtesting, ohlc
gdax-ohlc-import
Import historical OHLC data from GDAX
Stars: ✭ 26 (-3.7%)
Mutual labels:  trading, backtesting, ohlc
awesome-tradingview
Curated list of noteworthy TradingView Strategies, Indicators and Alert Scripts for Trading Bots (PineScript)
Stars: ✭ 173 (+540.74%)
Mutual labels:  trading, backtesting
ml monorepo
super-monorepo for machine learning and algorithmic trading
Stars: ✭ 43 (+59.26%)
Mutual labels:  trading, ohlc
Cryptotrader
A responsive dynamic webapp to trade cryptopairs on the most prominent exchanges
Stars: ✭ 118 (+337.04%)
Mutual labels:  trading, bitfinex
binance-downloader
Python tool to download Binance Candlestick (k-line) data from REST API
Stars: ✭ 44 (+62.96%)
Mutual labels:  trading, backtesting
gym-mtsim
A general-purpose, flexible, and easy-to-use simulator alongside an OpenAI Gym trading environment for MetaTrader 5 trading platform (Approved by OpenAI Gym)
Stars: ✭ 196 (+625.93%)
Mutual labels:  trading, backtesting
SierraChartZorroPlugin
A Zorro broker API plugin for Sierra Chart, written in Win32 C++.
Stars: ✭ 22 (-18.52%)
Mutual labels:  trading, backtesting
autoxd
A股回测框架, 模拟实盘账户交易, 适合编写T+0策略
Stars: ✭ 71 (+162.96%)
Mutual labels:  trading, backtesting
roq-samples
How to use the Roq C++20 API for Live Cryptocurrency Algorithmic and High-Frequency Trading as well as for Back-Testing and Historical Simulation
Stars: ✭ 119 (+340.74%)
Mutual labels:  trading, backtesting
TradeBot
Crypto trading bot using Binance API (Java)
Stars: ✭ 292 (+981.48%)
Mutual labels:  trading, backtesting
Crypto Trading Bot
Cryptocurrency trading bot in javascript for Bitfinex, Bitmex, Binance, FTX, Bybit ... (public edition)
Stars: ✭ 1,089 (+3933.33%)
Mutual labels:  trading, bitfinex
Trading Indicator
provide trading technical indicator values based on data of almost crypto currency exchanges
Stars: ✭ 31 (+14.81%)
Mutual labels:  trading, bitfinex
Krypto Trading Bot
Self-hosted crypto trading bot (automated high frequency market making) written in C++
Stars: ✭ 2,589 (+9488.89%)
Mutual labels:  trading, bitfinex
Coinbase Pro Trading Toolkit
DEPRECATED — The Coinbase Pro trading toolkit
Stars: ✭ 817 (+2925.93%)
Mutual labels:  trading, bitfinex
Backtrader
Python Backtesting library for trading strategies
Stars: ✭ 7,846 (+28959.26%)
Mutual labels:  trading, backtesting
Stocksharp
Algorithmic trading and quantitative trading open source platform to develop trading robots (stock markets, forex, crypto, bitcoins, and options).
Stars: ✭ 4,601 (+16940.74%)
Mutual labels:  trading, backtesting
Cryptofeed
Cryptocurrency Exchange Websocket Data Feed Handler
Stars: ✭ 643 (+2281.48%)
Mutual labels:  trading, bitfinex
backtrader template
Basic template for managing Backtrader backtests.
Stars: ✭ 131 (+385.19%)
Mutual labels:  trading, backtesting

bitfinex-ohlc-import

A script that imports all historical OHLC data from the Bitfinex API and stores it in a local database.

The data has a 1-minute interval and can be used to carry out further in-depth analysis of market trends or backtest trading bots.

All currently traded symbols (e.g. BTC-USD, ETH-USD, ...) are supported (check symbols.json for a list of them). The import will begin from the earliest trading date (defined in symbols_trading_start_days.json). The script can be invoked periodically (for example with a cronjob) to fetch the latest data. It will automatically resume from the latest saved date.

API rate limits are respected and will not be exceeded. The script will re-try fetching with an incremental backoff time and continue to the next symbol after 3 failed attempts.

Experimental support for the Websocket API is also available. It currently subscribes to all trading updates (buy/sell) but does not store that data.

Installation

The script can be run in a virtualenv (via pipenv) or by using the Docker. For local development the virtualenv is recommended. For production deployments the Docker image is recommended.

virtualenv (pipenv)

You need the sqlite3 library installed on your system. On macOS you can use homebrew: brew install sqlite3.

To install the development environment, clone the repo and run:

$ pipenv install --dev

The --dev flag will install development tools such as py.test.

Docker

You can build the Docker image with:

$ docker build -t bitfinex .

The Docker image will not install development tools such as py.test.

Usage

You can run the script with the following command:

$ pipenv run python bitfinex/main.py --debug

Or if you prefer Docker:

$ docker run --rm bitfinex python bitfinex/main.py --debug

The --debug flag will print detailed information for each request/response, which is very useful for debugging.

$ pipenv run python bitfinex/main.py --debug
2018-04-22 20:48:49,326 INFO     Found 105 symbols
2018-04-22 20:48:49,326 DEBUG    Found previous db entries. Resuming from latest
2018-04-22 20:48:49,327 INFO     1/105 | btcusd | Processing from 2013-04-20 02:59:00
2018-04-22 20:48:49,328 DEBUG    2013-04-20T02:59:00+00:00 -> 2013-04-20T19:39:00+00:00
2018-04-22 20:48:49,399 DEBUG    Starting new HTTPS connection (1): api.bitfinex.com
2018-04-22 20:48:49,624 DEBUG    https://api.bitfinex.com:443 "GET /v2/candles/trade:1m:tBTCUSD/hist?start=1366426740000&end=1366486740000&limit=1000 HTTP/1.1" 200 None
2018-04-22 20:48:49,633 DEBUG    Fetched 288 candles

The script will import OHLC data for all symbols defined in the symbols.json file. If the import is started for the first time, the date defined in symbols_trading_start_days.json will be used as a starting point. Otherwise the database is queried for the last date and the import will continue from there on.

The data is saved in a file called bitfinex.sqlite3 in the same directory as the script. You can change it by passing it as an argument:

$ pipenv run python bitfinex/main.py /path/to/my/db.sqlite3

Database schema

The data is stored in a Sqlite3 database and has a "candles" table with the following structure:

symbol (the trading symbol e.g. btcusd)
time (time in unix timestamp with milliseconds added)
open
close
high
low
volume

Example output:

$ sqlite3 bitfinex.sqlite3
sqlite> select * from candles;
btcusd|1366366980000|122.7|122.4|122.7|122.4|1
btcusd|1366366920000|123.2|122.7|123.2|122.7|82.9
btcusd|1366366800000|123.7|123.7|123.7|123.7|1.1

Export to CSV

The data can easily be exported to CSV:

$ sqlite3 bitfinex.sqlite3
sqlite> .headers on
sqlite> .mode csv
sqlite> .output data.csv
sqlite> SELECT * FROM candles;
sqlite> .quit

The data will be in a file called data.csv.

Testing

You need to have development dependencies installed (pipenv install --dev).

The tests are stored in the tests directory and can be run with py.test:

$ pipenv run py.test tests/
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].