Skip to content

Instantly share code, notes, and snippets.

@aido
Last active December 17, 2015 19:19
Show Gist options
  • Save aido/5659626 to your computer and use it in GitHub Desktop.
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.
"""
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