Last active
December 17, 2015 19:19
-
-
Save aido/5659626 to your computer and use it in GitHub Desktop.
A interactive panic bot for goxtool Mt.Gox trading bot framework.
Keypress 'b' to execute a buy marketorder with half of local currency balance.
Keypress 's' to sell half of BTC balance.
Keypress 'v' to execute a buy marketorder with entire local currency balance.
Keypress 'a' to sell entire BTC balance.
Keypress 'c' to cancel all open orders.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
a simple panic bot. | |
The file can be reloaded after editing without | |
restarting goxtool by simply pressing the l key. | |
""" | |
import strategy | |
import goxapi | |
class Strategy(strategy.Strategy): | |
"""a simple panic bot""" | |
def __init__(self, gox): | |
strategy.Strategy.__init__(self, gox) | |
self.debug("initializing panic") | |
def slot_keypress(self, gox, key): | |
price = (gox.orderbook.bid + gox.orderbook.ask) / 2 | |
key = chr(key) | |
if key == "a": | |
vol = goxapi.int2float(gox.wallet["BTC"], "BTC") | |
self.gox.sell(0, int(vol * 1e8)) | |
self.debug(" *** Market order fired: SELL %.8f at %.8f" % (vol, price / 1e5)) | |
elif key == "v": | |
vol = goxapi.int2float(gox.wallet[gox.currency], gox.currency) | |
self.gox.buy(0, int(vol * 1e8)) | |
self.debug(" *** Market order fired: BUY %f at %.8f" % (vol, price / 1e5)) | |
elif key == "s": | |
vol = goxapi.int2float(gox.wallet["BTC"], "BTC") / 2 | |
self.gox.sell(0, int(vol * 1e8)) | |
self.debug(" *** Market order fired: SELL %.8f at %.8f" % (vol, price / 1e5)) | |
elif key == "b": | |
vol = goxapi.int2float(gox.wallet[gox.currency], gox.currency) / 2 | |
self.gox.buy(0, int(vol * 1e8)) | |
self.debug(" *** Market order fired: BUY %f at %.8f" % (vol, price / 1e5)) | |
elif key == "c": | |
for order in self.gox.orderbook.owns: | |
self.gox.cancel(order.oid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment