self.CAD_USD_rate = rate self.CAD_USD_stamp = time.time() #self.logger.write ( 'rate: %f ' % self.CAD_USD_rate ) else: self.logger.write('error CAD_USD http %d' % r.status) connection.close() except Exception: self.logger.write('error CAD_USD\n' + str(traceback.format_exc())) pass trades = '/products/BTC-CAD/trades' #book = '/products/BTC-CAD/book?level=2' #if ( (time.time() - self.book_stamp) > 30 ): # self.book_fetch_full = True # book = '/products/BTC-CAD/book?level=3' # self.book_stamp = time.time ( ) book = '/products/BTC-CAD/book?level=3' ed = coinwatcher.CoinWatcher.fetchData(self, httplib.HTTPSConnection, 'api.gdax.com', book, trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('Coinbase-CAD', 'coinbaseCAD', CoinbaseCADWatcher)
if (r.status == 200): ticker_txt = r.read() ticker_json = json.loads(ticker_txt) rate = float(ticker_json['last_price']) if (rate > 0): self.LTC_USD_rate = rate self.LTC_USD_stamp = time.time() else: self.logger.write('error LTC_USD http %d' % r.status) connection.close() except Exception: self.logger.write('error LTC_USD\n' + str(traceback.format_exc())) pass trades = '/v1/trades/ltcbtc?timestamp=%d' % int( self.mostRecentTransaction) ed = coinwatcher.CoinWatcher.fetchData(self, httplib.HTTPSConnection, 'api.bitfinex.com', '/v1/book/ltcbtc', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('Bitfinex-LTC', 'bitfinexLTC', BitfinexLTCWatcher)
try: if ( mostRecentID != 0 ): self.mostRecentPrice = mostRecentPrice if ( self.mostRecentPrice == 0 ): self.mostRecentPrice = ed.bids[0][0] if ( mostRecentID != 0 ): self.mostRecentTransactionID = mostRecentID ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception: self.logger.write ( 'error buildData ticker\n' + str(traceback.format_exc()) ) return None return ed def fetchData ( self ): ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'bitcurex.com', '/api/usd/orderbook.json', '/api/usd/trades.json' ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Bitcurex-USD', 'bitcurexUSD', BitcurexUSDWatcher )
r = connection.getresponse() if (r.status == 200): rate_txt = r.read() rate = float(rate_txt.split(',')[1]) if (rate > 0): self.CNY_USD_rate = 1 / rate self.CNY_USD_stamp = time.time() #self.logger.write ( 'rate: %f ' % self.CNY_USD_rate ) else: self.logger.write('error: CNY_USD status %d' % r.status) connection.close() except Exception: self.logger.write('error: unable to get USD/CNY\n' + str(traceback.format_exc())) pass trades = '/futures/trades_btc_week.js' ed = coinwatcher.CoinWatcher.fetchData(self, httplib.HTTPSConnection, 'market.bitvc.com', '/futures/depths_btc_week.js', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('BitVCWeekly', 'bitvcweekCNY', BitVCWWatcher)
r = connection.getresponse ( ) if ( r.status == 200 ): rate_txt = r.read ( ) rate = float ( rate_txt.split(',')[1] ) if ( rate > 0 ): self.CNY_USD_rate = 1/rate self.CNY_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.CNY_USD_rate ) else: self.logger.write ( 'error: CNY_USD status %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error: unable to get USD/CNY\n' + str(traceback.format_exc()) ) pass trades = '/api/v1/trades.do?symbol=btc_cny' if ( self.mostRecentTransactionID > 0 ): trades = trades + '&since=%d' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'www.okcoin.cn', '/api/v1/depth.do?symbol=btc_cny', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'OK-CoinCNY', 'okcoinCNY', OKCoinCNYWatcher )
self.mostRecentPrice = mostRecentPrice if ( self.mostRecentPrice == 0 ): self.mostRecentPrice = ed.bids[0][0] if ( mostRecentID != 0 ): self.mostRecentTransactionID = mostRecentID self.mostRecentTransaction = mostRecentDate ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception: self.logger.write ( 'error: buildData() failed with ticker\n' + str(traceback.format_exc()) ) return None return ed def fetchData ( self ): trades = '/v1/trades/btcusd?timestamp=%d' % int ( self.mostRecentTransaction ) ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.bitfinex.com', '/v1/book/btcusd', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Bitfinex-USD', 'bitfinexUSD', BitfinexUSDWatcher )
if ( mostRecent != 0 ): self.mostRecentPrice = mostRecentPrice if ( self.mostRecentPrice == 0 ): self.mostRecentPrice = ed.bids[0][0] if ( mostRecent != 0 ): self.mostRecentTransactionID = mostRecent ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception: self.logger.write ( 'error: buildData() failed with ticker\n' + str(traceback.format_exc()) ) return None return ed def fetchData ( self ): trades = '/v1/markets/XBTUSD/trades?since=%d' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.itbit.com', '/v1/markets/XBTUSD/order_book', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'ItBit-USD', 'itbitUSD', ItBitUSDWatcher )
if r.status == 200: rate_txt = r.read() rate = float(rate_txt.split(",")[1]) if rate > 0: self.TRY_USD_rate = rate self.TRY_USD_stamp = time.time() # self.logger.write ( 'rate: %f ' % self.TRY_USD_rate ) else: self.logger.write("error TRY_USD http %d" % r.status) connection.close() except Exception: self.logger.write("error: unable to get USD/TRY\n" + str(traceback.format_exc())) pass trades = "/api/trades" if self.mostRecentTransactionID > 0: trades = trades + "?sinceid=%x" % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData( self, httplib.HTTPSConnection, "www.btcturk.com", "/api/orderbook", trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main("OK-CoinTRY", "btcturkTRY", BtcturkTRYWatcher)
if (r.status == 200): ticker_txt = r.read() ticker_json = json.loads(ticker_txt) rate = float(ticker_json['result']['XETHZUSD']['c'][0]) if (rate > 0): self.ETH_USD_rate = rate self.ETH_USD_stamp = time.time() #self.logger.write ( 'rate: %f ' % self.ETH_USD_rate ) else: self.logger.write('error ETH_USD http %d' % r.status) connection.close() except Exception: self.logger.write('error ETH_USD\n' + str(traceback.format_exc())) pass trades = '/0/public/Trades?pair=XETHXXBT&since=%s' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData( self, httplib.HTTPSConnection, 'api.kraken.com', '/0/public/Depth?pair=XETHXXBT', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('Kraken-ETH', 'krakenETH', KrakenETHWatcher)
if ( mostRecent != 0 ): self.mostRecentPrice = mostRecentPrice if ( self.mostRecentPrice == 0 ): self.mostRecentPrice = ed.bids[0][0] if ( mostRecent != 0 ): self.mostRecentTransactionID = trades['result']['last'] self.mostRecentTransaction = mostRecent ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception: self.logger.write ( 'error buildData ticker\n' + str(traceback.format_exc()) ) return None return ed def fetchData ( self ): trades = '/0/public/Trades?pair=XXBTZUSD&since=%s' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.kraken.com', '/0/public/Depth?pair=XXBTZUSD', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Kraken-USD', 'krakenUSD', KrakenUSDWatcher )
connection = httplib.HTTPSConnection ( 'api.kraken.com', timeout=5 ) connection.request ( 'GET', '/0/public/Ticker?pair=XZECZUSD' ) r = connection.getresponse ( ) if ( r.status == 200 ): ticker_txt = r.read ( ) ticker_json = json.loads ( ticker_txt ) rate = float ( ticker_json['result']['XZECZUSD']['c'][0] ) if ( rate > 0 ): self.ZEC_USD_rate = rate self.ZEC_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.ZEC_USD_rate ) else: self.logger.write ( 'error ZEC_USD http %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error ZEC_USD\n' + str(traceback.format_exc()) ) pass trades = '/0/public/Trades?pair=XZECXXBT&since=%s' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.kraken.com', '/0/public/Depth?pair=XZECXXBT', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Kraken-ZEC', 'krakenZEC', KrakenZECWatcher )
if ( self.mostRecentPrice == 0 ): self.mostRecentPrice = ed.bids[0][0] if ( mostRecentID != 0 ): # comes last as line above may fail self.mostRecentTransactionID = mostRecentID ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception as e: self.logger.write ( 'error buildData %s' % e ) return None return ed def fetchData ( self ): trades = '/api/v1/trades.do?symbol=btc_usd' if ( self.mostRecentTransactionID > 0 ): trades = trades + '&since=%d' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'www.okcoin.com', '/api/v1/depth.do?symbol=btc_usd', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'OK-CoinUSD', 'okcoinUSD', OKCoinUSDWatcher )
if ( rate > 0 ): self.CAD_USD_rate = rate self.CAD_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.CAD_USD_rate ) else: self.logger.write ( 'error CAD_USD http %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error CAD_USD\n' + str(traceback.format_exc()) ) pass trades = '/products/BTC-CAD/trades' #book = '/products/BTC-CAD/book?level=2' #if ( (time.time() - self.book_stamp) > 30 ): # self.book_fetch_full = True # book = '/products/BTC-CAD/book?level=3' # self.book_stamp = time.time ( ) book = '/products/BTC-CAD/book?level=3' ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.exchange.coinbase.com', book, trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Coinbase-CAD', 'coinbaseCAD', CoinbaseCADWatcher )
try: connection = httplib.HTTPConnection ( 'download.finance.yahoo.com', timeout=4 ) connection.request ( 'GET', '/d/quotes.csv?s=USDCNY=X&f=sl1&e=.csv' ) r = connection.getresponse ( ) if ( r.status == 200 ): rate_txt = r.read ( ) rate = float ( rate_txt.split(',')[1] ) if ( rate > 0 ): self.CNY_USD_rate = 1/rate self.CNY_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.CNY_USD_rate ) else: self.logger.write ( 'error: CNY_USD status %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error: unable to get USD/CNY\n' + str(traceback.format_exc()) ) pass ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'www.huobi.com', '/market/huobi.php?a=depth', '/market/huobi.php?a=trades' ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Huobi-CNY', 'huobiCNY', HuobiCNYWatcher )
if ( mostRecentID != 0 ): self.mostRecentPrice = mostRecentPrice if ( self.mostRecentPrice == 0 ): self.mostRecentPrice = ed.bids[0][0] if ( mostRecentID != 0 ): # comes last as line above may fail self.mostRecentTransactionID = mostRecentID ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception as e: self.logger.write ( 'error buildData %s' % e ) return None return ed def fetchData ( self ): trades = '/v3/futures/trades.html?type=weekly' ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPConnection, 'api.796.com', '/v3/futures/depth.html?type=weekly', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( '796Weekly', '796weeklyUSD', a796WWatcher )
ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception as e: self.logger.write ( 'error buildData %s' % e ) return None return ed def fetchData ( self ): trades = '/products/BTC-USD/trades' #book = '/products/BTC-USD/book?level=2' #if ( (time.time() - self.book_stamp) > 30 ): # self.book_fetch_full = True # book = '/products/BTC-USD/book?level=3' # self.book_stamp = time.time ( ) book = '/products/BTC-USD/book?level=3' ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.exchange.coinbase.com', book, trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Coinbase-USD', 'coinbaseUSD', CoinbaseUSDWatcher )
return ed def fetchData(self): if ((time.time() - self.EUR_USD_stamp) > 3600.0): # get USD/EUR rate every hour rate = self.fetchFixUSD('EUR') if (rate > 0): self.EUR_USD_rate = rate self.EUR_USD_stamp = time.time() trades = '/products/BTC-EUR/trades' #book = '/products/BTC-EUR/book?level=2' #if ( (time.time() - self.book_stamp) > 30 ): # self.book_fetch_full = True # book = '/products/BTC-EUR/book?level=3' # self.book_stamp = time.time ( ) book = '/products/BTC-EUR/book?level=3' ed = coinwatcher.CoinWatcher.fetchData(self, httplib.HTTPSConnection, 'api.gdax.com', book, trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('Coinbase-EUR', 'coinbaseEUR', CoinbaseEURWatcher)
try: connection = httplib.HTTPConnection ( 'download.finance.yahoo.com', timeout=5 ) connection.request ( 'GET', '/d/quotes.csv?s=JPYUSD=X&f=sl1&e=.csv' ) r = connection.getresponse ( ) if ( r.status == 200 ): rate_txt = r.read ( ) rate = float ( rate_txt.split(',')[1] ) if ( rate > 0 ): self.JPY_USD_rate = rate self.JPY_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.JPY_USD_rate ) else: self.logger.write ( 'error JPY_USD status %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error: unable to get JPY/USD\n' + str(traceback.format_exc()) ) pass trades = '/0/public/Trades?pair=XXBTZJPY&since=%s' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.kraken.com', '/0/public/Depth?pair=XXBTZJPY', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Kraken-JPY', 'krakenJPY', KrakenJPYWatcher )
connection.request ( 'GET', '/d/quotes.csv?s=EURUSD=X&f=sl1&e=.csv' ) r = connection.getresponse ( ) if ( r.status == 200 ): rate_txt = r.read ( ) rate = float ( rate_txt.split(',')[1] ) if ( rate > 0 ): self.EUR_USD_rate = rate self.EUR_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.EUR_USD_rate ) else: self.logger.write ( 'error: EUR_USD status %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error: unable to get EUR/USD\n' + str(traceback.format_exc()) ) pass trades = '/api/Public/Transactions/BTCEUR' if ( self.mostRecentTransactionID > 0 ): trades += '?TransactionsId=%s' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'www.gatecoin.com', '/api/Public/MarketDepth/BTCEUR', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Gatecoin-EUR', 'gatecoinEUR', GatecoinEURWatcher )
connection = httplib.HTTPConnection ( 'download.finance.yahoo.com', timeout=5 ) connection.request ( 'GET', '/d/quotes.csv?s=EURUSD=X&f=sl1&e=.csv' ) r = connection.getresponse ( ) if ( r.status == 200 ): rate_txt = r.read ( ) rate = float ( rate_txt.split(',')[1] ) if ( rate > 0 ): self.EUR_USD_rate = rate self.EUR_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.EUR_USD_rate ) else: self.logger.write ( 'error: EUR_USD status %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error: unable to get EUR/USD\n' + str(traceback.format_exc()) ) pass trades = '/v1/markets/XBTEUR/trades?since=%d' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.itbit.com', '/v1/markets/XBTEUR/order_book', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'ItBit-EUR', 'itbitEUR', ItBitEURWatcher )
if ( rate > 0 ): self.EUR_USD_rate = rate self.EUR_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.EUR_USD_rate ) else: self.logger.write ( 'error EUR_USD http %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error EUR_USD\n' + str(traceback.format_exc()) ) pass trades = '/products/BTC-EUR/trades' #book = '/products/BTC-EUR/book?level=2' #if ( (time.time() - self.book_stamp) > 30 ): # self.book_fetch_full = True # book = '/products/BTC-EUR/book?level=3' # self.book_stamp = time.time ( ) book = '/products/BTC-EUR/book?level=3' ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.exchange.coinbase.com', book, trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Coinbase-EUR', 'coinbaseEUR', CoinbaseEURWatcher )
connection.request ( 'POST', '/api/2/ltc_btc/trades', params, headers ) r = connection.getresponse ( ) if ( r.status == 200 ): tradesData = r.read ( ) else: self.logger.write ( 'error fetchData trades http %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error fetchData connection\n' + str(traceback.format_exc()) ) return None lag = time.time() - start # convert to JSON (book,trades) = self.makeJSON ( bookData, tradesData ) if ( (book != None) and (trades != None) ): ed = self.buildData ( book, trades, lag ) if ( ed != None ): ed.timestamp = start return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'BTCE-LTC', 'btceLTC', BTCELTCWatcher )
self.mostRecentTransactionID = mostRecentID self.mostRecentTransaction = mostRecentDate ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception: self.logger.write('error: buildData() failed with ticker\n' + str(traceback.format_exc())) return None return ed def fetchData(self): trades = '/derivatives/api/tradingdata/trades?contract=F-XBT:USD-Dec16&since=%d' % int( self.mostRecentTransactionID) ed = coinwatcher.CoinWatcher.fetchData( self, httplib.HTTPSConnection, 'www.cryptofacilities.com', '/derivatives/api/cumulativebidask?tradeable=F-XBT:USD-Dec16&unit=USD', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('CFDec16', 'cfdec16USD', CFDec16Watcher)
rate = float(rate_txt.split(",")[1]) if rate > 0: self.PLN_USD_rate = rate self.PLN_USD_stamp = time.time() # self.logger.write ( 'rate: %f ' % self.PLN_USD_rate ) else: self.logger.write("error PLN_USD status %d" % r.status) connection.close() except Exception: self.logger.write("error PLN/USD\n" + str(traceback.format_exc())) pass # disabled 2014 07 18 ; server returned errors # if ( self.mostRecentTransactionID != 0 ): # trades = '/json/BTCPLN/trades.json?since=%d' % (self.mostRecentTransactionID-1) # else: trades = "/json/BTCPLN/trades.json" ed = coinwatcher.CoinWatcher.fetchData( self, httplib.HTTPSConnection, "www.bitmarket.pl", "/json/BTCPLN/orderbook.json", trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main("Bitmarket-PLN", "bitmarketPLN", BitmarketPLNWatcher)
if (mostRecentID != 0): # comes last as line above may fail self.mostRecentTransactionID = mostRecentID ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception as e: self.logger.write('error buildData %s' % e) return None return ed def fetchData(self): trades = '/api/v1/future_trades.do?symbol=btc_usd&contract_type=this_week' if (self.mostRecentTransactionID > 0): trades = trades + '&since=%d' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData( self, httplib.HTTPSConnection, 'www.okcoin.com', '/api/v1/future_depth.do?symbol=btc_usd&contract_type=this_week', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('OKCoinWeeklies', 'okcoinwkUSD', OKCoinUSDFWWatcher)
if ( (time.time()-self.PLN_USD_stamp) > 3600.0 ): # get USD/PLN rate every hour try: connection = httplib.HTTPConnection ( 'download.finance.yahoo.com', timeout=5 ) connection.request ( 'GET', '/d/quotes.csv?s=PLNUSD=X&f=sl1&e=.csv' ) r = connection.getresponse ( ) if ( r.status == 200 ): rate_txt = r.read ( ) rate = float ( rate_txt.split(',')[1] ) if ( rate > 0 ): self.PLN_USD_rate = rate self.PLN_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.PLN_USD_rate ) else: self.logger.write ( 'error: PLN_USD status %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error: unable to get PLN/USD\n' + str(traceback.format_exc()) ) pass ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'bitcurex.com', '/api/pln/orderbook.json', '/api/pln/trades.json' ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Bitcurex-PLN', 'bitcurexPLN', BitcurexPLNWatcher )
try: if ( mostRecentID != 0 ): self.mostRecentPrice = mostRecentPrice if ( self.mostRecentPrice == 0 ): self.mostRecentPrice = ed.bids[0][0] if ( mostRecentID != 0 ): self.mostRecentTransactionID = mostRecentID ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception: self.logger.write ( 'error: buildData ticker\n' + str(traceback.format_exc()) ) return None return ed def fetchData ( self ): trades = '/api/public/transactions?pair=BTCUSD' ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'bit-x.com', '/api/public/orderBook?pair=BTCUSD', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'BitX-USD', 'bitxUSD', BitXUSDWatcher )
self.mostRecentPrice = mostRecentPrice if ( self.mostRecentPrice == 0 ): self.mostRecentPrice = ed.bids[0][0] if ( mostRecentID != 0 ): self.mostRecentTransactionID = mostRecentID self.mostRecentTransaction = mostRecentDate ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception: self.logger.write ( 'error: buildData() failed with ticker\n' + str(traceback.format_exc()) ) return None return ed def fetchData ( self ): trades = '/v1/trades/ltcusd?timestamp=%d' % int ( self.mostRecentTransaction ) ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.bitfinex.com', '/v1/book/ltcusd', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Bitfinex-LTCUSD', 'bitfinexLTC', BitfinexltcUSDWatcher )
r = connection.getresponse ( ) if ( r.status == 200 ): ticker_txt = r.read ( ) ticker_json = json.loads ( ticker_txt ) rate = float ( ticker_json['result']['XETHZUSD']['c'][0] ) if ( rate > 0 ): self.ETH_USD_rate = rate self.ETH_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.ETH_USD_rate ) else: self.logger.write ( 'error ETH_USD http %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error ETH_USD\n' + str(traceback.format_exc()) ) pass trades = '/api/Public/Transactions/ETHBTC' if ( self.mostRecentTransactionID > 0 ): trades += '?TransactionsId=%s' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'www.gatecoin.com', '/api/Public/MarketDepth/ETHBTC', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Gatecoin-ETH', 'gatecoinETH', GatecoinETHWatcher )
connection = httplib.HTTPSConnection ( 'api.bitfinex.com', timeout=5 ) connection.request ( 'GET', '/v1/pubticker/ltcusd' ) r = connection.getresponse ( ) if ( r.status == 200 ): ticker_txt = r.read ( ) ticker_json = json.loads ( ticker_txt ) rate = float ( ticker_json['last_price'] ) if ( rate > 0 ): self.LTC_USD_rate = rate self.LTC_USD_stamp = time.time ( ) else: self.logger.write ( 'error LTC_USD http %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error LTC_USD\n' + str(traceback.format_exc()) ) pass trades = '/v1/trades/ltcbtc?timestamp=%d' % int ( self.mostRecentTransaction ) ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.bitfinex.com', '/v1/book/ltcbtc', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Bitfinex-LTC', 'bitfinexLTC', BitfinexLTCWatcher )
connection = httplib.HTTPSConnection ( 'api.kraken.com', timeout=5 ) connection.request ( 'GET', '/0/public/Ticker?pair=XETCZUSD' ) r = connection.getresponse ( ) if ( r.status == 200 ): ticker_txt = r.read ( ) ticker_json = json.loads ( ticker_txt ) rate = float ( ticker_json['result']['XETCZUSD']['c'][0] ) if ( rate > 0 ): self.ETC_USD_rate = rate self.ETC_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.ETC_USD_rate ) else: self.logger.write ( 'error ETC_USD http %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error ETC_USD\n' + str(traceback.format_exc()) ) pass trades = '/0/public/Trades?pair=XETCXXBT&since=%s' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.kraken.com', '/0/public/Depth?pair=XETCXXBT', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Kraken-ETC', 'krakenETC', KrakenETCWatcher )
'/d/quotes.csv?s=JPYUSD=X&f=sl1&e=.csv') r = connection.getresponse() if (r.status == 200): rate_txt = r.read() rate = float(rate_txt.split(',')[1]) if (rate > 0): self.JPY_USD_rate = rate self.JPY_USD_stamp = time.time() #self.logger.write ( 'rate: %f ' % self.JPY_USD_rate ) else: self.logger.write('error JPY_USD status %d' % r.status) connection.close() except Exception: self.logger.write('error: unable to get JPY/USD\n' + str(traceback.format_exc())) pass trades = '/api/trades' ed = coinwatcher.CoinWatcher.fetchData(self, httplib.HTTPSConnection, 'www.coincheck.jp', '/api/order_books', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('CoincheckJPY', 'coincheckJPY', CoincheckJPYWatcher)
self.mostRecentTransactionID = mostRecentID self.mostRecentTransaction = mostRecentDate ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception: self.logger.write('error: buildData() failed with ticker\n' + str(traceback.format_exc())) return None return ed def fetchData(self): trades = '/derivatives/api/tradingdata/trades?contract=F-XBT:USD-Sep16&since=%d' % int( self.mostRecentTransaction) ed = coinwatcher.CoinWatcher.fetchData( self, httplib.HTTPSConnection, 'www.cryptofacilities.com', '/derivatives/api/cumulativebidask?tradeable=F-XBT:USD-Sep16&unit=USD', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('CFSep16', 'cfsep16USD', CFSep16Watcher)
rate = float(rate_txt.split(',')[1]) if (rate > 0): self.AUD_USD_rate = rate self.AUD_USD_stamp = time.time() #self.logger.write ( 'rate: %f ' % self.AUD_USD_rate ) else: self.logger.write('error AUD_USD status %d' % r.status) connection.close() except Exception: self.logger.write('error AUD/USD\n' + str(traceback.format_exc())) pass trades = '/market/BTC/AUD/trades' if (self.mostRecentTransactionID != 0): trades += '?since=%d' % (self.mostRecentTransactionID) ed = coinwatcher.CoinWatcher.fetchData(self, httplib.HTTPSConnection, 'api.btcmarkets.net', '/market/BTC/AUD/orderbook', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('BTCMarkets-AUD', 'btcmarketsAUD', BTCMarketsAUDWatcher)
try: connection = httplib.HTTPConnection ( 'download.finance.yahoo.com', timeout=5 ) connection.request ( 'GET', '/d/quotes.csv?s=GBPUSD=X&f=sl1&e=.csv' ) r = connection.getresponse ( ) if ( r.status == 200 ): rate_txt = r.read ( ) rate = float ( rate_txt.split(',')[1] ) if ( rate > 0 ): self.GBP_USD_rate = rate self.GBP_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.GBP_USD_rate ) else: self.logger.write ( 'error: GBP_USD status %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error: unable to get GBP/USD\n' + str(traceback.format_exc()) ) pass trades = '/api/public/transactions?pair=BTCGBP' ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'bit-x.com', '/api/public/orderBook?pair=BTCGBP', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'BitX-GBP', 'bitxGBP', BitXGBPWatcher )
if ( rate > 0 ): self.GBP_USD_rate = rate self.GBP_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.GBP_USD_rate ) else: self.logger.write ( 'error GBP_USD http %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error GBP_USD\n' + str(traceback.format_exc()) ) pass trades = '/products/BTC-GBP/trades' #book = '/products/BTC-GBP/book?level=2' #if ( (time.time() - self.book_stamp) > 30 ): # self.book_fetch_full = True # book = '/products/BTC-GBP/book?level=3' # self.book_stamp = time.time ( ) book = '/products/BTC-GBP/book?level=3' ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.exchange.coinbase.com', book, trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Coinbase-GBP', 'coinbaseGBP', CoinbaseGBPWatcher )
self.mostRecentPrice = mostRecentPrice if ( self.mostRecentPrice == 0 ): self.mostRecentPrice = ed.bids[0][0] if ( mostRecentID != 0 ): self.mostRecentTransactionID = mostRecentID self.mostRecentTransaction = mostRecentDate ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception: self.logger.write ( 'error: buildData() failed with ticker\n' + str(traceback.format_exc()) ) return None return ed def fetchData ( self ): trades = '/derivatives/api/tradingdata/trades?contract=F-XBT:USD-May16-W4&since=%d' % int ( self.mostRecentTransactionID ) ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'www.cryptofacilities.com', '/derivatives/api/cumulativebidask?tradeable=F-XBT:USD-May16-W4&unit=USD', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'CFWeekly', 'cfweeklyUSD', CFWeeklyUSDWatcher )
r = connection.getresponse() if (r.status == 200): rate_txt = r.read() rate = float(rate_txt.split(',')[1]) if (rate > 0): self.CAD_USD_rate = rate self.CAD_USD_stamp = time.time() #self.logger.write ( 'rate: %f ' % self.CAD_USD_rate ) else: self.logger.write('error CAD_USD http %d' % r.status) connection.close() except Exception: self.logger.write('error CAD_USD\n' + str(traceback.format_exc())) pass trades = '/0/public/Trades?pair=XXBTZCAD&since=%s' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData( self, httplib.HTTPSConnection, 'api.kraken.com', '/0/public/Depth?pair=XXBTZCAD', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('Kraken-CAD', 'krakenCAD', KrakenCADWatcher)
rate_txt = r.read() rate = float(rate_txt.split(',')[1]) if (rate > 0): self.PLN_USD_rate = rate self.PLN_USD_stamp = time.time() #self.logger.write ( 'rate: %f ' % self.PLN_USD_rate ) else: self.logger.write('error PLN_USD %d' % r.status) connection.close() except Exception as e: self.logger.write('error PLN_USD %s' % e) pass if (self.mostRecentTransactionID != 0): trades = '/API/Public/BTCPLN/trades.json?since=%d' % self.mostRecentTransactionID else: trades = '/API/Public/BTCPLN/trades.json' ed = coinwatcher.CoinWatcher.fetchData( self, httplib.HTTPSConnection, 'market.bitbay.pl', '/API/Public/BTCPLN/orderbook.json', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('Bitbay-PLN', 'bitbayPLN', BitbayPLNWatcher)
r = connection.getresponse ( ) if ( r.status == 200 ): rate_txt = r.read ( ) rate = float ( rate_txt.split(',')[1] ) if ( rate > 0 ): self.AUD_USD_rate = rate self.AUD_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.AUD_USD_rate ) else: self.logger.write ( 'error AUD_USD status %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error AUD/USD\n' + str(traceback.format_exc()) ) pass trades = '/market/BTC/AUD/trades' if ( self.mostRecentTransactionID != 0 ): trades += '?since=%d' % (self.mostRecentTransactionID) ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.btcmarkets.net', '/market/BTC/AUD/orderbook', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'BTCMarkets-AUD', 'btcmarketsAUD', BTCMarketsAUDWatcher )
r = connection.getresponse() if (r.status == 200): rate_txt = r.read() rate = float(rate_txt.split(',')[1]) if (rate > 0): self.GBP_USD_rate = rate self.GBP_USD_stamp = time.time() #self.logger.write ( 'rate: %f ' % self.GBP_USD_rate ) else: self.logger.write('error GBP_USD http %d' % r.status) connection.close() except Exception: self.logger.write('error GBP_USD\n' + str(traceback.format_exc())) pass trades = '/0/public/Trades?pair=XXBTZGBP&since=%s' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData( self, httplib.HTTPSConnection, 'api.kraken.com', '/0/public/Depth?pair=XXBTZGBP', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('Kraken-GBP', 'krakenGBP', KrakenGBPWatcher)
if (self.mostRecentPrice == 0): self.mostRecentPrice = ed.bids[0][0] if (mostRecent != 0): self.mostRecentTransactionID = mostRecent ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception: self.logger.write('error: buildData() failed with ticker\n' + str(traceback.format_exc())) return None return ed def fetchData(self): trades = '/v1/markets/XBTUSD/trades?since=%d' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData( self, httplib.HTTPSConnection, 'api.itbit.com', '/v1/markets/XBTUSD/order_book', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('ItBit-USD', 'itbitUSD', ItBitUSDWatcher)
connection.request ( 'POST', '/api/2/btc_usd/trades', params, headers ) r = connection.getresponse ( ) if ( r.status == 200 ): tradesData = r.read ( ) else: self.logger.write ( 'error fetchData trades http %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error fetchData connection\n' + str(traceback.format_exc()) ) return None lag = time.time() - start # convert to JSON (book,trades) = self.makeJSON ( bookData, tradesData ) if ( (book != None) and (trades != None) ): ed = self.buildData ( book, trades, lag ) if ( ed != None ): ed.timestamp = start return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'BTCE-USD', 'btceUSD', BTCEUSDWatcher )
if (r.status == 200): ticker_txt = r.read() ticker_json = json.loads(ticker_txt) rate = float(ticker_json['result']['XXMRZUSD']['c'][0]) if (rate > 0): self.XMR_USD_rate = rate self.XMR_USD_stamp = time.time() #self.logger.write ( 'rate: %f ' % self.XMR_USD_rate ) else: self.logger.write('error XMR_USD http %d' % r.status) connection.close() except Exception: self.logger.write('error XMR_USD\n' + str(traceback.format_exc())) pass trades = '/0/public/Trades?pair=XXMRXXBT&since=%s' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData( self, httplib.HTTPSConnection, 'api.kraken.com', '/0/public/Depth?pair=XXMRXXBT', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('Kraken-XMR', 'krakenXMR', KrakenXMRWatcher)
r = connection.getresponse() if (r.status == 200): rate_txt = r.read() rate = float(rate_txt.split(',')[1]) if (rate > 0): self.PLN_USD_rate = rate self.PLN_USD_stamp = time.time() #self.logger.write ( 'rate: %f ' % self.PLN_USD_rate ) else: self.logger.write('error: PLN_USD status %d' % r.status) connection.close() except Exception: self.logger.write('error: unable to get PLN/USD\n' + str(traceback.format_exc())) pass ed = coinwatcher.CoinWatcher.fetchData(self, httplib.HTTPSConnection, 'bitcurex.com', '/api/pln/orderbook.json', '/api/pln/trades.json') return ed # # # main program # if __name__ == "__main__": coinwatcher.main('Bitcurex-PLN', 'bitcurexPLN', BitcurexPLNWatcher)
if (mostRecentID != 0): # comes last as line above may fail self.mostRecentTransactionID = mostRecentID ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception as e: self.logger.write('error buildData %s' % e) return None return ed def fetchData(self): trades = '/api/v1/future_trades.do?symbol=ltc_usd&contract_type=next_week' if (self.mostRecentTransactionID > 0): trades = trades + '&since=%d' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData( self, httplib.HTTPSConnection, 'www.okcoin.com', '/api/v1/future_depth.do?symbol=ltc_usd&contract_type=next_week', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('OKCoinltcBiweeklies', 'okcoinbiLTC', OKCoinLTCbiWatcher)
self.mostRecentPrice = mostRecentPrice if ( self.mostRecentPrice == 0 ): self.mostRecentPrice = ed.bids[0][0] if ( mostRecentDate != 0 ): self.mostRecentTransactionID = mostRecentID self.mostRecentTransaction = mostRecentDate ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception: self.logger.write ( 'error: buildData() failed with ticker\n' + str(traceback.format_exc()) ) return None return ed def fetchData ( self ): trades = '/api/1/public/BTCUSD/trades?format_item=object&from=%d&by=ts&sort=desc&max_results=1000&start_index=0' % int ( self.mostRecentTransaction ) ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPConnection, 'api.hitbtc.com', '/api/1/public/BTCUSD/orderbook', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'HitBTC-USD', 'hitbtcUSD', HitBTCUSDWatcher )
try: connection = httplib.HTTPConnection ( 'download.finance.yahoo.com', timeout=5 ) connection.request ( 'GET', '/d/quotes.csv?s=EURUSD=X&f=sl1&e=.csv' ) r = connection.getresponse ( ) if ( r.status == 200 ): rate_txt = r.read ( ) rate = float ( rate_txt.split(',')[1] ) if ( rate > 0 ): self.EUR_USD_rate = rate self.EUR_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.EUR_USD_rate ) else: self.logger.write ( 'error EUR_USD http %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error EUR_USD\n' + str(traceback.format_exc()) ) pass trades = '/0/public/Trades?pair=XXBTZEUR&since=%s' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.kraken.com', '/0/public/Depth?pair=XXBTZEUR', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Kraken-EUR', 'krakenEUR', KrakenEURWatcher )
self.GBP_USD_stamp = time.time() #self.logger.write ( 'rate: %f ' % self.GBP_USD_rate ) else: self.logger.write('error GBP_USD http %d' % r.status) connection.close() except Exception: self.logger.write('error GBP_USD\n' + str(traceback.format_exc())) pass trades = '/products/BTC-GBP/trades' #book = '/products/BTC-GBP/book?level=2' #if ( (time.time() - self.book_stamp) > 30 ): # self.book_fetch_full = True # book = '/products/BTC-GBP/book?level=3' # self.book_stamp = time.time ( ) book = '/products/BTC-GBP/book?level=3' ed = coinwatcher.CoinWatcher.fetchData(self, httplib.HTTPSConnection, 'api.exchange.coinbase.com', book, trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('Coinbase-GBP', 'coinbaseGBP', CoinbaseGBPWatcher)
self.mostRecentPrice = ed.bids[0][0] if (mostRecentID != 0): self.mostRecentTransactionID = mostRecentID self.mostRecentTransaction = mostRecentDate ed.rate = self.mostRecentPrice ed.lag = lag ed.ask_value = ed.asks[0][0] ed.bid_value = ed.bids[0][0] except Exception: self.logger.write('error buildData failed with ticker\n' + str(traceback.format_exc())) return None return ed def fetchData(self): trades = '/v1/trades/BTCUSD?since=%d' % self.mostRecentTransaction ed = coinwatcher.CoinWatcher.fetchData(self, httplib.HTTPSConnection, 'api.gemini.com', '/v1/book/BTCUSD', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('Gemini-USD', 'geminiUSD', GeminiUSDWatcher)
if rate > 0: self.EUR_USD_rate = rate self.EUR_USD_stamp = time.time() # self.logger.write ( 'rate: %f ' % self.EUR_USD_rate ) else: self.logger.write("error: EUR_USD status %d" % r.status) connection.close() except Exception: self.logger.write("error: unable to get EUR/USD\n" + str(traceback.format_exc())) pass trades = "/api/v1/bitcoin_charts/eur/trades?since=%d" % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData( self, httplib.HTTPSConnection, "paymium.com", "/api/v1/bitcoin_charts/eur/depth", trades ) return ed def stop(self): self.logger.write("shutdown last trade ID=%d" % self.mostRecentTransactionID) coinwatcher.CoinWatcher.stop(self) return # # # main program # if __name__ == "__main__": coinwatcher.main("Paymium-EUR", "paymiumEUR", PaymiumEURWatcher)
rate_txt = r.read() rate = float(rate_txt.split(',')[1]) if (rate > 0): self.CNY_USD_rate = 1 / rate self.CNY_USD_stamp = time.time() #self.logger.write ( 'rate: %f ' % self.CNY_USD_rate ) else: self.logger.write('error: CNY_USD status %d' % r.status) connection.close() except Exception: self.logger.write('error: unable to get USD/CNY\n' + str(traceback.format_exc())) pass trades = '/api/v1/trades.do?symbol=btc_cny' if (self.mostRecentTransactionID > 0): trades = trades + '&since=%d' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData( self, httplib.HTTPSConnection, 'www.okcoin.cn', '/api/v1/depth.do?symbol=btc_cny', trades) return ed # # # main program # if __name__ == "__main__": coinwatcher.main('OK-CoinCNY', 'okcoinCNY', OKCoinCNYWatcher)
connection = httplib.HTTPSConnection ( 'api.kraken.com', timeout=5 ) connection.request ( 'GET', '/0/public/Ticker?pair=XLTCZUSD' ) r = connection.getresponse ( ) if ( r.status == 200 ): ticker_txt = r.read ( ) ticker_json = json.loads ( ticker_txt ) rate = float ( ticker_json['result']['XLTCZUSD']['c'][0] ) if ( rate > 0 ): self.LTC_USD_rate = rate self.LTC_USD_stamp = time.time ( ) #self.logger.write ( 'rate: %f ' % self.LTC_USD_rate ) else: self.logger.write ( 'error LTC_USD http %d' % r.status ) connection.close ( ) except Exception: self.logger.write ( 'error LTC_USD\n' + str(traceback.format_exc()) ) pass trades = '/0/public/Trades?pair=XXBTXLTC&since=%s' % self.mostRecentTransactionID ed = coinwatcher.CoinWatcher.fetchData ( self, httplib.HTTPSConnection, 'api.kraken.com', '/0/public/Depth?pair=XXBTXLTC', trades ) return ed # # # main program # if __name__ == "__main__": coinwatcher.main ( 'Kraken-LTC', 'krakenLTC', KrakenLTCWatcher )