コード例 #1
0
    def test_get_market_data(self, symbol1, orderbook_2x2):
        """
        @description:
        Here we would like to make sure that client can get market data

        @pre-conditions:
        1. Create symbol (symbol1)
        2. Create order book (orderbook_2x2)

        @steps:
        1. Create 2 orders
        2. Place orders
        3. Get market data

        @assertions:
        JSON schema is valid
        All orders with action BUY in asks
        All orders with action SELL in bids
        Asks and Bids are sorted
        """
        order1 = MarketOrder(symbol1, 0.25, OrderAction.BUY)
        order2 = MarketOrder(symbol1, 0.25, OrderAction.BUY)
        order3 = MarketOrder(symbol1, 0.25, OrderAction.SELL)
        order4 = MarketOrder(symbol1, 0.25, OrderAction.SELL)
        orderbook_2x2.place_order(order1)
        orderbook_2x2.place_order(order2)
        orderbook_2x2.place_order(order3)
        orderbook_2x2.place_order(order4)
        market_data: dict = orderbook_2x2.get_market_data()

        assert is_market_data_schema_valid(market_data)

        asks = orderbook_2x2.get_orders_by_action(OrderAction.BUY)
        bids = orderbook_2x2.get_orders_by_action(OrderAction.SELL)
        assert {
            'price': order1.price,
            'quantity': order1.quantity
        } in market_data['asks']
        assert {
            'price': order2.price,
            'quantity': order2.quantity
        } in market_data['asks']
        assert {
            'price': order3.price,
            'quantity': order3.quantity
        } in market_data['bids']
        assert {
            'price': order4.price,
            'quantity': order4.quantity
        } in market_data['bids']

        assert market_data['bids'][0]['price'] >= market_data['bids'][1][
            'price']
        assert market_data['asks'][0]['price'] >= market_data['asks'][1][
            'price']
コード例 #2
0
    def test_get_order_by_action__check_limit_count(self, test_order_action,
                                                    count, is_it_positive_case,
                                                    symbol1, orderbook_2x2):
        """
        @description:
        Here we would like to make sure that client can define the count of orders during filering by action

        @pre-conditions:
        1. Create symbol (symbol1)
        2. Create order book (orderbook_2x2)

        @parameters:
        test_order_action: valid/invalid data that we would like to put to order as action
        count: expected count of orders by some order action
        is_it_positive_case: flag. "True" value means that test_order_action and count are valid and test should be passed.
                             "False" value means that test_order_action and count are invalid and test shouldn't be passed

        @steps:
        1. Create 2 BUY order
        2. Create 2 SELL order
        3. Place all created orders

        @assertions:
        1. If test_order_action is valid that count of orders by this action is correct
        2. If test_order_action is invalid that client received empty list
        """
        order1 = MarketOrder(symbol1, 0.25, OrderAction.BUY)
        order2 = MarketOrder(symbol1, 1, OrderAction.SELL)
        order3 = MarketOrder(symbol1, 1, OrderAction.SELL)
        order4 = MarketOrder(symbol1, 0.25, OrderAction.BUY)
        orderbook_2x2.place_order(order1)
        orderbook_2x2.place_order(order2)
        orderbook_2x2.place_order(order3)
        orderbook_2x2.place_order(order4)
        if is_it_positive_case:
            assert len(
                orderbook_2x2.get_orders_by_action(test_order_action,
                                                   count)) == count
        else:
            assert len(
                orderbook_2x2.get_orders_by_action(test_order_action,
                                                   count)) == 0
コード例 #3
0
    def test_quantity__get(self, symbol1):
        """
        @description:
        Here we would like to make sure that client can get order's quantity

        @pre-conditions:
        symbol1: default stock symbol with "symbol1" name

        @steps:
        1. Create order with quantity = 300 (for example)

        @assertions:
        1. Order's quantity is changed. Test is passed
        """
        quantity = 300
        order = MarketOrder(symbol1, quantity, OrderAction.BUY)
        assert order.quantity == quantity
コード例 #4
0
ファイル: order_book.py プロジェクト: artkuznetsov/order_book
 def _place_market_order(self, order: MarketOrder):
     order.price = self.quotes.get_current_quote(order.symbol)
     order.status = OrderStatus.PENDING
     self.orders.append(order)
     print(f"Order {order.__dict__} is placed.")
コード例 #5
0
ファイル: run.py プロジェクト: artkuznetsov/order_book
deep = Deep(4, 4)
order_book = OrderBook(deep)

symbol1 = Symbol('symbol1',
                 'exchange1',
                 SymbolType.STOCK,
                 Currency.EUR,
                 is_enabled=True)
symbol2 = Symbol('symbol2',
                 'exchange1',
                 SymbolType.OPTION,
                 Currency.USD,
                 is_enabled=True)

order1 = MarketOrder(symbol1, 2.5, OrderAction.BUY)
order2 = LimitOrder(symbol2, 1500, 12, OrderAction.SELL)
order3 = StopOrder(symbol1, 70, 20, OrderAction.BUY)
order4 = StopLimitOrder(symbol2, 70, 80, 2.5, OrderAction.SELL)
print(
    f"Order1 is {order1.__dict__}\nOrder2 is {order2.__dict__}\nOrder3 is {order3.__dict__}\nOrder4 is {order4.__dict__}"
)

order_book.place_order(order1)
order_book.place_order(order2)
order_book.place_order(order3)
order_book.place_order(order4)

while len(order_book.orders) < 4:
    print(order_book.get_market_data())
    time.sleep(5)
コード例 #6
0
def market_sell_order():
    return MarketOrder(
        Symbol('symbol1', 'exchange1', SymbolType.STOCK, Currency.USD), 300,
        OrderAction.SELL)