Exemplo n.º 1
0
    def __init__(self,
                 side: TradeSide,
                 trade_type: TradeType,
                 pair: 'TradingPair',
                 quantity: 'Quantity',
                 portfolio: 'Portfolio',
                 price: float,
                 criteria: Callable[['Order', 'Exchange'], bool] = None,
                 path_id: str = None):
        if quantity.size == 0:
            raise InvalidOrderQuantity(quantity)

        self.side = side
        self.type = trade_type
        self.pair = pair
        self.quantity = quantity
        self.portfolio = portfolio
        self.price = price
        self.criteria = criteria
        self.path_id = path_id or self.id
        self.status = OrderStatus.PENDING

        self.filled_size = 0
        self.remaining_size = self.size

        self._specs = []
        self._listeners = []
        self._trades = []

        self.quantity.lock_for(self.path_id)
Exemplo n.º 2
0
    def __init__(self,
                 step: int,
                 side: TradeSide,
                 trade_type: TradeType,
                 exchange_pair: 'ExchangePair',
                 quantity: 'Quantity',
                 portfolio: 'Portfolio',
                 price: float,
                 criteria: Callable[['Order', 'Exchange'], bool] = None,
                 path_id: str = None,
                 start: int = None,
                 end: int = None):
        super().__init__()

        quantity = quantity.contain(exchange_pair)

        if quantity.size == 0:
            raise InvalidOrderQuantity(quantity)

        self.step = step
        self.side = side
        self.type = trade_type
        self.exchange_pair = exchange_pair
        self.portfolio = portfolio
        self.price = price
        self.criteria = criteria
        self.path_id = path_id or str(uuid.uuid4())
        self.quantity = quantity
        self.start = start or step
        self.end = end
        self.status = OrderStatus.PENDING

        self._specs = []
        self._listeners = []
        self._trades = []

        wallet = portfolio.get_wallet(
            self.exchange_pair.exchange.id,
            self.side.instrument(self.exchange_pair.pair))

        if self.path_id not in wallet.locked.keys():
            self.quantity = wallet.lock(quantity, self, "LOCK FOR ORDER")

        self.remaining = self.quantity