Пример #1
0
    def updateAction(self, action, level, state, orderbookIndex=None, force_execution=False):
        if force_execution:
            runtime = state.getT()
            ot = OrderType.LIMIT_T_MARKET
        else:
            runtime = self.determineRuntime(state.getT())
            ot = OrderType.LIMIT

        if orderbookIndex is not None:
            orderbookState = self.orderbook.getState(orderbookIndex)
            action.setOrderbookState(orderbookState)
            action.setOrderbookIndex(orderbookIndex)

        if runtime <= 0 or level is None:
            price = None
            ot = OrderType.MARKET
        else:
            price = action.getOrderbookState().getPriceAtLevel(self.side, level)

        order = Order(
            orderType=ot,
            orderSide=self.side,
            cty=state.getI(),
            price=price
        )
        action.setState(state)
        action.setOrder(order)
        return action
Пример #2
0
    def createAction(self, level, state, orderbookIndex=None, force_execution=False):
        # Determines whether to run and force execution of given t, or if
        # segmentation of t into multiple runtimes is allowed.
        if force_execution:
            runtime = state.getT()
            ot = OrderType.LIMIT_T_MARKET
        else:
            runtime = self.determineRuntime(state.getT())
            ot = OrderType.LIMIT

        if orderbookIndex is None:
            orderbookState, orderbookIndex = self.getRandomOrderbookState()
        else:
            orderbookState = self.orderbook.getState(orderbookIndex)

        if runtime <= 0.0 or level is None:
            price = None
            ot = OrderType.MARKET
        else:
            price = orderbookState.getPriceAtLevel(self.side, level)

        order = Order(
            orderType=ot,
            orderSide=self.side,
            cty=state.getI(),
            price=price
        )
        action = Action(a=level, runtime=runtime)
        action.setState(state)
        action.setOrder(order)
        action.setOrderbookState(orderbookState)
        action.setOrderbookIndex(orderbookIndex)
        action.setReferencePrice(orderbookState.getBestAsk())
        return action
Пример #3
0
    def _update_execution(self, execution, a):
        runtime = self._determine_runtime(self.actionState.getT())
        orderbookState = self.orderbook.getState(self.orderbookIndex)

        if runtime <= 0.0 or a is None:
            price = None
            ot = OrderType.MARKET
        else:
            price = execution.getOrderbookState().getPriceAtLevel(self.side, a)
            ot = OrderType.LIMIT

        order = Order(orderType=ot,
                      orderSide=self.side,
                      cty=self.actionState.getI(),
                      price=price)
        execution.setRuntime(runtime)
        execution.setState(self.actionState)
        execution.setOrder(order)
        execution.setOrderbookState(orderbookState)
        execution.setOrderbookIndex(self.orderbookIndex)
        return execution
Пример #4
0
    def _create_execution(self, a):
        runtime = self._determine_runtime(self.actionState.getT())
        orderbookState = self.orderbook.getState(self.orderbookIndex)

        if runtime <= 0.0 or a is None:
            price = None
            ot = OrderType.MARKET
        else:
            price = orderbookState.getPriceAtLevel(self.side, a)
            ot = OrderType.LIMIT

        order = Order(orderType=ot,
                      orderSide=self.side,
                      cty=self.actionState.getI(),
                      price=price)
        execution = Action(a=a, runtime=runtime)
        execution.setState(self.actionState)
        execution.setOrder(order)
        execution.setOrderbookState(orderbookState)
        execution.setOrderbookIndex(self.orderbookIndex)
        execution.setReferencePrice(orderbookState.getBestAsk())
        return execution