def setup_client(currency='USD', dbname='mtgox_trades.db', **kwargs): table = "btc%s" % currency.lower() db = sqlite3.connect(dbname) setup_database(db, table) mtgox_client = mtgox.create_client('', '', currency) # No key/secret. tradefetch = TradeFetchStore(db, table, mtgox_client, **kwargs) return mtgox_client, tradefetch, db
def main(key, secret): currency = 'USD' # Changing this to 'EUR' should work just fine. plot = Demo(currency) mtgox_client = mtgox.create_client(key, secret, currency) # After connecting, subscribe to the channels 'lag' and 'trades. for ch in ('lag', 'ticker', 'trades'): mtgox_client.call('subscribe_type', ch) # The first time a connection is established, load some of the # last trades (it should be trades from 2 hours ago, but MtGox # does not actually send all of it). mtgox_client.call('load_trades_since', hours_ago=2, once=True) mtgox_client.evt.listen('trade_fetch', plot.mtgox_trade) # Listen for events in the registered channels. mtgox_client.evt.listen('trade', plot.mtgox_trade) mtgox_client.evt.listen('lag', plot.mtgox_lag) mtgox_client.evt.listen('ticker', plot.mtgox_vol) btce_client = btce.create_client() btce_client.evt.listen('trade_fetch', plot.btce_trade) # Get the last trades each x seconds. btce_pool = task.LoopingCall(btce_client.trades, p2=currency) btce_pool.start(10) # x seconds btcchina_cli = btcchina.create_client() btcchina_cli.evt.listen('trade_fetch', plot.btcchina_trade) btcchina_pool = task.LoopingCall(btcchina_cli.trades) btcchina_pool.start(10) bitstamp_cli = bitstamp.create_client() bitstamp_cli.evt.listen('trade_fetch', plot.bitstamp_trade) bitstamp_cli.transactions(timedelta=60*60) # Trades from last hour. # Get the last trades each x seconds. bitstamp_pool = task.LoopingCall(bitstamp_cli.transactions, timedelta=60) bitstamp_pool.start(10, now=False) # x seconds. print('Showing GUI..') plot.show() plot.raise_() reactor.addSystemEventTrigger('after', 'shutdown', app.quit) reactor.run()
def main(key, secret): # List of the currency symbols available in MtGox: # USD, AUD, CAD, CHF, CNY, DKK, EUR, GBP, HKD, JPY, NZD, PLN, RUB, SEK, # SGD, THB, NOK, CZK currency = 'USD' main = QG.QMainWindow() w = QG.QWidget() plotw = PlotDepthWidget(axconf=[0.1, 0.15, 0.87, 0.81]) l = QG.QVBoxLayout() l.addWidget(plotw) w.setLayout(l) main.setWindowTitle(u'MtGox Depth Market') main.setCentralWidget(w) def finish(event): reactor.stop() event.accept() main.closeEvent = finish demo = Demo(plotw.plot, currency) cli = mtgox.create_client(key, secret, currency) cli.evt.listen('depth_fetch', demo.depth_fetch) cli.evt.listen('depth', demo.depth_live) cli.evt.listen('userorder', demo.userorder) cli.call('subscribe_type', 'depth') # Default event: connected. cli.call('order_list') # If you do not wish to pre-load depth data, comment the following line. cli.call('depth_fetch', once=True) main.show() main.raise_() reactor.addSystemEventTrigger('after', 'shutdown', app.quit) reactor.run()