I'm making separate threads for individual goxtool bots to keep the goxtool thread for goxtool related stuff only. I choose this forum because the goxtool thread was moved into this forum too. (Similar software sometimes gets moved into different forums, I believe there is a forum missing for all kinds of software that is bitcoin related but *not* a bitcoin client/wallet itself)
And here is the balancer bot:
_balancer.py:
https://gist.github.com/prof7bit/5395900This bot will maintain a constant asset allocation ratio Bitcoin/Fiat = 50/50
http://en.wikipedia.org/wiki/Rebalancing_investments#Rebalancing_bonusIt will do so by placing limit orders above and below current price that will restore the 50/50 ratio once price moves there and fills the order. As soon as one order is filled it will cancel the other and then calculate and place 2 new orders above and below that new price. The price distance of the orders is 7%, that can be changed in the variable DISTANCE you should not make it smaller than 2%).
This strategy will produce a small profit in the long run (a few percent per week if there are huge price swings or nothing at all when its going sideways for many days), it seems a promising strategy for BTC/USD because of its insanely high volatility but it will also make your account balance go up and down directly in tandem with BTC price, so prepared to see huge swings in your account. You should write down BTC-price, USD and BTC balance in your account once a week and plot these curves after a few months or years to see the effect. This is not a get rich quick bot, this needs patience!
Installation and usage:- prerequisites: you are familiar with the usage of goxtool.py
- (most important) update goxtool to the latest version (git pull)
- save the file from the above link as _balancer.py in the same directory as goxtool
- ./goxtool.py --strategy=_balancer.py --protocol=websocket --use-http
- (optional) open a separate terminal and tail -f goxtool.log | grep Strategy to follow the debug output of the strategy module
- cancel all orders and bring your account into 50/50 balance, do so by pressing the b key
- start the bot by pressing the p key
Disclaimer: If the above sounds chinese to you or you cannot read the code or don't understand what it does or you are not a Linux user (needed for goxtool) then algo trading is not for you. You should have the skills to implement this yourself from scratch given the description of the strategy or be able to read, understand and debug every aspect of the existing code or it will only end with a huge disappointment or maybe even a desaster.As you can see in the code the the bot has some some hotkeys bound to certain actions to control its operations:
i show info about current status (how much out of balance)
c cancel all open rebalancing orders and suspend trading
b rebalance immediately with market order at current price
p place a pair of fresh rebalancing orders and start/resume trading
u manually force update of own order list and other stuff (should only be needed when socketio connection behaves strange or is down or other related problems, not used for normal operations)
like all other goxtool strategies it can be reloaded at runtime without restarting goxtool (for example after editing DISTANCE) by pressing the
l key (lowercase L).
As you also can see from the code it is triggering its trades when it has detected the number of orders being exactly 1, this does not happen in the trade message, the user_order message is the last API message that is sent after a series of messages updating the wallet and the trade message (and this signal is also triggered after reconnect), so this is the best place to trigger new orders, knowing that the wallet is updated already (we need the new account balance for the calculations).
When the bot ever comes out of sync, I have seen this happening when price is jumping around too fast and you choose DISTANCE too small and mtgox is under ddos at the same time and the connection becomes really unreliable then you need to cancel all orders (press c to cancel and halt trading, also check with F6 that really all orders have been canceled, maybe use u to manually update if socketio is down and if its screwed up totally then restart goxtool. This should not happen very often) and then check if you need to rebalance (press i and see the log) and if needed manually rebalance (press b) and then resume automatic rebalancing (press p).