예제 #1
0
 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
     orders_sell = util.get_orders(db,
                                   validity='valid',
                                   show_empty=False,
                                   show_expired=False,
                                   filters=[{
                                       'field': 'give_asset',
                                       'op': '==',
                                       'value': 'CHA'
                                   }, {
                                       'field': 'get_asset',
                                       'op': '==',
                                       'value': 'BTC'
                                   }])
     orders_buy = util.get_orders(db,
                                  validity='valid',
                                  show_empty=False,
                                  show_expired=False,
                                  filters=[{
                                      'field': 'get_asset',
                                      'op': '==',
                                      'value': 'CHA'
                                  }, {
                                      'field': 'give_asset',
                                      'op': '==',
                                      'value': 'BTC'
                                  }])
     orders_sell = sorted(order_tuples(orders_sell),
                          key=lambda tup: tup[1],
                          reverse=True)
     orders_buy = sorted(order_tuples(orders_buy),
                         key=lambda tup: tup[1],
                         reverse=True)
     my_orders = None
     my_order_matches = None
     balance = None
     self.render("wallet.html",
                 db_updated=db_updated,
                 bitcoin_updated=bitcoin_updated,
                 version_updated=version_updated,
                 wallet=None,
                 orders_buy=orders_buy,
                 orders_sell=orders_sell,
                 info=info,
                 error=error,
                 block_count_db=block_count_db,
                 block_count_bitcoin=block_count_bitcoin,
                 balance=balance,
                 my_orders=my_orders,
                 my_order_matches=my_order_matches)
예제 #2
0
 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
     orders_sell = util.get_orders(db, validity='valid', show_empty=False, show_expired=False, filters=[{'field': 'give_asset', 'op': '==', 'value': 'CHA'},{'field': 'get_asset', 'op': '==', 'value': 'BTC'}])
     orders_buy = util.get_orders(db, validity='valid', show_empty=False, show_expired=False, filters=[{'field': 'get_asset', 'op': '==', 'value': 'CHA'},{'field': 'give_asset', 'op': '==', 'value': 'BTC'}])
     orders_sell = sorted(order_tuples(orders_sell), key=lambda tup: tup[1], reverse=True)
     orders_buy = sorted(order_tuples(orders_buy), key=lambda tup: tup[1], reverse=True)
     my_orders = None
     my_order_matches = None
     balance = None
     self.render("wallet.html", db_updated = db_updated, bitcoin_updated = bitcoin_updated, version_updated = version_updated, wallet = None, orders_buy = orders_buy, orders_sell = orders_sell, info = info, error = error, block_count_db = block_count_db, block_count_bitcoin = block_count_bitcoin, balance = balance, my_orders = my_orders, my_order_matches = my_order_matches)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
def depth (give_asset, get_asset, title = "Open Orders" ):
    # Open orders.
    orders = util.get_orders(db, validity='Valid', show_expired=False, show_empty=False)
    table = PrettyTable(['Give Quantity', 'Give Asset', 'Price', 'Price Assets', 'Fee (BTC)', '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(title)
    table = table.get_string(sortby='Price')
    if os.name == 'nt':
        table = windows(table)
    print(table)
    print('\n')
예제 #8
0
 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
     orders_sell = util.get_orders(db, validity='valid', show_empty=False, show_expired=False, filters=[{'field': 'give_asset', 'op': '==', 'value': 'CHA'},{'field': 'get_asset', 'op': '==', 'value': 'BTC'}])
     orders_buy = util.get_orders(db, validity='valid', show_empty=False, show_expired=False, filters=[{'field': 'get_asset', 'op': '==', 'value': 'CHA'},{'field': 'give_asset', 'op': '==', 'value': 'BTC'}])
     orders_sell = sorted(order_tuples(orders_sell), key=lambda tup: tup[1], reverse=True)
     orders_buy = sorted(order_tuples(orders_buy), key=lambda tup: tup[1], reverse=True)
     my_orders = None
     my_order_matches = None
     balance = None
     if self.get_argument("form")=="balance":
         address = self.get_argument("address")
         try:
             wallet = util.get_address(db, address = address)
         except:
             wallet = None
         balance = None
         if wallet != None:
             for balance in wallet['balances']:
                 if balance['asset']=='CHA':
                     balance = util.devise(db, balance['amount'], 'CHA', 'output')
     elif self.get_argument("form")=="my_orders":
         address = self.get_argument("address")
         try:
             my_orders = util.get_orders(db, validity='valid', show_empty=False, show_expired=False, source=address)
             my_orders = order_tuples(my_orders)
             my_order_matches = util.get_order_matches(db, validity='pending', is_mine=True, address=address)
             my_order_matches = order_match_tuples(my_order_matches)
         except:
             my_orders = None
             my_order_matches = None
     elif self.get_argument("form")=="btcpay":
         order_match_id = self.get_argument("order_match_id")
         try:
             tx_hex = btcpay.create(db, order_match_id, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "BTC payment successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form")=="cancel":
         tx_hash = self.get_argument("tx_hash")
         try:
             tx_hex = cancel.create(db, tx_hash, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Cancel successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form")=="send":
         source = self.get_argument("source")
         destination = self.get_argument("destination")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA', 'input')
         try:
             tx_hex = send.create(db, source, destination, quantity, 'CHA', unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Send successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form")=="burn":
         source = self.get_argument("source")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA', 'input')
         try:
             tx_hex = burn.create(db, source, quantity, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Burn successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form")=="buy":
         source = self.get_argument("source")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA', 'input')
         price = util.devise(db, self.get_argument("price"), 'value', 'input')
         pricetimesquantity = float(self.get_argument("quantity"))*float(self.get_argument("price"))
         pricetimesquantity = int(pricetimesquantity*config.UNIT)
         expiration = 6 * 24 #24 hour order
         try:
             tx_hex = order.create(db, source, 'BTC', pricetimesquantity, 'CHA', quantity,
                                        expiration, 0, config.MIN_FEE, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Buy order successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form")=="sell":
         source = self.get_argument("source")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA', 'input')
         price = util.devise(db, self.get_argument("price"), 'value', 'input')
         pricetimesquantity = float(self.get_argument("quantity"))*float(self.get_argument("price"))
         pricetimesquantity = int(pricetimesquantity*config.UNIT)
         expiration = 6 * 24 #24 hour order
         try:
             tx_hex = order.create(db, source, 'CHA', quantity, 'BTC', pricetimesquantity,
                                            expiration, 0, config.MIN_FEE, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Sell order successful"
         except:
             error = sys.exc_info()[1]
     self.render("wallet.html", db_updated = db_updated, bitcoin_updated = bitcoin_updated, version_updated = version_updated, orders_buy = orders_buy, orders_sell = orders_sell, info = info, error = error, block_count_db = block_count_db, block_count_bitcoin = block_count_bitcoin, balance = balance, my_orders = my_orders, my_order_matches = my_order_matches)
예제 #9
0
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
예제 #10
0
 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
     orders_sell = util.get_orders(db,
                                   validity='valid',
                                   show_empty=False,
                                   show_expired=False,
                                   filters=[{
                                       'field': 'give_asset',
                                       'op': '==',
                                       'value': 'CHA'
                                   }, {
                                       'field': 'get_asset',
                                       'op': '==',
                                       'value': 'BTC'
                                   }])
     orders_buy = util.get_orders(db,
                                  validity='valid',
                                  show_empty=False,
                                  show_expired=False,
                                  filters=[{
                                      'field': 'get_asset',
                                      'op': '==',
                                      'value': 'CHA'
                                  }, {
                                      'field': 'give_asset',
                                      'op': '==',
                                      'value': 'BTC'
                                  }])
     orders_sell = sorted(order_tuples(orders_sell),
                          key=lambda tup: tup[1],
                          reverse=True)
     orders_buy = sorted(order_tuples(orders_buy),
                         key=lambda tup: tup[1],
                         reverse=True)
     my_orders = None
     my_order_matches = None
     balance = None
     if self.get_argument("form") == "balance":
         address = self.get_argument("address")
         try:
             wallet = util.get_address(db, address=address)
         except:
             wallet = None
         balance = None
         if wallet != None:
             for balance in wallet['balances']:
                 if balance['asset'] == 'CHA':
                     balance = util.devise(db, balance['amount'], 'CHA',
                                           'output')
     elif self.get_argument("form") == "my_orders":
         address = self.get_argument("address")
         try:
             my_orders = util.get_orders(db,
                                         validity='valid',
                                         show_empty=False,
                                         show_expired=False,
                                         source=address)
             my_orders = order_tuples(my_orders)
             my_order_matches = util.get_order_matches(db,
                                                       validity='pending',
                                                       is_mine=True,
                                                       address=address)
             my_order_matches = order_match_tuples(my_order_matches)
         except:
             my_orders = None
             my_order_matches = None
     elif self.get_argument("form") == "btcpay":
         order_match_id = self.get_argument("order_match_id")
         try:
             tx_hex = btcpay.create(db, order_match_id, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "BTC payment successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form") == "cancel":
         tx_hash = self.get_argument("tx_hash")
         try:
             tx_hex = cancel.create(db, tx_hash, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Cancel successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form") == "send":
         source = self.get_argument("source")
         destination = self.get_argument("destination")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA',
                                'input')
         try:
             tx_hex = send.create(db,
                                  source,
                                  destination,
                                  quantity,
                                  'CHA',
                                  unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Send successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form") == "burn":
         source = self.get_argument("source")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA',
                                'input')
         try:
             tx_hex = burn.create(db, source, quantity, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Burn successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form") == "buy":
         source = self.get_argument("source")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA',
                                'input')
         price = util.devise(db, self.get_argument("price"), 'value',
                             'input')
         pricetimesquantity = float(self.get_argument("quantity")) * float(
             self.get_argument("price"))
         pricetimesquantity = int(pricetimesquantity * config.UNIT)
         expiration = 6 * 24  #24 hour order
         try:
             tx_hex = order.create(db,
                                   source,
                                   'BTC',
                                   pricetimesquantity,
                                   'CHA',
                                   quantity,
                                   expiration,
                                   0,
                                   config.MIN_FEE,
                                   unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Buy order successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form") == "sell":
         source = self.get_argument("source")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA',
                                'input')
         price = util.devise(db, self.get_argument("price"), 'value',
                             'input')
         pricetimesquantity = float(self.get_argument("quantity")) * float(
             self.get_argument("price"))
         pricetimesquantity = int(pricetimesquantity * config.UNIT)
         expiration = 6 * 24  #24 hour order
         try:
             tx_hex = order.create(db,
                                   source,
                                   'CHA',
                                   quantity,
                                   'BTC',
                                   pricetimesquantity,
                                   expiration,
                                   0,
                                   config.MIN_FEE,
                                   unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Sell order successful"
         except:
             error = sys.exc_info()[1]
     self.render("wallet.html",
                 db_updated=db_updated,
                 bitcoin_updated=bitcoin_updated,
                 version_updated=version_updated,
                 orders_buy=orders_buy,
                 orders_sell=orders_sell,
                 info=info,
                 error=error,
                 block_count_db=block_count_db,
                 block_count_bitcoin=block_count_bitcoin,
                 balance=balance,
                 my_orders=my_orders,
                 my_order_matches=my_order_matches)
예제 #11
0
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