Pages:
Author

Topic: goxtool bot: portfolio rebalancing - page 8. (Read 26586 times)

member
Activity: 105
Merit: 10
April 22, 2013, 09:06:44 AM
#13
an other idea could be to allow to pass config file as parameter like this

Code:
python goxtool.py --config /path/to/goxtool.ini

so it will be possible to have a screen with BTCUSD and an other one with BTCEUR

**but** if your strategies are writing files it could be a problem because 2 differents goxtools
are writing on same file...
Let's say that you are implementing a trailing stop strategy...
you will store stop loss price in a file (because you want not to lose value if goxtool is
stopped and started)
let's call sl.txt this file (ini, json or yaml file)

maybe you should add a "name" parameter in goxtool.ini
Code:
[gox]
name = MyGox1
currency = USD
use_ssl = True
use_plain_old_websocket = False
use_http_api = False
load_fulldepth = True
load_history = True
history_timeframe = 15
secret_key =
secret_secret =

[goxtool]
set_xterm_title = True

and strategy that writes files (to store data such as last stop price) will store data as
MyGox1_sl.txt

so differents goxtool could work together

(english is not my mother tongue... so please excuse me if it's not very clear)


Adding config parameter is quite easy to do

in goxtool.py file

Code:
    argp.add_argument('--config', action="store", default="goxtool.ini",
        help="name of config file, default=goxtool.ini")

    args = argp.parse_args()

    config = goxapi.GoxConfig(args.config)

So you can now have a goxtoolBTCEUR.ini with
Code:
[gox]
currency = EUR
use_ssl = True
use_plain_old_websocket = False
use_http_api = False
load_fulldepth = True
load_history = True
history_timeframe = 15
secret_key =
secret_secret =

[goxtool]
set_xterm_title = True

and call goxtool with this config file as parameter using

Code:
python goxtool.py --config goxtoolBTCUSD.ini

or with my Raspberry Pi running my Bitcoin/Litecoin softwares in GNU Screen

Code:
screen -t goxtoolBTCUSD 50 python /home/pi/src/goxtool/goxtool.py --config /home/pi/src/goxtool/goxtoolBTCUSD.ini
screen -t goxtoolBTCEUR 51 python /home/pi/src/goxtool/goxtool.py --config /home/pi/src/goxtool/goxtoolBTCEUR.ini
member
Activity: 105
Merit: 10
April 22, 2013, 05:07:47 AM
#12
I don't like the idea of this .ini file

because you can't have 2 goxtool instance running in 2 differents GNU screen
 (one for BTC/USD and an other one for BTC/EUR)

(if you want to do this you will have to copy goxtool)

maybe you should add flag to CLI
Code:
--cur1 BTC --cur2 EUR
or
Code:
--symbol BTCEUR
hero member
Activity: 938
Merit: 500
https://youengine.io/
April 22, 2013, 04:55:19 AM
#11
I like the idea, is it also able to trade BTC/EUR ?
Yes, just change the currency in goxtool.ini from USD to EUR.
hero member
Activity: 938
Merit: 500
https://youengine.io/
April 22, 2013, 04:52:33 AM
#10
I think a nice feature (although far from full proof) would be to cancel all orders if there are >2 bot orders, then place them again.  However it is still possible that some of those rouge orders get filled in the meantime.

I'm trying to understand wat might have happened to cause these symptoms, i don't have any idea yet. It should not trade if there are != 1 open orders, it should not trade if there are != 0 submitted but not yet acked orders.

How did you start goxtool, did you use --use-http or did you send the orders via the streming API? I cannot imagine any scenario where sending an order would *not* increment gox.count_submitted *or* the number of own orders in orderbook.owns. Either the sent order doesn't get acked then count_submitted will be != 0 or there comes the ack with order id for each order then count_submitted = 0 but orderbook.owns has a new element added. In both cases it shoudl stop sending more orders. The only way I could vaguely imagine was if you did not --use-http and submitted via socketio, never received the ack and order ID, a reconnect would reset the count_submitted counter [Edit: actually only a *successful* download of own orders will reset count_submitted, not a simple reconnect] and because of ddos and 502 error you would never get the full own order list download but for some reason all the submitted orders (submitted through socketio and never acked) would later go through all at once [because they were hanging around somewhere on the server in some kind of separate (undocumented?) queue all the time]. Thats why I recommend --use-http because that way you *WILL* get an ack for every order under all circumstances because the http call will either succeed (ack) or fail.

Are you running the latest version of goxtool.py and the latet version of the bot (3rd revision) from the github gist in post #1 of this thread or are you still using one of the older versions from the other thread?

If this happens again please save the log file (*before* you restart goxtool because restarting will truncate the old log)
hero member
Activity: 588
Merit: 500
April 22, 2013, 02:28:18 AM
#9
I like the idea, is it also able to trade BTC/EUR ?
hero member
Activity: 560
Merit: 500
I am the one who knocks
April 21, 2013, 09:33:39 PM
#8
So... Did anyone else have the bot freak out and place 30+ orders because of GOX lag today?


hmm i may have mentioned this.....need to make something like

if(watch.goxLag())
{
trade
}


goxLag()
{

if
{last.ping() > choose interval
return false}

...condition
false

....condition
true

}

etc

It wasn't just lag tho. When I looked there was only like 60s.  However I kept getting 503 errors all over the place. 

I think a nice feature (although far from full proof) would be to cancel all orders if there are >2 bot orders, then place them again.  However it is still possible that some of those rouge orders get filled in the meantime.
legendary
Activity: 2632
Merit: 1023
April 21, 2013, 08:41:06 PM
#7
So... Did anyone else have the bot freak out and place 30+ orders because of GOX lag today?


hmm i may have mentioned this.....need to make something like

if(watch.goxLag())
{
trade
}


goxLag()
{

if
{last.ping() > choose interval
return false}

...condition
false

....condition
true

}

etc
hero member
Activity: 560
Merit: 500
I am the one who knocks
April 21, 2013, 06:23:28 PM
#6
So... Did anyone else have the bot freak out and place 30+ orders because of GOX lag today?
full member
Activity: 227
Merit: 100
April 21, 2013, 03:37:44 AM
#5
I set DISTANCE at 5.
I was balanced at 126.30
First trade went smoothly at 119.97
New orders opened
full member
Activity: 227
Merit: 100
April 21, 2013, 02:20:09 AM
#4
F*ck! I was doing that by hand when I was awake with emotions envolved.
I wanted an emotionless robot to do that for me all day long.
Thanks for that bot.
Donation is coming your way.
https://blockchain.info/tx/b7945ec1febb42338e96d9a05019593751dbf8f3775e56ca74789e2de661b1a0
Thanks again
legendary
Activity: 2968
Merit: 1198
April 21, 2013, 01:41:11 AM
#3
I guess my worrie is in spikey fast tradeing with bad conections sometimes computer programs behace in unexpected manners.

There are definitely issues with lag, dropped gox connections, etc.  Some of those are discussed on the main thread, as they aren't really specific to this strategy.

Another rebalancing strategy discussed on the same wiki page might also be interesting to play with:

http://en.wikipedia.org/wiki/Constant_proportion_portfolio_insurance

legendary
Activity: 2632
Merit: 1023
April 21, 2013, 01:02:26 AM
#2
hero member
Activity: 938
Merit: 500
https://youengine.io/
April 20, 2013, 12:38:00 PM
#1
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/5395900

This bot will maintain a constant asset allocation ratio Bitcoin/Fiat = 50/50
http://en.wikipedia.org/wiki/Rebalancing_investments#Rebalancing_bonus
It 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).
Pages:
Jump to: