GithubHelp home page GithubHelp logo

crypto_balancer's Introduction

Build Status Coverage Status

Cryptocurrency Portfolio Balancer

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

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

To support this project

To support this project, feel free to send any tips in XRP to: https://www.xrptipbot.com/u:HammerToe/n:twitter

Or direct to rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY dest tag 8172226

Install

Via Pip:

pip install crypto_balancer

Via source from Github:

git clone [email protected]:hammertoe/crypto_balancer.git
cd crypto_balancer
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. An example config file is included at config.ini.example but below is all you need:

[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:

[email protected]
*/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.

crypto_balancer's People

Contributors

alloynetworks avatar hammertoe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

crypto_balancer's Issues

Out of memory when too much assets

I got some memory problem when I use more than 10 assets to rebalance.

My server is 64 GB RAM which are completly used and lead to a "process stopped", after swap was also fully used.

I suspect the loop "while todo" in the method balancer from simple_balancer.py. Is it a know "problem" ?

Is it a normal behavior and number of assets is limited to RAM available ?

Best regards,

Questions regarding your fork

Hi, I noticed your fork is recent so before trying, I'd like to ask three questions:

  • in config.ini.example, the targets have an odd indentation (first with title, then the other on newline): is it mandatory?
  • I suppose it uses v3 API on Binance, am I correct?
  • does the balancer still work if you have A B C coins and then change the config file to points to B C D E coins?

Thanks.

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.