コード例 #1
0
    def __init__(self, live_order: LiveOrder):
        self.account_id = live_order.acct
        self.exchange = global_common.get_enum_from_value(live_order.exchange, StockExchanges)
        self.contract_id = live_order.conid
        self.order_id = live_order.orderId
        self.currency = global_common.get_enum_from_value(live_order.cashCcy, global_common.Currency)
        self.unfilled_quantity = Decimal(str(live_order.remainingQuantity))
        self.filled_quantity = Decimal(str(live_order.filledQuantity))
        self.order_description = live_order.orderDesc
        self.symbol = live_order.ticker
        self.security_type = global_common.get_enum_from_value(live_order.secType, InstrumentType)
        self.status = live_order.status
        self.last_execution_time = datetime.datetime.utcfromtimestamp(int(live_order.lastExecutionTime_r / 1000))
        self.custom_order_id = live_order.order_ref
        self.time_in_force = global_common.get_enum_from_value(live_order.timeInForce, OrderTimeInForce)
        self.side = global_common.get_enum_from_value(live_order.side, OrderSide)

        if live_order.orderType == "Limit":
            self.order_type = OrderType.LIMIT
        elif live_order.orderType == "Market":
            self.order_type = OrderType.MARKET

        if self.order_type is not OrderType.MARKET:
            self.price = Decimal(str(live_order.price))
        else:
            self.price = None
コード例 #2
0
 def __init__(self, description: str, position_size: float, market_price: float, market_value: float,
              instrument_type: str, currency: str, account_id: str):
     self.description = description
     self.position_size = Decimal(str(position_size))
     self.market_price = Decimal(str(market_price))
     self.market_value = Decimal(str(market_value))
     self.account_id = account_id
     self.instrument_type = global_common.get_enum_from_value(instrument_type, InstrumentType)
     self.currency = global_common.get_enum_from_value(currency, global_common.Currency)
コード例 #3
0
 def __init__(self, portfolio_position: ibkr_models.PortfolioPosition):
     self.name = portfolio_position.name
     self.full_name = portfolio_position.fullName
     self.account_id = portfolio_position.acctId
     self.symbol = portfolio_position.contractDesc
     self.contract_id = portfolio_position.conid
     self.market_price = Decimal(str(portfolio_position.mktPrice))
     self.market_value = Decimal(str(portfolio_position.mktValue))
     self.currency = global_common.get_enum_from_value(portfolio_position.currency, global_common.Currency)
     self.instrument_type = global_common.get_enum_from_value(portfolio_position.assetClass, InstrumentType)
     self.position = Decimal(str(portfolio_position.position))
コード例 #4
0
 def __init__(self, alpaca_account: alpaca_trade_api.entity.Account):
     self.account_blocked = alpaca_account._raw["account_blocked"]
     self.account_number = alpaca_account._raw["account_number"]
     self.buying_power = Decimal(str(alpaca_account._raw["buying_power"]))
     self.cash = Decimal(str(alpaca_account._raw["cash"]))
     self.currency = global_common.get_enum_from_value(
         alpaca_account._raw["currency"], global_common.Currency)
     self.daytrading_buying_power = Decimal(
         str(alpaca_account._raw["daytrading_buying_power"]))
     self.equity = Decimal(str(alpaca_account._raw["equity"]))
     self.portfolio_value = Decimal(
         str(alpaca_account._raw["portfolio_value"]))
     self.status = global_common.get_enum_from_value(
         alpaca_account._raw["status"], AccountStatus)
コード例 #5
0
 def __init__(self, account: str, contract: ibapi.contract.Contract, quantity: float, average_cost: float):
     self.account = account
     self.contract = Contract(contract.conId, contract.currency, contract.symbol, contract.exchange)
     self.symbol = self.contract.symbol
     self.quantity = Decimal(str(quantity))
     self.average_cost = Decimal(str(average_cost))
     self.security_type = global_common.get_enum_from_value(contract.secType, SecurityType)
コード例 #6
0
 def __init__(self, order_id: int, status: str, quantity_filled: float, remaining_to_fill: float, average_fill_price: float, contract: ibapi.contract.Contract, order: ibapi.order.Order, order_state: ibapi.order_state.OrderState):
     self.order_id = order_id
     self.status = global_common.get_enum_from_value(status, OrderStatus)
     self.quantity_filled = Decimal(str(quantity_filled))
     self.remaining_to_fill = Decimal(str(remaining_to_fill))
     self.average_fill_price = Decimal(str(average_fill_price))
     self.contract = Contract(contract.conId, contract.currency, contract.symbol, contract.exchange)
     self.order = order
     self.order_state = order_state
コード例 #7
0
    def __init__(self, alpaca_order: alpaca_trade_api.entity.Order):
        self.id = alpaca_order._raw["id"]
        self.created_at = dateutil.parser.isoparse(
            alpaca_order._raw["created_at"])
        self.updated_at = dateutil.parser.isoparse(
            alpaca_order._raw["updated_at"])
        self.submitted_at = dateutil.parser.isoparse(
            alpaca_order._raw["submitted_at"])
        self.asset_id = alpaca_order._raw["asset_id"]
        self.symbol = alpaca_order._raw["symbol"]
        self.quantity = Decimal(alpaca_order._raw["qty"])
        self.filled_qty = Decimal(alpaca_order._raw["filled_qty"])
        self.order_type = global_common.get_enum_from_value(
            alpaca_order._raw["order_type"], OrderType)
        self.side = global_common.get_enum_from_value(
            alpaca_order._raw["side"], OrderSide)
        self.time_in_force = global_common.get_enum_from_value(
            alpaca_order._raw["time_in_force"], OrderTimeInForce)
        self.status = global_common.get_enum_from_value(
            alpaca_order._raw["status"], OrderStatus)
        self.is_extended_hours = alpaca_order._raw["extended_hours"]

        if alpaca_order._raw["limit_price"] is not None:
            self.limit_price = Decimal(alpaca_order._raw["limit_price"])

        if alpaca_order._raw["filled_at"] is not None:
            self.filled_at = dateutil.parser.isoparse(
                alpaca_order._raw["filled_at"])

        if alpaca_order._raw["expired_at"] is not None:
            self.expired_at = dateutil.parser.isoparse(
                alpaca_order._raw["expired_at"])

        if alpaca_order._raw["canceled_at"] is not None:
            self.canceled_at = dateutil.parser.isoparse(
                alpaca_order._raw["canceled_at"])

        if alpaca_order._raw["failed_at"] is not None:
            self.failed_at = dateutil.parser.isoparse(
                alpaca_order._raw["failed_at"])

        if alpaca_order._raw["filled_avg_price"] is not None:
            self.filled_avg_price = Decimal(
                alpaca_order._raw["filled_avg_price"])
コード例 #8
0
 def __init__(self, contract_id: int, currency: str, symbol: str, exchange: str):
     self.contract_id = contract_id
     self.currency = global_common.get_enum_from_value(currency, global_common.Currency)
     self.symbol = symbol
     self.exchange = global_common.get_enum_from_value(exchange, Exchange)
コード例 #9
0
    def __init__(self, symbol: str, contract_id: int, instrument_type: str, exchanges_list: List[str], main_exchange:
    str, name: str, open_price: str, close_price: str, high_price: str, low_price: str, last_price: str,
                 change_in_currency: str, change_in_percentage: str, bid_price: str, ask_price: str,
                 ask_size: str, bid_size: str,
                 volume: str, option_volume: str, dividend_amount: str, dividend_yield: str, market_capitalization:
            str, price_to_earnings_ratio: str, earnings_per_share: str):

        if contract_id is None:
            raise StockDataNotAvailableException()

        self.last_price = Decimal(str(last_price.replace("C", "").replace("H", "")))
        self.symbol = symbol

        if contract_id is not None:
            self.contract_id = contract_id

        if exchanges_list is not None:
            self.exchanges_list = exchanges_list

        if name is not None:
            self.name = name

        if instrument_type is not None:
            self.instrument_type = global_common.get_enum_from_value(instrument_type, InstrumentType)

        if main_exchange is not None:
            self.main_exchange = main_exchange

        if change_in_percentage is not None:
            self.change_in_percentage = Decimal(str(change_in_percentage))

        if change_in_currency is not None:
            self.change_in_currency = Decimal(str(change_in_currency))

        if bid_price is not None:
            self.bid_price = Decimal(str(bid_price))

        if bid_size is not None:
            self.bid_size = Decimal(str(bid_size))

        if ask_price is not None:
            self.ask_price = Decimal(str(ask_price))

        if ask_size is not None:
            self.ask_size = Decimal(str(ask_size))

        if volume is not None:
            self.volume = Decimal(str(volume))

        if dividend_amount is not None:
            self.dividend_amount = Decimal(str(dividend_amount))

        if earnings_per_share is not None:
            self.earnings_per_share = Decimal(str(earnings_per_share))

        if price_to_earnings_ratio is not None:
            self.price_to_earnings_ratio = Decimal(str(price_to_earnings_ratio))

        if market_capitalization is not None:
            self.market_capitalization = ibkr_web_api.common.get_number_from_text_with_suffixes(market_capitalization)

        if open_price is not None:
            self.open_price = Decimal(str(open_price))

        if low_price is not None:
            self.low_price = Decimal(str(low_price))

        if high_price is not None:
            self.high_price = Decimal(str(high_price))

        if close_price is not None:
            self.close_price = Decimal(str(close_price))

        if option_volume is not None:
            self.option_volume = Decimal(str(ibkr_web_api.common.get_number_from_text_with_suffixes(option_volume)))

        if dividend_yield is not None:
            self.dividend_yield = Decimal(str(dividend_yield).replace("%", ""))
コード例 #10
0
 def __init__(self, account_information: ibkr_models.AccountInformation):
     self.available_funds = Decimal(str(account_information.totalcashvalue.amount))
     self.currency = global_common.get_enum_from_value(account_information.fullavailablefunds.currency, global_common.Currency)
     self.updated_at = datetime.datetime.utcfromtimestamp(int(account_information.fullavailablefunds.timestamp / 1000))
     self.net_liquidity = Decimal(str(account_information.netliquidation.amount))