@alpacahq/typescript-sdk
Version:
A TypeScript SDK for the https://alpaca.markets REST API and WebSocket streams.
500 lines • 16.9 kB
TypeScript
import { ClientContext } from "../factory/createClient.js";
export type UnstableNumber = string | number;
export type Nullable<T> = T | null;
export type AccountStatus = "ONBOARDING" | "SUBMISSION_FAILED" | "SUBMITTED" | "ACCOUNT_UPDATED" | "APPROVAL_PENDING" | "ACTIVE" | "REJECTED";
export type OptionsApprovedLevel = 0 | 1 | 2;
export type OptionsTradingLevel = 0 | 1 | 2;
export type Account = {
id: string;
account_number: string;
status: AccountStatus;
currency: string;
cash: string;
portfolio_value: string;
non_marginable_buying_power: string;
accrued_fees: string;
pending_transfer_in: string;
pending_transfer_out: string;
pattern_day_trader: boolean;
trade_suspended_by_user: boolean;
trading_blocked: boolean;
transfers_blocked: boolean;
account_blocked: boolean;
created_at: string;
shorting_enabled: boolean;
long_market_value: string;
short_market_value: string;
equity: string;
last_equity: string;
multiplier: string;
buying_power: string;
initial_margin: string;
maintenance_margin: string;
sma: string;
daytrade_count: number;
last_maintenance_margin: string;
daytrading_buying_power: string;
regt_buying_power: string;
options_buying_power: string;
options_approved_level: OptionsApprovedLevel;
options_trading_level: OptionsTradingLevel;
};
export declare const getAccount: ({ request }: ClientContext) => () => Promise<Account>;
export type BaseOrder = {
id: string;
client_order_id: string;
created_at: string;
updated_at: string;
submitted_at: string;
filled_at: Nullable<UnstableNumber>;
expired_at: Nullable<UnstableNumber>;
canceled_at: Nullable<UnstableNumber>;
failed_at: Nullable<UnstableNumber>;
replaced_at: Nullable<UnstableNumber>;
replaced_by: Nullable<UnstableNumber>;
replaces: Nullable<UnstableNumber>;
asset_id: string;
notional: Nullable<UnstableNumber>;
qty: string;
filled_qty: string;
filled_avg_price: Nullable<UnstableNumber>;
order_class: string;
order_type: string;
type: Type;
side: string;
time_in_force: string;
limit_price: Nullable<UnstableNumber>;
stop_price: Nullable<UnstableNumber>;
status: string;
extended_hours: boolean;
legs?: Nullable<object>;
trail_percent: Nullable<UnstableNumber>;
trail_price: Nullable<UnstableNumber>;
hwm: Nullable<UnstableNumber>;
subtag: Nullable<UnstableNumber>;
source: Nullable<UnstableNumber>;
};
export type EquityOrder = BaseOrder & {
asset_class: "us_equity";
symbol: string;
};
export type OptionsOrder = BaseOrder & {
asset_class: "us_option";
symbol: string;
order_class: "simple";
};
export type CryptoOrder = BaseOrder & {
asset_class: "crypto";
symbol: string;
};
export type Order = EquityOrder | OptionsOrder | CryptoOrder;
export type Position = {
asset_id: string;
exchange: string;
asset_class: string;
symbol: string;
asset_marginable: boolean;
qty: string;
avg_entry_price: string;
side: Direction;
market_value: string;
cost_basis: string;
unrealized_pl: string;
unrealized_plpc: string;
unrealized_intraday_pl: string;
unrealized_intraday_plpc: string;
current_price: string;
lastday_price: string;
change_today: string;
qty_available: string;
};
export type TimeInForce = "day" | "gtc" | "opg" | "cls" | "ioc" | "fok";
export type PositionIntent = "buy_to_open" | "buy_to_close" | "sell_to_open" | "sell_to_close";
export type Type = "market" | "limit" | "stop" | "stop_limit" | "trailing_stop";
export type Side = "buy" | "sell";
export type OrderClass = "simple" | "oco" | "oto" | "bracket" | "";
export type Direction = "long" | "short";
export type TakeProfit = {
limit_price?: string;
};
export type StopLoss = {
stop_price?: string;
limit_price?: string;
};
export type CreateOrderOptions = {
symbol: string;
qty?: UnstableNumber;
notional?: UnstableNumber;
side: Side;
type: Type;
time_in_force: TimeInForce;
limit_price?: UnstableNumber;
stop_price?: UnstableNumber;
trail_price?: UnstableNumber;
trail_percent?: UnstableNumber;
extended_hours?: boolean;
client_order_id?: string;
order_class?: OrderClass;
take_profit?: TakeProfit;
stop_loss?: StopLoss;
position_intent?: PositionIntent;
};
export declare const createOrder: ({ request }: ClientContext) => (data: CreateOrderOptions) => Promise<Order>;
export type GetOrderOptions = {
order_id: string;
};
export declare const getOrder: ({ request }: ClientContext) => ({ order_id }: GetOrderOptions) => Promise<Order>;
export type GetOrdersOptions = {
status?: string;
limit?: UnstableNumber;
after?: string;
until?: string;
direction?: Direction;
nested?: boolean;
symbols?: string;
side?: Side;
order_id: string;
};
export declare const getOrders: ({ request }: ClientContext) => (params: GetOrdersOptions) => Promise<Order>;
export type ReplaceOrderOptions = {
qty?: UnstableNumber;
time_in_force?: string;
limit_price?: UnstableNumber;
stop_price?: UnstableNumber;
trail?: UnstableNumber;
client_order_id?: string;
order_id: string;
};
export declare const replaceOrder: ({ request }: ClientContext) => (data: ReplaceOrderOptions) => Promise<Order>;
export type CancelOrderOptions = {
order_id: string;
};
export declare const cancelOrder: ({ request }: ClientContext) => ({ order_id }: CancelOrderOptions) => Promise<Order>;
export declare const cancelOrders: ({ request }: ClientContext) => () => Promise<Order>;
export type GetPositionOptions = {
symbol_or_asset_id: string;
};
export declare const getPosition: ({ request }: ClientContext) => ({ symbol_or_asset_id }: GetPositionOptions) => Promise<Position>;
export declare const getPositions: ({ request }: ClientContext) => () => Promise<Position[]>;
export type ClosePositionOptions = {
symbol_or_asset_id: string;
};
export declare const closePosition: ({ request }: ClientContext) => ({ symbol_or_asset_id }: ClosePositionOptions) => Promise<Order>;
export declare const closePositions: ({ request }: ClientContext) => () => Promise<Nullable<Order>[]>;
export type GetAssetsOptions = {
status?: string;
asset_class?: string;
asset_status?: string;
};
export type ExerciseOption = {
symbol_or_contract_id: string;
};
export declare const exerciseOption: ({ request }: ClientContext) => ({ symbol_or_contract_id }: ExerciseOption) => Promise<Order>;
export type GetCalendarOptions = {
start?: string;
end?: string;
dateType?: "TRADING" | "SETTLEMENT";
};
export type Calendar = {
date: string;
open: string;
close: string;
settlement_date: string;
};
export declare const getCalendar: ({ request }: ClientContext) => (params?: GetCalendarOptions) => Promise<Calendar[]>;
export type Clock = {
timestamp: string;
is_open: boolean;
next_open: string;
next_close: string;
};
export declare const getClock: ({ request }: ClientContext) => () => Promise<Clock>;
export type GetAssetOptions = {
symbol_or_asset_id: string;
};
export declare const getAsset: ({ request }: ClientContext) => ({ symbol_or_asset_id }: GetAssetOptions) => Promise<Asset>;
export type Asset = {
id: string;
class: string;
exchange: string;
symbol: string;
name: string;
status: string;
tradable: boolean;
marginable: boolean;
shortable: boolean;
easy_to_borrow: boolean;
fractionable: boolean;
maintenance_margin_requirement: string;
tradability: string;
symbol_with_class: string;
asset_id: string;
};
export declare const getAssets: ({ request }: ClientContext) => (params?: GetAssetsOptions) => Promise<Asset[]>;
export type Watchlist = {
id: string;
account_id: string;
created_at: string;
updated_at: string;
name: string;
assets: Asset[];
};
export type GetWatchlistOptions = {
watchlist_id: string;
};
export declare const getWatchlist: ({ request }: ClientContext) => ({ watchlist_id }: GetWatchlistOptions) => Promise<Watchlist>;
export declare const getWatchlists: ({ request }: ClientContext) => () => Promise<Watchlist[]>;
export type CreateWatchlistOptions = {
name: string;
symbols: Nullable<string[]>;
};
export declare const createWatchlist: ({ request }: ClientContext) => (data: CreateWatchlistOptions) => Promise<Watchlist>;
export type UpdateWatchlistOptions = {
name: string;
symbols: Nullable<string[]>;
watchlist_id: string;
};
export declare const updateWatchlist: ({ request }: ClientContext) => (data: UpdateWatchlistOptions) => Promise<Watchlist>;
export type DeleteWatchlistOptions = {
watchlist_id: string;
};
export declare const deleteWatchlist: ({ request }: ClientContext) => ({ watchlist_id }: DeleteWatchlistOptions) => Promise<unknown>;
export type PortfolioHistory = {
timestamp: string[];
equity: string[];
profit_loss: string[];
profit_loss_pct: string[];
base_value: string;
base_value_asof: string;
timeframe: string;
};
export type GetPortfolioHistoryOptions = {
period?: string;
timeframe?: string;
intraday_reporting?: string;
start?: string;
end?: string;
pnl_reset?: string;
};
export declare const getPortfolioHistory: ({ request }: ClientContext) => (params: GetPortfolioHistoryOptions) => Promise<PortfolioHistory>;
export type Configurations = {
dtbp_check: string;
trade_confirm_email: string;
suspend_trade: boolean;
no_shorting: boolean;
fractional_trading: boolean;
max_margin_multiplier: string;
max_options_trading_level: number;
pdt_check: string;
ptp_no_exception_entry: boolean;
};
export declare const getConfigurations: ({ request }: ClientContext) => () => Promise<Configurations>;
export type UpdateConfigurationsOptions = {
dtbp_check?: string;
trade_confirm_email?: string;
suspend_trade?: boolean;
no_shorting?: boolean;
fractional_trading?: boolean;
max_margin_multiplier?: string;
max_options_trading_level?: number;
pdt_check?: string;
ptp_no_exception_entry?: boolean;
};
export declare const updateConfigurations: ({ request }: ClientContext) => (data: UpdateConfigurationsOptions) => Promise<Configurations>;
export type TradingActivity = {
activity_type: string;
id: string;
cum_qty: string;
leaves_qty: string;
price: string;
qty: string;
side: string;
symbol: string;
transaction_time: string;
order_id: string;
type: string;
order_status: string;
};
export type NonTradeActivity = {
activity_type: string;
id: string;
date: string;
net_amount: string;
symbol?: string;
qty?: string;
per_share_amount?: string;
};
export type Activity = TradingActivity | NonTradeActivity;
export type GetActivityOptions = {
activity_type: string;
activity_types?: string;
date?: string;
until?: string;
after?: string;
direction?: string;
pageSize?: number;
pageToken?: string;
category?: string;
};
export declare const getActivity: ({ request }: ClientContext) => ({ activity_type }: GetActivityOptions) => Promise<Activity[]>;
export declare const getActivities: ({ request }: ClientContext) => () => Promise<Activity[]>;
export type OptionsContract = {
id: string;
symbol: string;
name: string;
status: string;
tradable: boolean;
tradability: string;
chain_id: string;
type: string;
option_type: string;
expiration_date: string;
strike_price: string;
min_ticks: {
above_tick: string;
below_tick: string;
cutoff_price: string;
};
option_style: string;
created_at: string;
updated_at: string;
last_trade_date: string;
underlying: string;
tradable_chain_id: string;
chain_symbol: string;
description: string;
asset_id: string;
};
export type GetOptionsContractOptions = {
symbol_or_contract_id: string;
};
export declare const getOptionsContract: ({ request }: ClientContext) => ({ symbol_or_contract_id }: GetOptionsContractOptions) => Promise<OptionsContract>;
export type GetOptionsContractsOptions = {
underlying_symbols?: string;
status?: string;
active?: boolean;
expiration_date?: string;
expiration_date_gte?: string;
expiration_date_lte?: string;
root_symbol?: string;
type?: string;
style?: string;
strike_price_gte?: UnstableNumber;
strike_price_lte?: UnstableNumber;
page_token?: string;
limit?: UnstableNumber;
symbol_or_contract_id: string;
};
export declare const getOptionsContracts: ({ request }: ClientContext) => (params: GetOptionsContractsOptions) => Promise<OptionsContract[]>;
export type CorporateAction = {
id: string;
corporate_actions_id: string;
ca_type: string;
ca_sub_type: string;
initiating_symbol: string;
initiating_original_cusip: string;
target_symbol: string;
target_original_cusip: string;
declaration_date: string;
expiration_date: string;
record_date: string;
payable_date: string;
cash: string;
old_rate: string;
new_rate: string;
};
export type GetCorporateActionOptions = {
id: string;
};
export declare const getCorporateAction: ({ request }: ClientContext) => ({ id }: GetCorporateActionOptions) => Promise<CorporateAction>;
export type GetCorporateActionsOptions = {
ca_types: string;
since: string;
until: string;
symbol?: string;
cusip?: string;
date_type?: string;
};
export declare const getCorporateActions: ({ request }: ClientContext) => (params: GetCorporateActionsOptions) => Promise<CorporateAction[]>;
export type CryptoWallet = {
id: string;
currency: string;
balance: string;
available: string;
held: string;
profile_id: string;
};
export type GetWalletOptions = {
asset: string;
};
export declare const getCryptoWallet: ({ request }: ClientContext) => ({ asset }: GetWalletOptions) => Promise<CryptoWallet>;
export declare const getCryptoWallets: ({ request }: ClientContext) => () => Promise<CryptoWallet[]>;
export type CryptoFee = {
fee: string;
network_fee: string;
estimated_delivery: string;
};
export type GetCryptoFeeEstimateOptions = {
asset: string;
from_address: string;
to_address: string;
amount: string;
};
export declare const getFeeEstimate: ({ request }: ClientContext) => (params: GetCryptoFeeEstimateOptions) => Promise<CryptoFee>;
export type CryptoTransfer = {
id: string;
tx_hash: string;
direction: "INCOMING" | "OUTGOING";
status: "PROCESSING" | "FAILED" | "COMPLETE";
amount: string;
usd_value: string;
network_fee: string;
fees: string;
chain: string;
asset: string;
from_address: string;
to_address: string;
created_at: string;
};
export type CryptoTransferResponse = {
wallets?: CryptoWallet | CryptoWallet[];
transfers?: CryptoTransfer[];
};
export type GetCryptoTransferOptions = {
transfer_id: string;
};
export declare const getCryptoTransfer: ({ request }: ClientContext) => ({ transfer_id }: GetCryptoTransferOptions) => Promise<CryptoTransfer | CryptoTransferResponse>;
export type GetCryptoTransfersOptions = {
asset?: string;
};
export declare const getCryptoTransfers: ({ request }: ClientContext) => (params?: GetCryptoTransfersOptions) => Promise<CryptoTransfer[]>;
export type CreateCryptoTransferOptions = {
amount: string;
address: string;
asset: string;
};
export declare const createCryptoTransfer: ({ request }: ClientContext) => (data: CreateCryptoTransferOptions) => Promise<CryptoTransfer>;
export type WhitelistedAddress = {
id: string;
chain: string;
asset: string;
address: string;
status: "ACTIVE" | "PENDING";
created_at: string;
};
export type GetCryptoWhitelistedAddressOptions = {
address: string;
asset: string;
};
export declare const getCryptoWhitelistedAddress: ({ request }: ClientContext) => (params: GetCryptoWhitelistedAddressOptions) => Promise<WhitelistedAddress>;
export declare const getCryptoWhitelistedAddresses: ({ request }: ClientContext) => () => Promise<WhitelistedAddress[]>;
export type RequestCryptoWhitelistedAddressOptions = {
address: string;
asset: string;
};
export declare const requestCryptoWhitelistedAddress: ({ request }: ClientContext) => (data: RequestCryptoWhitelistedAddressOptions) => Promise<WhitelistedAddress>;
export type RemoveCryptoWhitelistedAddressOptions = {
whitelisted_address_id: string;
};
export declare const removeCryptoWhitelistedAddress: ({ request }: ClientContext) => ({ whitelisted_address_id }: RemoveCryptoWhitelistedAddressOptions) => Promise<unknown>;
//# sourceMappingURL=trade.d.ts.map