How to use the futures.models.Order.objects.filter function in futures

To help you get started, we’ve selected a few futures examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github domino14 / Webolith / djAerolith / futures / views.py View on Github external
def orders_response(user):
    if not user.is_authenticated():
        return []
    orders = Order.objects.filter(creator=user, filled=False)
    resp = []
    for order in orders:
        resp.append({'order_type': order.order_type,
                     'future': order.future.pk,
                     'quantity': order.quantity,
                     'unit_price': order.unit_price,
                     'id': order.pk})
    return resp
github domino14 / Webolith / djAerolith / futures / views.py View on Github external
# Validate these parameters.
    # This is a fairly "expensive" function in that it needs to acquire
    # a lock. The lock ensures that orders can be submitted
    # and tested against open orders of the same future atomically.
    # Additionally the entire thing is wrapped in a transaction
    # (using TransactionMiddleware) so that we're not in a weird state
    # if something 500s or times out.
    # We acquire the lock prior to order validation as nothing can change
    # between the order being validated and it possibly being matched.
    lonelock(Order, future.pk)
    error = validate_order_params(num_shares, price, wallet, order_type,
                                  future)
    if error:
        return response(error, status=400)

    open_orders = Order.objects.filter(filled=False, future=future).exclude(
        creator=wallet.user)

    # Create an order.
    order = Order(future=future, quantity=int(num_shares),
                  unit_price=int(price), creator=wallet.user)
    if order_type == 'buy':
        order.order_type = Order.ORDER_TYPE_BUY
        open_orders = open_orders.filter(order_type=Order.ORDER_TYPE_SELL)
    elif order_type == 'sell':
        order.order_type = Order.ORDER_TYPE_SELL
        open_orders = open_orders.filter(order_type=Order.ORDER_TYPE_BUY)
    # Save the order, then we will see if we have a match.
    order.save()
    freeze_assets(order, wallet)

    logger.debug('*' * 20)