def getCurrentPrice(self): c = CampBX(self.config['exchange.campbx.username'], self.config['exchange.campbx.password']) currentPrice = c.xticker() price = [] currentTime = int(time.time()) price.append(currentTime) price.append(float(currentPrice['Last Trade'])) price.append(float(currentPrice['Best Ask'])) price.append(float(currentPrice['Best Bid'])) return price
def campbx_ticker(self): c = CampBX() t = c.xticker() now = time.localtime(time.time()) open = int(time.mktime((now[0], now[1], now[2], 0, 0, 0, now[6], now[7], now[8]))) now = time.time() url = "http://api.bitcoincharts.com/v1/trades.csv?symbol=cbxUSD&start=%d" % open r = self.browser.open(url) opening_price = float(r.readlines()[0].split(',')[1]) current_value = float(t['Last Trade']) change = current_value - opening_price percentage = change / current_value if self.last_cbxusd_market_query is None or \ now - self.last_cbxusd_market_query_ts > 15*60*60: url = "http://api.bitcoincharts.com/v1/markets.json" r = self.browser.open(url) js = json.loads(r.read()) for market in js: if market['symbol'].upper() == 'CBXUSD': self.last_cbxusd_market_query = market self.last_cbxusd_market_query_ts = now break volume = "(unknown)" if self.last_cbxusd_market_query is not None: v = float(self.last_cbxusd_market_query['volume']) volume = "%.2f BTC" % v sym = { 'n' : 'CAMPBX', 'l1' : "%.02f" % current_value, 'c6' : "%+.02f" % change, 'p2' : "%+.02f%%" % (percentage * 100), 'btc' : volume, } return sym
def campbx_ticker(self): c = CampBX() t = c.xticker() now = time.localtime(time.time()) open = int( time.mktime( (now[0], now[1], now[2], 0, 0, 0, now[6], now[7], now[8]))) now = time.time() url = "http://api.bitcoincharts.com/v1/trades.csv?symbol=cbxUSD&start=%d" % open r = self.browser.open(url) opening_price = float(r.readlines()[0].split(',')[1]) current_value = float(t['Last Trade']) change = current_value - opening_price percentage = change / current_value if self.last_cbxusd_market_query is None or \ now - self.last_cbxusd_market_query_ts > 15*60*60: url = "http://api.bitcoincharts.com/v1/markets.json" r = self.browser.open(url) js = json.loads(r.read()) for market in js: if market['symbol'].upper() == 'CBXUSD': self.last_cbxusd_market_query = market self.last_cbxusd_market_query_ts = now break volume = "(unknown)" if self.last_cbxusd_market_query is not None: v = float(self.last_cbxusd_market_query['volume']) volume = "%.2f BTC" % v sym = { 'n': 'CAMPBX', 'l1': "%.02f" % current_value, 'c6': "%+.02f" % change, 'p2': "%+.02f%%" % (percentage * 100), 'btc': volume, } return sym