示例#1
0
def clean_price_movement(input_data: Dict[str, Any]) -> Dict[str, Any]:
    data = deepcopy(input_data)

    data = convert_floats(
        data, ["market_hours_last_movement_pct", "market_hours_last_price"])

    return data
示例#2
0
def clean_execution(input_data: Dict[str, Any]) -> Dict[str, Any]:
    data = deepcopy(input_data)

    data = convert_floats(data, ["price", "quantity"])
    data = convert_dates(data, ["settlement_date", "timestamp"])

    return data
示例#3
0
def clean_portfolio(input_data: Dict[str, Any]) -> Dict[str, Any]:
    data = deepcopy(input_data)

    data = convert_floats(
        data,
        [
            "market_value",
            "equity",
            "extended_hours_market_value",
            "extended_hours_equity",
            "extended_hours_portfolio_equity",
            "last_core_market_value",
            "last_core_equity",
            "last_core_portfolio_equity",
            "excess_margin",
            "excess_maintenance",
            "excess_margin_with_uncleared_deposits",
            "excess_maintenance_with_uncleared_deposits",
            "equity_previous_close",
            "portfolio_equity_previous_close",
            "adjusted_equity_previous_close",
            "adjusted_portfolio_equity_previous_close",
            "withdrawable_amount",
            "unwithdrawable_deposits",
            "unwithdrawable_grants",
        ],
    )
    data = convert_dates(data, ["start_date"])

    return data
示例#4
0
def clean_order(input_data: Dict[str, Any]) -> Dict[str, Any]:
    data = deepcopy(input_data)

    data["state"] = State.to_enum(data["state"])
    data["time_in_force"] = TimeInForce.to_enum(data["time_in_force"])
    data["side"] = ExecutionType.to_enum(data["side"])
    data["type"] = OrderType.to_enum(data["type"])
    data["executions"] = [
        Execution(**clean_execution(e)) for e in data["executions"]
    ]

    consolidate_price_data(data, [
        "price", "stop_price", "dollar_based_amount", "total_notional",
        "executed_notional"
    ])

    data = convert_floats(data, [
        "cumulative_quantity", "quantity", "average_price", "fees",
        "stop_price", "last_trail_price"
    ])
    data = convert_dates(data, [
        "last_transaction_at", "stop_triggered_at",
        "last_trail_price_updated_at"
    ])

    return data
def clean_historicals(input_data: Dict[str, Any]) -> Dict[str, Any]:
    data = deepcopy(input_data)

    data = convert_floats(
        data, ["open_price", "close_price", "high_price", "low_price"])
    data = convert_dates(data, ["begins_at"])

    return data
示例#6
0
def clean_transfer(input_data: Dict[str, Any]) -> Dict[str, Any]:
    data = deepcopy(input_data)

    data["direction"] = TransferDirection.to_enum(data["direction"])
    data["state"] = State.to_enum(data["state"])
    data["rhs_state"] = State.to_enum(data["rhs_state"])

    data = convert_floats(data, ["amount", "fees", "early_access_amount"])

    data = convert_dates(
        data, ["expected_landing_date", "expected_landing_datetime"])

    return data
示例#7
0
def clean_dividend(input_data: Dict[str, str]) -> Dict[str, Any]:
    data: Dict[str, Any] = deepcopy(input_data)

    data["drip_order_execution_price"] = (
        Price(**clean_price(data["drip_order_execution_price"]))
        if "drip_order_execution_price" in data else None)

    data["state"] = DividendState.to_enum(data["state"])
    data = convert_floats(
        data,
        ["amount", "rate", "position", "withholding", "drip_order_quantity"])
    data = convert_dates(data, ["record_date", "payable_date", "paid_at"])

    return data
def clean_fundamentals(input_data: Dict[str, Any]) -> Dict[str, Any]:
    data = deepcopy(input_data)

    data = convert_floats(
        data,
        [
            "open",
            "high",
            "low",
            "volume",
            "average_volume_2_weeks",
            "average_volume",
            "high_52_weeks",
            "low_52_weeks",
            "market_cap",
            "shares_outstanding",
        ],
    )
    data = convert_floats(data,
                          ["dividend_yield", "float", "pb_ratio", "pe_ratio"],
                          0.00)
    data = convert_dates(data, ["datetime"])

    return data
示例#9
0
def clean_option(input_data: Dict[str, Any]) -> Dict[str, Any]:
    data = deepcopy(input_data)

    data["min_ticks"] = Tick(**clean_tick(data["min_ticks"]))
    data["rhs_tradability"] = Tradability.to_enum(data["rhs_tradability"])
    data["state"] = State.to_enum(data["state"])
    data["tradability"] = Tradability.to_enum(data["tradability"])
    data["type"] = OptionType.to_enum(data["type"])

    data = convert_floats(
        data,
        [
            "strike_price",
            "adjusted_mark_price",
            "ask_price",
            "ask_size",
            "bid_price",
            "bid_size",
            "break_even_price",
            "high_price",
            "last_trade_price",
            "last_trade_size",
            "low_price",
            "mark_price",
            "open_interest",
            "previous_close_price",
            "volume",
            "chance_of_profit_long",
            "chance_of_profit_short",
            "delta",
            "gamma",
            "implied_volatility",
            "rho",
            "theta",
            "vega",
            "high_fill_rate_buy_price",
            "high_fill_rate_sell_price",
            "low_fill_rate_buy_price",
            "low_fill_rate_sell_price",
        ],
    )

    data = convert_dates(data, ["expiration_date", "issue_date", "sellout_datetime", "previous_close_date"])

    return data
示例#10
0
def clean_quote(input_data: Dict[str, Any]) -> Dict[str, Any]:
    data = deepcopy(input_data)

    data = convert_floats(
        data,
        [
            "ask_price",
            "bid_price",
            "last_trade_price",
            "last_extended_hours_trade_price",
            "previous_close",
            "adjusted_previous_close",
        ],
    )

    data = convert_dates(data, ["previous_close_date"])

    return data
示例#11
0
def clean_position(input_data: Dict[str, Any]) -> Dict[str, Any]:
    data = deepcopy(input_data)

    data = convert_floats(
        data,
        [
            "quantity",
            "intraday_quantity",
            "average_buy_price",
            "pending_average_buy_price",
            "intraday_average_buy_price",
            "shares_available_for_exercise",
            "shares_held_for_buys",
            "shares_held_for_options_collateral",
            "shares_held_for_options_events",
            "shares_held_for_sells",
            "shares_held_for_stock_grants",
            "shares_pending_from_options_events",
        ],
    )

    data = convert_dates(data)

    return data
示例#12
0
def clean_earnings_per_share(input_data: Dict[str, Any]) -> Dict[str, Any]:
    return convert_floats(input_data, ["estimate", "actual"], 0.00)
示例#13
0
def clean_tick(input_data: Dict[str, Any]) -> Dict[str, Any]:
    data = deepcopy(input_data)

    data = convert_floats(data, ["above_tick", "below_tick", "cutoff_price"])

    return data
示例#14
0
def clean_price(input_data: Dict[str, Any]) -> Dict[str, Any]:
    data = deepcopy(input_data)

    data = convert_floats(data, ["amount"])

    return data