Skip to main content

Build Status Coverage Status

Cryptocurrency Portfolio Balancer

USE AT YOUR OWN RISK. THIS TRADES REAL MONEY. NO WARRENTY IS GIVEN

A script that can connect to a cryptocurrency exchange and buy/sell cryptocurrency to keep your portfolio balancer to a certain ratio.

Install

$ virtualenv --python=python3 .
$ . bin/activate
$ pip install -r requirements.txt
$ pip install -e .

Config

Create a config file in config.ini with definition of your exchange and portfolio percentages, and theshold (percent) that rebalancing is needed:

[binance]
api_key = <api key>
api_secret = <api secret>
threshold = 2.0
targets = XRP 40
          BTC 20
	  ETH 20
	  BNB 10
	  USDT 10

By default it values the portfolio in USDT, this can be changed with --valuebase argument.

Running

Dry run (don't actually trade) against Binance

$ crypto_balancer binance
Connected to exchange: binance

Current Portfolio:
  XRP    3272.28  (39.92 / 40.00%)
  BTC    0.14     (20.05 / 20.00%)
  ETH    3.85     (20.02 / 20.00%)
  BNB    22.81    ( 9.99 / 10.00%)
  USDT   262.48   (10.02 / 10.00%)

  Total value: 2619.40 USDT
  Balance error: 0.043 / 0.08

No balancing needed

To force it to rebalance regardless of if needed:

$ crypto_balancer --force binance
Connected to exchange: binance

Current Portfolio:
  XRP    3272.28  (39.92 / 40.00%)
  BTC    0.14     (20.04 / 20.00%)
  ETH    3.85     (20.02 / 20.00%)
  BNB    22.81    ( 9.99 / 10.00%)
  USDT   262.48   (10.02 / 10.00%)

  Total value: 2619.28 USDT
  Balance error: 0.042 / 0.08

Balancing needed [FORCED]:

Proposed Portfolio:
  XRP    3278.51  (40.00 / 40.00%)
  BTC    0.14     (20.04 / 20.00%)
  ETH    3.83     (19.95 / 20.00%)
  BNB    22.81    ( 9.99 / 10.00%)
  USDT   262.48   (10.02 / 10.00%)

  Total value: 2619.28 USDT
  Balance error: 0.032
  Total fees to re-balance: 0.00199 USDT

Orders:
  BUY 6.2279674364331195 XRP/ETH @ 0.00234478

To get it to actually execute trades if needed:

$ crypto_balancer --force --trade binance
Connected to exchange: binance

Current Portfolio:
  XRP    3272.28  (39.96 / 40.00%)
  BTC    0.14     (20.04 / 20.00%)
  ETH    3.84     (19.94 / 20.00%)
  BNB    22.94    (10.04 / 10.00%)
  USDT   262.48   (10.02 / 10.00%)

  Total value: 2619.01 USDT
  Balance error: 0.043 / 0.08

Balancing needed [FORCED]:

Proposed Portfolio:
  XRP    3272.28  (39.96 / 40.00%)
  BTC    0.14     (20.04 / 20.00%)
  ETH    3.85     (20.00 / 20.00%)
  BNB    22.80    ( 9.98 / 10.00%)
  USDT   262.48   (10.02 / 10.00%)

  Total value: 2619.01 USDT
  Balance error: 0.031 / 0.08
  Total fees to re-balance: 0.001592 USDT

Orders:
  Submitted: sell 0.13 BNB/ETH @ 0.08422

Running automatically

You can set this to run in a cron job on a unix system by putting something along the lines of (adjust for your path and email address) below in your crontab file:

MAILTO=matt@example.com
*/5 * * * * OUTPUT=`cd /home/matt/crypto_balancer; bin/crypto_balancer --trade binance`; echo "$OUTPUT" | grep -q "No balancing needed" || echo "$OUTPUT"

This will run the script every 5 minutes, and will email you only if some balancing (or an error) occurs.

Metadata

Release files for crypto-balancer 3.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crypto-balancer 3.1.1
File Size Uploaded Provenance
crypto_balancer-3.1.1.tar.gz 12.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for crypto-balancer 3.1.1
File Interpreter ABI Platform
crypto_balancer-3.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 28.7 kB

Release files / crypto_balancer-3.1.1.tar.gz

Download URL crypto_balancer-3.1.1.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e962b71714370bc0f117b22003d15fe61e40a60501d81d99c6d38f7c9185958b
BLAKE2b-256 checksum
How to use checksums
89a92bc2abd93a69814ad4e39a54ef2adc90fa6b15f0141a40904d6f42f38934
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

Release files / crypto_balancer-3.1.1-py3-none-any.whl

Download URL crypto_balancer-3.1.1-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2842c87dbc603d5f3b1cee28fbbd09a41945610850f17671dcb65749b9c153ee
BLAKE2b-256 checksum
How to use checksums
b56b069b72d2cade82272eb2e5e5552b18c92b568f96a42169c5fb3e7b14f7a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

Security for crypto-balancer 3.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page