Пример #1
0
                    'side': 'ask',
                    'qty': np.random.poisson(volume) * lot_size,
                    'tid': order_id
                }
                if order['qty'] > 0:
                    next_orders.append(order)

        # Process orders
        random.shuffle(next_orders)
        for order in next_orders:
            x_traded = [initial_price]
            y_traded = [0]
            order_side = order['side'] if order['type'] == 'market' else ''
            # market_order = order['side'] if order['type'] == 'market' else ''

            trades, order = lob.processOrder(order, False, False)
            total_orders += 1

            if order:
                # order was created or not fully executed
                idNum = order['idNum']
                order['time_limit'] = t + np.random.geometric(
                    float(df[df['price'] == order['price']]['gamma']))
                limit_orders.insert(idNum, order)
                born_and_dead_history[idNum] = {
                    'idNum': idNum,
                    'born': t,
                    'dead': order['time_limit']
                }

            if trades:
Пример #2
0
            'qty': 5,
            'price': 99,
            'tid': 102
        },
        {
            'type': 'limit',
            'side': 'bid',
            'qty': 5,
            'price': 97,
            'tid': 103
        },
    ]

    # Add orders to LOB
    for order in someOrders:
        trades, idNum = lob.processOrder(order, False, False)

    # The current book may be viewed using a print
    print lob

    # Submitting a limit order that crosses the opposing best price will
    # result in a trade.
    crossingLimitOrder = {
        'type': 'limit',
        'side': 'bid',
        'qty': 2,
        'price': 102,
        'tid': 109
    }
    trades, orderInBook = lob.processOrder(crossingLimitOrder, False, False)
    print "Trade occurs as incoming bid limit crosses best ask.."