The Cryptofeed library is intended for use by Python developers.
You have several ways to get/use Cryptofeed:
- Pip -
pip install cryptofeed
- Git -
git clone https://github.com/bmoscon/cryptofeed
- Zipped source code - Download github.com/bmoscon/cryptofeed/archive/master.zip
- Pipenv
In the following chapters you will find further details on the use of Pip and Pipenv.
The safe way to install or upgrade the Cryptofeed library:
python3 -m pip install --user --upgrade cryptofeed
To minimize the number of dependencies to download, the dependencies required by the Rest API, and the cryptofeed backends are optional, but easy to install.
See the file setup.py
for the exhaustive list of these extra dependencies.
You can install Cryptofeed along with all optional dependencies in one bundle:
python3 -m pip install --user --upgrade cryptofeed[all]
Cryptofeed can also be used to access the Rest API of some crypto-exchange to retrieve historical market data and to place orders. See also the dedicated chapter Rest API.
python3 -m pip install --user --upgrade cryptofeed[rest_api]
To install Cryptofeed along with Arctic in one bundle:
python3 -m pip install --user --upgrade cryptofeed[arctic]
python3 -m pip install --user --upgrade cryptofeed[redis]
python3 -m pip install --user --upgrade cryptofeed[zmq]
python3 -m pip install --user --upgrade cryptofeed[zmq]
python3 -m pip install --user --upgrade cryptofeed[mongo]
python3 -m pip install --user --upgrade cryptofeed[postgres]
python3 -m pip install --user --upgrade cryptofeed[kafka]
The tool Pipenv allows the installation of
the Cryptofeed library and its dependencies
without affecting your daily Python environment.
Pipenv is based on pip
and virtualenv
.
You may want to install the latest versions of Pip and Pipenv on your user Python environment to limit conflicts with the operating system:
python3 -m pip install --user --upgrade pip
python3 -m pip install --user --upgrade pipenv
Once you have cloned/downloaded the Cryptofeed source code, you can install the dependencies within a dedicated Python virtual environment using the following command line:
cd your/path/to/cryptofeed
python3 -m pipenv install
Note: the default Pipfile
is configured to install all optional dependencies.
You may edit the Pipfile
to comment the optional dependencies you do not need.
Edit the Pipfile
and comment some (or all)
dependencies above the line # Optional dependencies
.
Then:
cd your/path/to/cryptofeed
python3 -m pipenv clean
You may also copy/hack that Pipfile
within your own project.
That Pipfile
is in the public domain to give you more freedom.
Note: See the LICENSE for the rest of the Cryptofeed files.
You can update the dependency versions once a week:
cd your/path/to/cryptofeed
python3 -m pipenv update
You can also check the entire dependency tree:
cd your/path/to/cryptofeed
python3 -m pipenv graph
In the following example we execute the script demo.py
:
cd your/path/to/cryptofeed
PYTONPATH=. python3 -m pipenv run python3 examples/demo.py
To use shorter command lines, you may want to enter in the sub-shell of the Python virtual environment:
cd your/path/to/cryptofeed
python3 -m pipenv shell
export PYTONPATH=$PWD
cd path/to/your/project
python your-awesome-script.py
[...]
exit # or [Ctrl] + [D]
Note: Remember that you are in a sub-shell of a virtual environment.
To leave this sub-shell, use the command exit
or the keyboard shortcut Ctrl + D.
The [dev-packages]
section (of the Pipfile
) lists
the Python packages used for the Cryptofeed development.
cd your/path/to/cryptofeed
python3 -m pipenv install --dev
Pytest is listed in the [dev-packages]
section with
pytest-asyncio
, a Pytest plugin allowing
to write unit tests for asyncio
functions.
Once the development dependencies are installed, perform the unit tests in the way you prefer:
-
Using a long Python command line:
cd your/path/to/cryptofeed python3 -m pipenv run python3 -m pytest tests
-
Entering the sub-shell of the virtual environment:
cd your/path/to/cryptofeed python3 -m pipenv shell pytest [...] exit # or [Ctrl] + [D]
The [dev-packages]
section of the Pipfile
also lists
Pylint with many plugins for relevant static code analysis.
This allows you to detect potential bugs and error-prone coding style.
cd your/path/to/cryptofeed
python3 -m pipenv run python3 -m pylint --output-format=colorized ./cryptofeed/exchange
You may want to reduce the number of reported issues
by disabling the minor/verbose ones with the --disable
option:
cd your/path/to/cryptofeed
python3 -m pipenv run python3 -m pylint --output-format=colorized --disable=C0111,C0301,C0103,R0903,R0913,R0912 ./cryptofeed/exchange
Parse two folders containing Python files:
cd your/path/to/cryptofeed
python3 -m pipenv run python3 -m pylint --output-format=colorized ./cryptofeed ./examples
Activate the Pylint plugins with the option --load-plugins
:
cd your/path/to/cryptofeed
export PYTONPATH=.
python3 -m pipenv run python3 -m pylint --verbose --output-format=colorized --load-plugins=pylint_topology,pylint_import_modules,pylint_google_style_guide_imports_enforcing,pylint_unittest,pylint_requests,pylint_args,string_spaces_checkers ./cryptofeed
When almost all reported issues are fixed,
you can speed up the Pylint processing with the option --jobs=8
.
Using this option when there are still many issues
may duplicate/mix the Pylint output.
One more thing: The [dev-packages]
section also lists the tool
isort
.
The following isort
options apply the same formatting as black
,
but only to the import
sections:
cd your/path/to/cryptofeed
python3 -m pipenv run python3 -m isort --jobs=8 --atomic --multi-line 3 --force-grid-wrap 0 --trailing-comma --use-parentheses --apply --recursive .
If you have a problem with the installation/hacking of Cryptofeed, you are welcome to open a new issue: https://github.com/bmoscon/cryptofeed/issues/ or join us on Slack: cryptofeed-dev.slack.com
Your Pull Requests are also welcome, even for minor changes.