Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
e2b3afb
Working PluginConsole filtering debug messages starting with '[s]', c…
caktux Dec 1, 2013
7fad47a
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 1, 2013
a300457
Add balancer.py, buy.py and sell.py, copy original docs to README and…
caktux Dec 2, 2013
616c188
h5 on donations title...
caktux Dec 2, 2013
8637a66
and at the bottom
caktux Dec 2, 2013
09509f0
fixing readme
caktux Dec 2, 2013
0bcf870
fixing readme
caktux Dec 2, 2013
6342cf1
fixing readme
caktux Dec 2, 2013
0a0c43b
Use <kbd> in readme
caktux Dec 2, 2013
ee041c1
fixing readme
caktux Dec 2, 2013
2f3fe07
fixing readme
caktux Dec 2, 2013
261b793
Add simulate flag, protect against selling below current ask price + …
caktux Dec 2, 2013
28e1115
use mark_own and output cleanup
caktux Dec 2, 2013
15c19f8
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 3, 2013
140aa39
Add protection against buying above current bid price, adjust sell pr…
caktux Dec 3, 2013
638b7c6
Show prices in status bar with important info in bold, no more blue b…
caktux Dec 4, 2013
e888e12
Update README.md
caktux Dec 4, 2013
8e7f3e2
Update README.md
caktux Dec 4, 2013
a596fa1
Allow overriding defaults with a json encoded user.conf file, fix som…
caktux Dec 6, 2013
0546316
force data types read from user.conf
caktux Dec 6, 2013
77f8806
use int instead of bool for _simulate flags from user.conf
caktux Dec 6, 2013
290d318
Update README.md
caktux Dec 6, 2013
cf7104f
Merge balancer updates from prof7bit, improved distance calculation, …
caktux Dec 6, 2013
fe5f1a5
Merge branch 'master' of https://github.com/caktux/goxtool
caktux Dec 6, 2013
7f421c8
Show monthly volume and trade fee in PluginConsole
caktux Dec 6, 2013
55f9954
use int() for balancer_compensate_fees from conf
caktux Dec 6, 2013
acc89f0
buy more, sell less, and check for 0.011 buy amount instead of just c…
caktux Dec 7, 2013
e9c8115
Add balancer target margin, BTC total with current market in status a…
caktux Dec 8, 2013
e2f939b
don't show buy/sell strategy info on every tick
caktux Dec 8, 2013
dc01f1e
INS or = to select, Macs don't have an Insert key
caktux Dec 8, 2013
ab78dff
fit key help in window, update readme
caktux Dec 8, 2013
d8ef6f1
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 11, 2013
ab182a4
revert to buy more, sell more and correct next_buy and next_sell to b…
caktux Dec 11, 2013
f872d7a
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 11, 2013
1a61a56
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 11, 2013
f2da6fa
typo
Dec 12, 2013
ec75c64
add `pubnub` option into args description
Dec 12, 2013
c0cff30
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 12, 2013
aa6e57b
Merge branch 'master_prof7bit' of https://github.com/gwdp/goxtool
caktux Dec 12, 2013
04e41b6
default to pubnub, update readme and typo
caktux Dec 12, 2013
70fab7a
this fixes backspace on macosx -- #11
Dec 12, 2013
22a0d4d
add total fiat in status
caktux Dec 12, 2013
0867d69
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 12, 2013
362a1da
Merge branch 'master_prof7bit_issue11' of https://github.com/gwdp/gox…
caktux Dec 12, 2013
f1d0499
Compensate fees on price instead of volume and apply target margin wh…
caktux Dec 12, 2013
1cc2f97
log to balancer.log, keep underscore for forced prices
caktux Dec 12, 2013
ab36405
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 12, 2013
82ea350
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 12, 2013
d94b698
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 12, 2013
26a79a0
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 13, 2013
51b7b2f
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 13, 2013
abbb6b6
improve fee compensation, output cleanup, use self.step_factor
caktux Dec 13, 2013
8f62c66
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 13, 2013
81d8e2b
int(round()) and mention if live
caktux Dec 13, 2013
eb64e90
fix forced price with self.step_factor
caktux Dec 14, 2013
63bf3cc
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 14, 2013
4bf9a8f
press h for help
caktux Dec 14, 2013
6bcfaae
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 16, 2013
6a75fa2
show transactions total
caktux Dec 16, 2013
11f241e
show totals in balancer also
caktux Dec 16, 2013
c3cdbee
quote2float in new totals and first take at fixing mtgox satoshi bug
caktux Dec 16, 2013
5c076e1
compare directly
caktux Dec 16, 2013
ae15b51
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 17, 2013
6338717
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 17, 2013
3e5e81c
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 18, 2013
fd976a9
balancer: write actual trades to log instead of placed orders and mov…
caktux Dec 19, 2013
0e6862f
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Dec 19, 2013
39634b3
missing self...
caktux Dec 19, 2013
b82a213
balancer: implement simulation wallet with logging
caktux Dec 23, 2013
6aeb686
balancer: fix reloading in simulation
caktux Dec 23, 2013
86f93c9
balancer: fix simulation sell trades and fake wallet btc balance not …
caktux Dec 28, 2013
0f92d9a
use self.gox.curr_quote in buy.py
caktux Jan 2, 2014
797924f
balancer: improve fee compensation once more
caktux Jan 5, 2014
7bcf4b5
Support separate buy and sell price distance, default to 5% and with …
caktux Jan 9, 2014
7c7a16d
Merge branch 'master' of https://github.com/prof7bit/goxtool
caktux Jan 18, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 200 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,205 @@
#goxtool.py
#### Hosted version available at [https://zerogox.com](https://zerogox.com)

Goxtool is a trading client for the MtGox Bitcon currency exchange. It is
designed to work in the Linux console (it has a curses user interface). It
can display live streaming market data and you can buy and sell with
keyboard commands.
# Goxtool

Goxtool also has a simple interface to plug in your own automated trading
strategies, your own code can be (re)loded at runtime, it will receive
events from the API and can act upon them.
Goxtool is a Python trading client and auto-trading bot for the MtGox Bitcoin currency exchange. It is designed to work in the Linux console and has a curses user interface. It can display live streaming market data and you can buy and sell with keyboard commands.

The user manual is here:
Goxtool also has a simple interface to plug in your own automated trading strategies, your own code can be reloaded at runtime, will receive events from the API and can act upon them.


## Installation

Open a terminal in an empty folder or in the folder you usually use to clone repositories and clone the master branch:

```
git clone git://github.com/caktux/goxtool.git
```

This will create a folder named goxtool containing all the needed files. Thats all, now it is installed and ready to use. You can now already watch live market data (without any trading functions being enabled), you can later add a MtGox API-key to it to have full access to your account but for now just proceed to the next step, start it without an account, just to make sure everything works.


## Usage

Change into to the goxtool folder that was created in the previous step and start goxtool.py:

```
cd goxtool
./goxtool.py
```

Keyboard commands (only the ones useful in view-only mode, without Mt.Gox account):

- <kbd>q</kbd> quit
- <kbd>l</kbd> (lower case "L") reload the strategy module (see advanced usage)
- <kbd>D</kbd> (shift + d) switch to depth chart view
- <kbd>H</kbd> (shift + h) switch to candlestick history chart view
- <kbd>S</kbd> (shift + s) toggle summing up the volume of order book levels on/off
- <kbd>T</kbd> (shift + t) toggle summing up the volume in the depth chart on/off
- <kbd>-</kbd> order book zoom out (increase group size)
- <kbd>+</kbd> order book zoom in (decrease group size)
- <kbd>,</kbd> depth chart zoom out (increase group size)
- <kbd>.</kbd> depth chart zoom in (decrease group size)

(There will be even more commands once you connect it to your Mt.Gox account)

There is also a goxtool.ini file, it will be created on the first start. In the .ini file there are some parameters you can change, for example the currency you want to trade BTC against or some parameters regarding the network protocol. Some of the .ini settings can be overridden by command line options (use the --help option to see a list). The default protocol is now PubNub, with websocket and socketio as alternatives. Goxtool implements all three protocols with PubNub currently being more reliable. There is also an option to use the http API for trading commands with websocket and socketio, the default is to send all commands to the streaming socket when using websocket, this affects only what happens when you buy/sell/cancel, it does not affect the streaming update of order book and chart.

The two options are socketio or websocket, the .ini setting for this is use_plain_old_websocket. To force it connecting with socketio:

```
./goxtool.py --protocol=socketio
```

To force it connecting to the websocket server do this:

```
./goxtool.py --protocol=websocket
```

It has turned out that websocket is currently the most reliable protocol after pubnub. These options on the command line take precedence over what you have configured in the .ini file (but it won't change your .ini), you can make websocket the default (so you don't need this option anymore) by editing the ini file.

If you experience a high lag between sending an order and the ack (the op:result) not appearing immediately which is happening during times of really high volume then you should consider also adding --use-http to make it send trading commands via http. Http makes it slightly slower to execute many trades in a row but has been much more reliable when mtgox was under heavy load or ddos or similar. If you don't need to send many orders very fast then this option won't hurt. --use-http can be combined with either socketio or websocket and is forced for PubNub.

The following is what I am currently using and I recommend it:

```
./goxtool.py --protocol=websocket --use-http
```


## Trading with your MtGox account

First you will need to add an API key in MtGox, then do the following:

```
./goxtool.py --add-secret
```

This will now ask you for your key, secret and a password (not your MtGox one) to secure those on your drive. The key and secret belong to a shared secret that is created by MtGox to authenticate your trading software against their API. You can request as many keys from MtGox as you need, every application you connect to your MtGox account should have its own key, you can also at any time delete the keys again that you no longer need.

If you need a Key/Secret pair for goxtool, open your web browser, log in to your MtGox account, click on "Security Center", click on "Advanced API Key Creation", choose a name for your key (every key will have a name so you can later easily tell them apart), make sure you check at least the boxes "Get Info" and "Trade" (this is what the application will be allowed to do with this key) and then finally click on "Create Key".

Now MtGox will create 2 strings of cryptic numbers and letters, the "API-Key" and the "Secret". Now copy/paste the API-Key into the terminal where it asked you for "Key", press enter, now it will ask you for "Secret", copy/paste the Secret into the terminal, press enter and now it will ask you for a passphrase. It is important to understand what is going on here. The Key/Secret from above must under no circumstances ever come into the wrong hands, therefore goxtool won't just store them in the .ini file, goxtool will encrypt it and thats what the passphrase is needed for. Choose a secure passphrase (it will ask you twice to make sure there is no typo), you will also not see anything in the console (not even "*") while typing, this is not a bug, this is intentional. Choose a strong passphrase, type it into the terminal, press enter, repeat the passphrase, press enter again and now it will tell you that it has been encrypted and saved to the .ini file and exit.

Now start goxtool again:

```
./goxtool.py
```


Which will ask:

```
enter passphrase for secret:
```

From now on every time you start goxtool it will ask you for the passphrase in order to be able to decrypt and use the secret. Enter your passphrase, press enter. Now goxtool will start and you will notice that now it is showing your account balance at the top of the window. Now all trading functions are enabled.

Keyboard commands for trading:

- <kbd>F4</kbd> : New buy order
- <kbd>F5</kbd> : New sell order
- <kbd>F6</kbd> : View orders / cancel order(s)

In the cancel dialog you can move up/down with the arrow keys, use INS or = to select/unselect orders (you can select multiple orders and cancel them all at once) or if you just quickly want to cancel only one order just highlight to the order and hit F8. It behaves a little bit like deleting files in midnight commander.

When entering a new order you can move between the fields with up/down keys or move to the next field with tab or enter (but only if you entered a valid number into the previous field, decimal separator is . (not comma, even on European computers), send the order with enter.

All dialogs can be closed with `F10` or `ESC`.


## Strategy modules

Running all strategies:

```
./goxtool.py --strategy=balancer.py,buy.py,sell.py
```


#### Balancer

Portfolio rebalancing bot that will buy and sell to maintain a constant asset allocation ratio of exactly 50/50 = fiat/BTC.

- <kbd>i</kbd> for information (how much currently out of balance)
- <kbd>o</kbd> to see order book
- <kbd>r</kbd> to rebalance with market order at current price (required before rebalancing)
- <kbd>p</kbd> to add initial rebalancing orders
- <kbd>c</kbd> to cancel all rebalancing orders
- <kbd>u</kbd> to update account information, order list and wallet

```
./goxtool.py --strategy=balancer.py
```

#### Buy strategy

Buy strategy module. Set `buy_level` at the price you want to buy, `threshold` above your level for a log alert and `volume` in fiat (`0` for full balance). Set `simulate` to `False` to activate.

* <kbd>b</kbd> to see Buy objective

```
./goxtool.py --strategy=buy.py
```

#### Sell strategy

Sell strategy module. Set `sell_level` at the price you want to sell, `threshold` below your level for a log alert and `volume` in fiat (`0` for full balance). Set `simulate` to `False` to activate.

- <kbd>s</kbd> to see Sell objective

```
./goxtool.py --strategy=sell.py
```

#### Making your own

You can write your own trading bots. There is a file named `strategy.py`, it contains a class Strategy() which constitutes a trading bot that by default does nothing (its an empty skeleton). It has event methods (slots) connected to signals that will be fired when certain events occur. From within these methods you can then do arbitrary stuff (peek around in gox.orderbook to see where bids and asks are located, call gox.buy(), gox.sell() or gox.cancel() methods to build a fully automated trading bot or you can use the key press slot (it will be called on all letter keys except l and q) to build a semi-automatic bot that reacts to key presses or to influence parameters of your bot or anything else you can imagine. Examples of simple bots will soon follow.

If you decide to make serious use of this then please create a new python file for your strategy. either make a copy of the default strategy.py skeleton or make a module that imports strategy and has a class Strategy(strategy.Strategy), give this module file a different name and leave strategy.py alone so it won't collide with upstream changes you pull from github. By default goxtool will load strategy.py but you can start it with the --strategy command line option to specify your own strategy module or a comma separated list of many modules:

```
./goxtool --strategy=mybot.py,myotherbot.py
```

You can even edit the strategy while goxtool is running and then reload it at runtime (this can be very useful), just press the l key (lowercase L) and it will do the following things:

* emit signal _strategy_unload, this will call slot_before_unload()
* free the currently running instance of Strategy() (your __del__() method should be called)
* re-import the changed module file
* create a new instance of Strategy() and call your__init__() again.

You should persist the state of your bot (if needed) in slot_before_unload() and reload it in __init__(). Leave the __del__() method alone, its only there to print a log message to debug proper unloading!

Please make sure that you can see the debug output from the __del__() method in the log when the strategy is reloading, you must be sure its able to free and garbage collect your strategy! If you instantiate any circular references, even something as innocent as a double linked list or even just an object holding a reference to the strategy then this will effectively keep python from being able to garbage-collect it and hold it in memory indefinitely (and keep sending it signals!).

Use the slot_before_unload() method to del everything in your strategy that might hold any circular references. You can check that it works if you see the debug output of __del__() in the log scrolling by when you press l to reload it, the fact that __del__() was called is proof that it was properly garbage-collected.

Trading functions do NOT block, this means they also won't return the MtGox order ID, you need to find your own way of remembering which orders you have sent already. A few moments (seconds or minutes) after you have sent them they will be acked by MtGox and it will fire orderbook.signal_changed()and when this happens you will find it in the gox.orderbook.owns list and it will have an official order ID. I know this is not optimal (because this part of the code is not yet complete, eventually there will be dedicated signals to notify your bot about the results of trading commands) and also this document is not yet a complete documentation. If you really want to dive into this: use the source, Luke.
How to keep it up to date

Occasionally I will commit bugfixes, improvements, etc. To update your copy of goxtool (assuming you previously installed it with git clone and not by just downloading a zip file) do the following:

```
git pull
```

and if that complains because of local uncommitted changes because you edited the strategy.py module or did other changes to the code then try this:

```
git stash
git pull
git stash pop
```

Of course you could have also have followed my previous advise to not do anything other than simple throw-away experiments in strategy.py so you can always `git reset --hard` if everything else fails and use a separate file (and probably even separate git branches) for serious bot development but this is outside the scope of this document, there exist specialized howtos for git and github elsewhere.

Original user manual is here:
[http://prof7bit.github.com/goxtool/](http://prof7bit.github.com/goxtool/)

##### Donations appreciated

prof7bit (goxtool): 1C8aDabADaYvTKvCAG1htqYcEgpAhkeYoW

caktux (mods): 18zX3wb318o2Pw9ZUHgG3mmQME536Qg2Ha
Loading