How to use the futures.models.SuccessfulTransaction.objects 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 / tests.py View on Github external
# Someone wants to buy 10@155
        order = Order.objects.all().order_by('-pk')[0]
        order_1 = Order.objects.get(pk=1) # Buy 10@155
        self.assertEqual(order_1.filled, False)
        self.assertEqual(order.filled, True)
        self.assertEqual(order_1.quantity, 6)
        self.assertEqual(order.filled_by, order_1.creator)
        future = Future.objects.get(pk=1)
        self.assertEqual(future.last_buy, 155)
        self.assertEqual(future.ask, 600)
        self.assertEqual(future.bid, 155)
        self.assertEqual(future.volume, 4)
        history = FutureHistory.objects.filter(future=future)
        self.assertEqual(history.count(), 1)
        self.assertEqual(history[0].price, 155)
        transactions = SuccessfulTransaction.objects.filter(future=future)
        self.assertEqual(transactions.count(), 1)
        self.assertTrue(self.compare_transactions(
            transactions[0], SuccessfulTransaction(
                buyer=order_1.creator, seller=user, future=future,
                quantity=4, unit_price=155)))
        # Wallets
        wallet = Wallet.objects.get(user=user)
        wallet_1 = Wallet.objects.get(user=order_1.creator)
        key = '%s' % future.pk
        self.assertEqual(json.loads(wallet.shares_owned)[key], 3)
        self.assertEqual(json.loads(wallet_1.shares_owned)[key], 4)
        self.assertEqual(json.loads(wallet.shares_owned)['4'], 10) # Unchanged.
        self.assertEqual(wallet_1.points, 10000 - (4 * 155))
        self.assertEqual(wallet.points, 10000 + (4 * 155))
        self.assertEqual(wallet.frozen, 0)
        self.assertEqual(wallet_1.frozen, 0)
github domino14 / Webolith / djAerolith / futures / tests.py View on Github external
self.assertEqual(order_1.filled, True)
        self.assertEqual(order_2.filled, True)
        self.assertEqual(order_1.filled_by, user)
        self.assertEqual(order_2.filled_by, user)
        # Fetch new updated future.
        future = Future.objects.get(pk=4)
        self.assertEqual(future.last_buy, 600)
        self.assertEqual(future.bid, 650)
        self.assertEqual(future.ask, None)
        self.assertEqual(future.volume, 12)
        history = FutureHistory.objects.filter(future=future)
        logger.debug(history)
        self.assertEqual(history.count(), 2)
        self.assertEqual(history[0].price, 325)
        self.assertEqual(history[1].price, 600)
        transactions = SuccessfulTransaction.objects.filter(future=future)
        self.assertEqual(transactions.count(), 2)

        self.assertTrue(self.compare_transactions(
            transactions[0], SuccessfulTransaction(
                buyer=user, seller=order_1.creator, future=future,
                quantity=4, unit_price=325)))
        self.assertTrue(self.compare_transactions(
            transactions[1], SuccessfulTransaction(
                buyer=user, seller=order_2.creator, future=future,
                quantity=8, unit_price=600)))
        # Wallets.
        wallet = Wallet.objects.get(user=user)
        wallet_1 = Wallet.objects.get(user=order_1.creator)
        wallet_2 = Wallet.objects.get(user=order_2.creator)
        key = '%s' % future.pk
        self.assertEqual(json.loads(wallet.shares_owned)[key], 12)
github domino14 / Webolith / djAerolith / futures / views.py View on Github external
def last_transactions(user):
    ret = []
    if not user.is_authenticated():
        return ret
    user_transactions = (SuccessfulTransaction.objects.filter(buyer=user) |
                         SuccessfulTransaction.objects.filter(seller=user)
                         ).order_by('-created')[:10]
    for t in user_transactions:
        obj = {}
        if t.buyer == user:
            obj['type'] = 'Buy'
        elif t.seller == user:
            obj['type'] = 'Sell'
        obj['future'] = t.future.id,
        obj['quantity'] = t.quantity
        obj['unitPrice'] = t.unit_price
        obj['date'] = str(t.created) + ' PST'  # Since our Django app is in PST
                                               # time...
        ret.append(obj)
    return ret
github domino14 / Webolith / djAerolith / futures / views.py View on Github external
def last_transactions(user):
    ret = []
    if not user.is_authenticated():
        return ret
    user_transactions = (SuccessfulTransaction.objects.filter(buyer=user) |
                         SuccessfulTransaction.objects.filter(seller=user)
                         ).order_by('-created')[:10]
    for t in user_transactions:
        obj = {}
        if t.buyer == user:
            obj['type'] = 'Buy'
        elif t.seller == user:
            obj['type'] = 'Sell'
        obj['future'] = t.future.id,
        obj['quantity'] = t.quantity
        obj['unitPrice'] = t.unit_price
        obj['date'] = str(t.created) + ' PST'  # Since our Django app is in PST
                                               # time...
        ret.append(obj)
    return ret