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
import time from decimal import Decimal import decimal decimal.getcontext().prec = 2 import logging logger = logging.getLogger('localbitcoins') from campbx import CampBX import book import config c = CampBX(config.username, config.password) def usd_balance(): return (u'Liquid USD' in c.my_funds() or None) and Decimal( c.my_funds()[u'Liquid USD']) def ticker(): return c.xticker() def market_buy(usd): old_balance = usd_balance() fee = Decimal('1') - ( Decimal('1') / (Decimal('1') + config.account_deposit_fee + config.market_order_fee)) usd_to_exchange = Decimal(usd) * (Decimal('1') - fee)