'ITERATIONS': 0, } # Analysis Data ADATA = { 'EMA_FAST': None, #BTC 'EMA_SLOW': None, #BTC 'POS_CROSSOVER': None, 'LAST': 0, } # API Config API_KEY = "" API_SECRET = "" API_CURRENCY = "USD" API = MtGox(API_KEY, API_SECRET, API_CURRENCY) def analyze(): if not ADATA['EMA_FAST'] or not ADATA['EMA_SLOW']: ADATA['EMA_FAST'] = ADATA['LAST'] ADATA['EMA_SLOW'] = ADATA['LAST'] if ADATA['POS_CROSSOVER'] == None: if ADATA['EMA_FAST'] < ADATA['EMA_SLOW']: ADATA['POS_CROSSOVER'] = False if ADATA['EMA_FAST'] > ADATA['EMA_SLOW']: ADATA['POS_CROSSOVER'] = True ADATA['EMA_FAST'] = ( (2 * (ADATA['LAST'] - ADATA['EMA_FAST'])) / 11) + ADATA['EMA_FAST'] ADATA['EMA_SLOW'] = ( (2 * (ADATA['LAST'] - ADATA['EMA_SLOW'])) / 22) + ADATA['EMA_SLOW']
def onBuy(order, amount, price): print "Bought %.2f BTC at %.2f USD" % (amount, price) def onSell(order, amount, price): print "Sold %.2f BTC at %.2f USD" % (amount, price) gox.cancel_all() print '' # os.system('clear') if usds > 0.1: for i in range(LEVELS, 0, -1): price = movavg / (1 + MARGIN_BUY * i) amount = (usds / LEVELS) / price print ("%.2f" % price) self.gox.buy(amount, price, None, onBuy) print '------' if btcs > 0.1: for i in range(1, LEVELS + 1): price = movavg * (1 + MARGIN_SELL * i) amount = btcs / LEVELS print ("%.2f " % price) self.gox.sell(amount, price, None, onSell) if __name__ == "__main__": from mtgox import MtGox from config import KEY, SEC gox = MtGox(KEY, SEC) gox.start() scalper = Scalper(gox) scalper.start()
logging.basicConfig( filename = 'interactive.log', filemode = 'w', format = '[%(asctime)s, %(threadName)s, %(name)s, %(levelname)s]\n %(message)s', # format = '%(name)-12s: %(message)s', datefmt = '%d/%m %H:%M:%S', ) # logging.getLogger('MtGoxCore').setLevel(logging.DEBUG) logging.getLogger('MtGox').setLevel(logging.DEBUG) logging.getLogger('MtGoxCore').setLevel(logging.NOTSET) # logging.getLogger('MtGox').setLevel(logging.INFO) TIMEOUT = 60 _gox = MtGox(KEY, SEC) _gox.start() _scalper = Scalper(_gox) _scalper.start() def _to_decimal(x): return Decimal(str(x)) def stop(): _gox.stop() _scalper.stop() quit() def ticker(): x = _gox.ticker() return {'buy': str(x['buy']),