def post(self): db_updated = yield tornado.gen.Task(is_db_updated) bitcoin_updated = yield tornado.gen.Task(is_bitcoin_updated) version_updated = yield tornado.gen.Task(is_version_updated) block_count_db, block_count_bitcoin = yield tornado.gen.Task(get_status) info = None error = None bets = util.get_bets(db, order_by='tx_index', validity='valid') bets = bet_tuples(bets[:100]) my_bets = [] supply = util.devise(db, util.cha_supply(db), 'CHA', 'output') max_profit = float(supply)*config.MAX_PROFIT if self.get_argument("form")=="roll" and self.get_argument("source") and self.get_argument("bet") and self.get_argument("payout") and self.get_argument("chance"): source = self.get_argument("source") bet_amount = util.devise(db, self.get_argument("bet"), 'CHA', 'input') chance = util.devise(db, self.get_argument("chance"), 'value', 'input') payout = util.devise(db, self.get_argument("payout"), 'value', 'input') try: tx_hex = bet.create(db, source, bet_amount, chance, payout, unsigned=False) bitcoin.transmit(tx_hex, ask=False) info = "Thanks for betting!" except: error = sys.exc_info()[1] elif self.get_argument("form")=="my_bets" and self.get_argument("address"): try: my_bets = util.get_bets(db, source = self.get_argument("address"), order_by='tx_index', validity='valid') my_bets = bet_tuples(my_bets) except: my_bets = [] self.render("casino.html", db_updated = db_updated, bitcoin_updated = bitcoin_updated, version_updated = version_updated, bets = bets, my_bets = my_bets, supply = supply, house_edge = config.HOUSE_EDGE, max_profit = max_profit, info = info, error = error, block_count_db = block_count_db, block_count_bitcoin = block_count_bitcoin)
def post(self): db_updated = yield tornado.gen.Task(is_db_updated) bitcoin_updated = yield tornado.gen.Task(is_bitcoin_updated) version_updated = yield tornado.gen.Task(is_version_updated) block_count_db, block_count_bitcoin = yield tornado.gen.Task( get_status) info = None error = None bets = util.get_bets(db, order_by='tx_index', validity='valid') bets = bet_tuples(bets[:100]) my_bets = [] supply = util.devise(db, util.cha_supply(db), 'CHA', 'output') max_profit = float(supply) * config.MAX_PROFIT if self.get_argument("form") == "roll" and self.get_argument( "source") and self.get_argument("bet") and self.get_argument( "payout") and self.get_argument("chance"): source = self.get_argument("source") bet_amount = util.devise(db, self.get_argument("bet"), 'CHA', 'input') chance = util.devise(db, self.get_argument("chance"), 'value', 'input') payout = util.devise(db, self.get_argument("payout"), 'value', 'input') try: tx_hex = bet.create(db, source, bet_amount, chance, payout, unsigned=False) bitcoin.transmit(tx_hex, ask=False) info = "Thanks for betting!" except: error = sys.exc_info()[1] elif self.get_argument("form") == "my_bets" and self.get_argument( "address"): try: my_bets = util.get_bets(db, source=self.get_argument("address"), order_by='tx_index', validity='valid') my_bets = bet_tuples(my_bets) except: my_bets = [] self.render("casino.html", db_updated=db_updated, bitcoin_updated=bitcoin_updated, version_updated=version_updated, bets=bets, my_bets=my_bets, supply=supply, house_edge=config.HOUSE_EDGE, max_profit=max_profit, info=info, error=error, block_count_db=block_count_db, block_count_bitcoin=block_count_bitcoin)
def get(self): db_updated = yield tornado.gen.Task(is_db_updated) bitcoin_updated = yield tornado.gen.Task(is_bitcoin_updated) version_updated = yield tornado.gen.Task(is_version_updated) block_count_db, block_count_bitcoin = yield tornado.gen.Task( get_status) info = None error = None bets = util.get_bets(db, order_by='tx_index', validity='valid') bets = bet_tuples(bets[:100]) my_bets = [] supply = util.devise(db, util.cha_supply(db), 'CHA', 'output') max_profit = float(supply) * config.MAX_PROFIT self.render("casino.html", db_updated=db_updated, bitcoin_updated=bitcoin_updated, version_updated=version_updated, bets=bets, my_bets=my_bets, supply=supply, house_edge=config.HOUSE_EDGE, max_profit=max_profit, info=info, error=error, block_count_db=block_count_db, block_count_bitcoin=block_count_bitcoin)
def market (give_asset, get_asset): # TODO: Regularly check if DB is up‐to‐date. (Just use API?!) os.system('cls' if os.name=='nt' else 'clear') # Open orders. orders = util.get_orders(db, validity='Valid', show_expired=False, show_empty=False) table = PrettyTable(['Give Quantity', 'Give Asset', 'Get Quantity', 'Get Asset', 'Price', 'Price Assets', 'Fee', 'Time Left', 'Tx Hash']) for order in orders: if give_asset and order['give_asset'] != give_asset: continue if get_asset and order['get_asset'] != get_asset: continue order = format_order(order) table.add_row(order) print('Open Orders') print(str(table.get_string(sortby='Price'))) print('\n') # Open bets. bets = util.get_bets(db, validity='Valid', show_empty=False) table = PrettyTable(['Bet Type', 'Feed Address', 'Deadline', 'Target Value', 'Leverage', 'Wager', 'Counterwager', 'Odds', 'Time Left', 'Tx Hash']) for bet in bets: bet = format_bet(bet) table.add_row(bet) print('Open Bets') print(str(table)) print('\n') # Matched orders awaiting BTC payments from you. awaiting_btcs = util.get_order_matches(db, validity='Valid: awaiting BTC payment', is_mine=True) table = PrettyTable(['Matched Order ID', 'Time Left']) for order_match in awaiting_btcs: order_match = format_order_match(order_match) table.add_row(order_match) print('Order Matches Awaiting BTC Payment') print(str(table)) print('\n') # Feeds broadcasts = util.get_broadcasts(db, validity='Valid', order_by='timestamp', order_dir='desc') table = PrettyTable(['Feed Address', 'Timestamp', 'Text', 'Value', 'Fee Multiplier']) seen_addresses = [] for broadcast in broadcasts: # Always show only the latest broadcast from a feed address. if broadcast['source'] not in seen_addresses: feed = format_feed(broadcast) table.add_row(feed) seen_addresses.append(broadcast['source']) else: continue print('Feeds') print(str(table)) time.sleep(30)
def market (give_asset, get_asset): # TODO: Regularly check if DB is up‐to‐date. os.system('cls' if os.name=='nt' else 'clear') # Open orders. orders = util.get_orders(db, validity='Valid', show_expired=False, show_empty=False) table = PrettyTable(['Give Quantity', 'Give Asset', 'Get Quantity', 'Get Asset', 'Price', 'Price Assets', 'Fee', 'Time Left', 'Tx Hash']) for order in orders: if give_asset and order['give_asset'] != give_asset: continue if get_asset and order['get_asset'] != get_asset: continue order = format_order(order) table.add_row(order) print('Open Orders') print(str(table.get_string(sortby='Price'))) print('\n') # Open bets. bets = util.get_bets(db, validity='Valid', show_empty=False) table = PrettyTable(['Bet Type', 'Feed Address', 'Deadline', 'Target Value', 'Leverage', 'Wager', 'Counterwager', 'Odds', 'Time Left', 'Tx Hash']) for bet in bets: bet = format_bet(bet) table.add_row(bet) print('Open Bets') print(str(table)) print('\n') # Matched orders awaiting BTC payments from you. awaiting_btcs = util.get_order_matches(db, validity='Valid: awaiting BTC payment', is_mine=True) table = PrettyTable(['Matched Order ID', 'Time Left']) for order_match in awaiting_btcs: order_match = format_order_match(order_match) table.add_row(order_match) print('Order Matches Awaiting BTC Payment') print(str(table)) print('\n') # Feeds broadcasts = util.get_broadcasts(db, validity='Valid', order_by='timestamp', order_dir='desc') table = PrettyTable(['Feed Address', 'Timestamp', 'Text', 'Value', 'Fee Multiplier']) seen_addresses = [] for broadcast in broadcasts: # Always show only the latest broadcast from a feed address. if broadcast['source'] not in seen_addresses: feed = format_feed(broadcast) table.add_row(feed) seen_addresses.append(broadcast['source']) else: continue print('Feeds') print(str(table)) time.sleep(30)
def market (give_asset, get_asset): # Your Pending Orders Matches. awaiting_btcs = util.get_order_matches(db, status='pending', is_mine=True) table = PrettyTable(['Matched Order ID', 'Time Left']) for order_match in awaiting_btcs: order_match = format_order_match(db, order_match) table.add_row(order_match) print('Your Pending Order Matches') print(table) print('\n') # Open orders. orders = util.get_orders(db, status='valid', show_expired=False, show_empty=False) table = PrettyTable(['Give Quantity', 'Give Asset', 'Price', 'Price Assets', 'Required BTC Fee', 'Provided BTC Fee', 'Time Left', 'Tx Hash']) for order in orders: if give_asset and order['give_asset'] != give_asset: continue if get_asset and order['get_asset'] != get_asset: continue order = format_order(order) table.add_row(order) print('Open Orders') table = table.get_string(sortby='Price') print(table) print('\n') # Open bets. bets = util.get_bets(db, status='valid', show_empty=False) table = PrettyTable(['Bet Type', 'Feed Address', 'Deadline', 'Target Value', 'Leverage', 'Wager', 'Odds', 'Time Left', 'Tx Hash']) for bet in bets: bet = format_bet(bet) table.add_row(bet) print('Open Bets') print(table) print('\n') # Feeds broadcasts = util.get_broadcasts(db, status='valid', order_by='timestamp', order_dir='desc') table = PrettyTable(['Feed Address', 'Timestamp', 'Text', 'Value', 'Fee Fraction']) seen_addresses = [] for broadcast in broadcasts: # Only show feeds with broadcasts in the last two weeks. last_block_time = util.last_block(db)['block_time'] if broadcast['timestamp'] + config.TWO_WEEKS < last_block_time: continue # Always show only the latest broadcast from a feed address. if broadcast['source'] not in seen_addresses: feed = format_feed(broadcast) table.add_row(feed) seen_addresses.append(broadcast['source']) else: continue print('Feeds') print(table)
def market (give_asset, get_asset): # Your Pending Orders Matches. awaiting_btcs = util.get_order_matches(db, status='pending', is_mine=True) table = PrettyTable(['Matched Order ID', 'Time Left']) for order_match in awaiting_btcs: order_match = format_order_match(db, order_match) table.add_row(order_match) print('Your Pending Order Matches') print(table) print('\n') # Open orders. orders = util.get_orders(db, status='open', show_expired=False) table = PrettyTable(['Give Quantity', 'Give Asset', 'Price', 'Price Assets', 'Required BTC Fee', 'Provided BTC Fee', 'Time Left', 'Tx Hash']) for order in orders: if give_asset and order['give_asset'] != give_asset: continue if get_asset and order['get_asset'] != get_asset: continue order = format_order(order) table.add_row(order) print('Open Orders') table = table.get_string(sortby='Price') print(table) print('\n') # Open bets. bets = util.get_bets(db, status='open') table = PrettyTable(['Bet Type', 'Feed Address', 'Deadline', 'Target Value', 'Leverage', 'Wager', 'Odds', 'Time Left', 'Tx Hash']) for bet in bets: bet = format_bet(bet) table.add_row(bet) print('Open Bets') print(table) print('\n') # Feeds broadcasts = util.get_broadcasts(db, status='valid', order_by='timestamp', order_dir='desc') table = PrettyTable(['Feed Address', 'Timestamp', 'Text', 'Value', 'Fee Fraction']) seen_addresses = [] for broadcast in broadcasts: # Only show feeds with broadcasts in the last two weeks. last_block_time = util.last_block(db)['block_time'] if broadcast['timestamp'] + config.TWO_WEEKS < last_block_time: continue # Always show only the latest broadcast from a feed address. if broadcast['source'] not in seen_addresses: feed = format_feed(broadcast) table.add_row(feed) seen_addresses.append(broadcast['source']) else: continue print('Feeds') print(table)
def get(self): db_updated = yield tornado.gen.Task(is_db_updated) bitcoin_updated = yield tornado.gen.Task(is_bitcoin_updated) version_updated = yield tornado.gen.Task(is_version_updated) block_count_db, block_count_bitcoin = yield tornado.gen.Task(get_status) info = None error = None bets = util.get_bets(db, order_by='tx_index', validity='valid') bets = bet_tuples(bets[:100]) my_bets = [] supply = util.devise(db, util.cha_supply(db), 'CHA', 'output') max_profit = float(supply)*config.MAX_PROFIT self.render("casino.html", db_updated = db_updated, bitcoin_updated = bitcoin_updated, version_updated = version_updated, bets = bets, my_bets = my_bets, supply = supply, house_edge = config.HOUSE_EDGE, max_profit = max_profit, info = info, error = error, block_count_db = block_count_db, block_count_bitcoin = block_count_bitcoin)
def market (give_asset, get_asset, depthonly=False): # Open Orders if depthonly: depth(give_asset,get_asset,"Open Orders to Give " + give_asset + ", Get " + get_asset + " (Bids)") depth(get_asset,give_asset,"Open Orders to Give " + get_asset + ", Get " + give_asset + " (Offers)") else: depth(give_asset,get_asset) # Open bets. bets = util.get_bets(db, validity='Valid', show_empty=False) table = PrettyTable(['Bet Type', 'Feed Address', 'Deadline', 'Target Value', 'Leverage', 'Wager', 'Odds', 'Time Left', 'Tx Hash']) for bet in bets: bet = format_bet(bet) table.add_row(bet) print('Open Bets') if os.name == 'nt': table = windows(table.get_string()) print(table) print('\n') # Feeds broadcasts = util.get_broadcasts(db, validity='Valid', order_by='timestamp', order_dir='desc') table = PrettyTable(['Feed Address', 'Timestamp', 'Text', 'Value', 'Fee Multiplier']) seen_addresses = [] for broadcast in broadcasts: # Only show feeds with broadcasts in the last two weeks. last_block_time = util.last_block(db)['block_time'] if broadcast['timestamp'] + config.TWO_WEEKS < last_block_time: continue # Always show only the latest broadcast from a feed address. if broadcast['source'] not in seen_addresses: feed = format_feed(broadcast) table.add_row(feed) seen_addresses.append(broadcast['source']) else: continue print('Feeds') if os.name == 'nt': table = windows(table.get_string()) print(table) # Matched orders awaiting BTC payments from you. awaiting_btcs = util.get_order_matches(db, validity='Valid: awaiting BTC payment', is_mine=True) table = PrettyTable(['Matched Order ID', 'Time Left']) for order_match in awaiting_btcs: order_match = format_order_match(db, order_match) table.add_row(order_match) print('Order Matches Awaiting BTC Payment from You') if os.name == 'nt': table = windows(table.get_string()) print(table) print('\n')
def get_address (db, address, start_block=None, end_block=None): address_dict = {} address_dict['balances'] = util.get_balances(db, address=address) address_dict['debits'] = util.get_debits(db, address=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['credits'] = util.get_credits(db, address=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['burns'] = util.get_burns(db, source=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['sends'] = util.get_sends(db, source=address, destination=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block, filterop='or') #^ with filterop == 'or', we get all sends where this address was the source OR destination address_dict['orders'] = util.get_orders(db, source=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['order_matches'] = util.get_order_matches(db, address=address, order_by='tx0_block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['btcpays'] = util.get_btcpays(db, filters=[{'field': 'source', 'op': '==', 'value': address}, {'field': 'destination', 'op': '==', 'value': address}], filterop='or', order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['issuances'] = util.get_issuances(db, issuer=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['broadcasts'] = util.get_broadcasts(db, source=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['bets'] = util.get_bets(db, source=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['bet_matches'] = util.get_bet_matches(db, address=address, order_by='tx0_block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['dividends'] = util.get_dividends(db, source=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['cancels'] = util.get_cancels(db, source=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['callbacks'] = util.get_callbacks(db, source=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['bet_expirations'] = util.get_bet_expirations(db, source=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['order_expirations'] = util.get_order_expirations(db, source=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['bet_match_expirations'] = util.get_bet_match_expirations(db, address=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) address_dict['order_match_expirations'] = util.get_order_match_expirations(db, address=address, order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block) return address_dict