Ejemplo n.º 1
0
def decodeOrder(request, dbsession, order):
    entityObj =dbsession.query(Entity).filter(Entity.id==order.entity_id).one()
    entityDict = {'name': entityObj.name, 'url': sm_url.formEntityURI(request, entityObj)}
    userObj = dbsession.query(User).filter(User.id == order.user_id).one()
    userDict = {'id': userObj.id, 'name': userObj.name, 'url': route_url('user', request, user=userObj.name)}
    transactions = dbsession.query(Transaction).filter(or_(Transaction.buy_order_id == order.id, Transaction.sell_order_id == order.id)).all()
    transactionList = decodeTransactionList(request, dbsession, transactions)
    return {'id': order.id, 'quantity': order.quantity, 'minPrice': float(order.minPrice), 'maxPrice': float(order.maxPrice), 'buyorsell': order.buyOrSell, 'timestamp': str(order.timestamp), 'entity':entityDict, 'url': route_url('order', request, order=order.id), 'user': userDict, 'transactions': transactionList}
Ejemplo n.º 2
0
def decodeTransaction(request, dbsession, transaction):
    entityObj =dbsession.query(Entity).filter(Entity.id==transaction.entity_id).one()
    entityDict = {'name': entityObj.name, 'url': sm_url.formEntityURI(request, entityObj)}
    if transaction.from_user_id==None: buyerDict = {'id': '', 'name': 'Free shares', 'url': ''}
    else:
        buyerObj = dbsession.query(User).filter(User.id == transaction.from_user_id).one()
        buyerDict = {'id': buyerObj.id, 'name': buyerObj.name, 'url': route_url('user', request, user=buyerObj.name)}
    sellerObj = dbsession.query(User).filter(User.id == transaction.to_user_id).one()
    sellerDict = {'id': sellerObj.id, 'name': sellerObj.name, 'url': route_url('user', request, user=sellerObj.name)}
    buyOrderDict = {'id': transaction.buy_order_id, 'url': route_url('order', request, order=transaction.buy_order_id)}
    sellOrderDict = {'id': transaction.sell_order_id, 'url': route_url('order', request, order=transaction.sell_order_id)}
    return {'id': transaction.id, 'timestamp': str(transaction.timestamp), 'entity': entityDict, 'quantity': transaction.quantity, 'price': str(transaction.price), 'buyer': buyerDict, 'seller': sellerDict, 'buyOrder': buyOrderDict, 'sellOrder': sellOrderDict, 'url': route_url('transaction', request, transaction=transaction.id)}
Ejemplo n.º 3
0
def decodeShare(request, dbsession, share):
    entityObj =dbsession.query(Entity).filter(Entity.id==share.entity_id).one()
    entityDict = {'name': entityObj.name, 'url': sm_url.formEntityURI(request, entityObj)}
    return {'quantity': int(share.quantity), 'cost': float(share.cost), 'entity': entityDict}