def get_bets (validity=None, address=None, show_empty=True, show_expired=True): db = sqlite3.connect(config.DATABASE) db.row_factory = sqlite3.Row cursor = db.cursor() cursor.execute('''SELECT * FROM bets ORDER BY odds DESC, tx_index''') block_count = bitcoin.rpc('getblockcount', [])['result'] bets = [] for bet in cursor.fetchall(): if validity and bet['Validity'] != validity: continue if not show_empty and not bet['wager_remaining']: continue if address and bet['source'] != address: continue time_left = util.get_time_left(bet) if not show_expired and time_left < 0: continue bets.append(dict(bet)) cursor.close() return bets
def format_order (order): price = D(order['get_amount']) / D(order['give_amount']) give_remaining = util.devise(D(order['give_remaining']), order['give_id'], 'output') get_remaining = util.devise(give_remaining * price, order['get_id'], 'ouput') give_name = util.get_asset_name(order['give_id']) get_name = util.get_asset_name(order['get_id']) give = str(give_remaining) + ' ' + give_name get = str(round(get_remaining, 8)) + ' ' + get_name price_string = str(price.quantize(config.FOUR).normalize()) price_string += ' ' + get_name + '/' + give_name if order['fee_required']: fee = str(order['fee_required'] / config.UNIT) + ' BTC (required)' else: fee = str(order['fee_provided'] / config.UNIT) + ' BTC (provided)' return [give, get, price_string, fee, util.get_time_left(order), util.short(order['tx_hash'])]
def get_orders (validity=None, address=None, show_empty=True, show_expired=True): db = sqlite3.connect(config.DATABASE) db.row_factory = sqlite3.Row cursor = db.cursor() cursor.execute('''SELECT * FROM orders ORDER BY price ASC, tx_index''') block_count = bitcoin.rpc('getblockcount', [])['result'] orders = [] for order in cursor.fetchall(): if validity and order['Validity'] != validity: continue if not show_empty and not order['give_remaining']: continue if address and order['source'] != address: continue # Ignore BTC orders one block early. time_left = util.get_time_left(order) if not show_expired and not ((time_left > 0 and order['give_id'] and order['get_id']) or time_left > 1): continue orders.append(dict(order)) cursor.close() return orders
def format_bet (bet): odds = D(bet['counterwager_amount']) / D(bet['wager_amount']) wager_remaining = D(bet['wager_remaining']) counterwager_remaining = round(wager_remaining * odds) if not bet['target_value']: target_value = None else: target_value = bet['target_value'] if not bet['leverage']: leverage = None else: leverage = util.devise(db, D(bet['leverage']) / 5040, 'leverage', 'output') return [util.BET_TYPE_NAME[bet['bet_type']], bet['feed_address'], util.isodt(bet['deadline']), target_value, leverage, str(wager_remaining / config.UNIT) + ' XCP', str(counterwager_remaining / config.UNIT) + ' XCP', util.devise(db, odds, 'odds', 'output'), util.get_time_left(bet), util.short(bet['tx_hash'])]
def format_order (order): give_remaining = util.devise(db, D(order['give_remaining']), order['give_asset'], 'output') get_remaining = util.devise(db, round(D(order['give_remaining']) * D(order['price'])), order['get_asset'], 'output') give_asset = order['give_asset'] get_asset = order['get_asset'] if get_asset < give_asset: price = util.devise(db, D(get_remaining) / D(give_remaining), 'price', 'output') price_assets = get_asset + '/' + give_asset else: price = util.devise(db, D(give_remaining) / D(get_remaining), 'price', 'output') price_assets = give_asset + '/' + get_asset if order['fee_required']: fee = str(order['fee_required'] / config.UNIT) else: fee = str(order['fee_provided'] / config.UNIT) return [D(give_remaining), give_asset, D(get_remaining), get_asset, price, price_assets, fee, util.get_time_left(order), util.short(order['tx_hash'])]
def format_bet (bet): odds = D(bet['counterwager_amount']) / D(bet['wager_amount']) wager_remaining = D(bet['wager_remaining']) counterwager_remaining = round(wager_remaining * odds) if not bet['threshold']: threshold = None else: threshold = bet['threshold'] if not bet['leverage']: leverage = None else: leverage = D(D(bet['leverage']) / 5040).quantize(config.FOUR).normalize() return [util.BET_TYPE_NAME[bet['bet_type']], bet['feed_address'], bet['deadline'], threshold, leverage, str(wager_remaining / config.UNIT) + ' XCP', str(counterwager_remaining / config.UNIT) + ' XCP', odds.quantize(config.FOUR).normalize(), util.get_time_left(bet), util.short(bet['tx_hash'])]
def format_order (order): give_remaining = util.devise(db, D(order['give_remaining']), order['give_asset'], 'output') get_remaining = util.devise(db, round(D(order['give_remaining']) * D(order['price'])), order['get_asset'], 'output') give_asset = order['give_asset'] get_asset = order['get_asset'] price = util.devise(db, D(get_remaining) / D(give_remaining), 'price', 'output') price_assets = get_asset + '/' + give_asset if order['fee_required']: fee = str(order['fee_required'] / config.UNIT) else: fee = str(order['fee_provided'] / config.UNIT) return [give_remaining, give_asset, get_remaining, get_asset, price, price_assets, fee, util.get_time_left(order), util.short(order['tx_hash'])]
def format_order (order): price = D(order['get_amount']) / D(order['give_amount']) give_remaining = util.devise(db, D(order['give_remaining']), order['give_asset'], 'output') get_remaining = D(give_remaining) * price give_asset = order['give_asset'] get_asset = order['get_asset'] price = util.devise(db, get_remaining / D(give_remaining), 'price', 'output') price_assets = get_asset + '/' + give_asset if order['fee_required']: fee = str(order['fee_required'] / config.UNIT) else: fee = str(order['fee_provided'] / config.UNIT) return [give_remaining, give_asset, get_remaining, get_asset, price, price_assets, fee, util.get_time_left(order), util.short(order['tx_hash'])]