-
Notifications
You must be signed in to change notification settings - Fork 4
Alpaca
Swift API client for Alpaca’s trade API. Contribute on GitHub.
public final class Alpaca
public init(sessionConfiguration: URLSessionConfiguration = .default, mode: Mode = .paper, version: Version = .v2, key: Key)
canImport(Combine)
-
The account API serves important information related to an account, including account status, funds available for trade, funds available for withdrawal, and various flags relevant to an account’s ability to trade.
var account: AnyPublisher<Account, Error>
canImport(Combine)
-
Attempts to cancel all open orders.
var cancelAllOrders: AnyPublisher<[OrderCancellation], Error>
A response will be provided for each order that is attempted to be cancelled. If an order is no longer cancelable, the server will respond with status 500 and reject the request.
canImport(Combine)
-
Retrieves a list of the account’s open positions.
var positions: AnyPublisher<[Position], Error>
canImport(Combine)
-
Closes (liquidates) all of the account’s open long and short positions. A response will be provided for each order that is attempted to be cancelled. If an order is no longer cancelable, the server will respond with status 500 and reject the request.
var closeAllPositions: AnyPublisher<[PositionLiquidation], Error>
canImport(Combine)
-
The clock API serves the current market timestamp, whether or not the market is currently open, as well as the times of the next market open and close.
var clock: AnyPublisher<Clock, Error>
let api: AlpacaAPI
canImport(Combine)
-
Retrieves a list of orders for the account, filtered by the supplied query parameters.
func orders(queryParameters: Order.QueryParameters? = nil) -> AnyPublisher<[Order], Error>
canImport(Combine)
-
Retrieves a single order for the given order ID.
func order(id: String) -> AnyPublisher<Order, Error>
canImport(Combine)
-
Retrieves a single order for the given client order ID.
func order(clientID: String) -> AnyPublisher<Order, Error>
canImport(Combine)
-
Places a new order for the given account.
func place(order: OrderRequest) -> AnyPublisher<Order, Error>
An order request may be rejected if the account is not authorized for trading, or if the tradable balance is insufficient to fill the order.
canImport(Combine)
-
Replaces a single order with updated parameters. Each parameter overrides the corresponding attribute of the existing order.
func replace(order id: String, with order: OrderRequest) -> AnyPublisher<Order, Error>
A success return code from a replaced order does NOT guarantee the existing open order has been replaced. If the existing open order is filled before the replacing (new) order reaches the execution venue, the replacing (new) order is rejected, and these events are sent in the trade_updates stream channel. While an order is being replaced, buying power is reduced by the larger of the two orders that have been placed (the old order being replaced, and the newly placed order to replace it). If you are replacing a buy entry order with a higher limit price than the original order, the buying power is calculated based on the newly placed order. If you are replacing it with a lower limit price, the buying power is calculated based on the old order.
canImport(Combine)
-
Attempts to cancel an open order.
func cancelOrder(id: String) -> AnyPublisher<String, Error>
If the order is no longer cancelable (example: status=
orderFilled
), the server will respond with status 422, and reject the request.
canImport(Combine)
-
Retrieves the account’s open position for the given
symbol
.func position(symbol: String) -> AnyPublisher<Position, Error>
canImport(Combine)
-
Closes (liquidates) the account’s open position for the given
symbol
. Works for both long and short positions.func closePosition(symbol: String) -> AnyPublisher<Order, Error>
canImport(Combine)
-
The assets API serves as the master list of assets available for trade and data consumption from Alpaca.
func assets(queryParameters: Asset.QueryParameters? = nil) -> AnyPublisher<[Asset], Error>
Assets are sorted by asset class, exchange and symbol. Some assets are only available for data consumption via Polygon, and are not tradable with Alpaca. These assets will be marked with the flag
tradable
=false
.
canImport(Combine)
-
Get an asset for the given symbol (or asset ID).
func asset(symbol: String) -> AnyPublisher<Asset, Error>
canImport(Combine)
-
The calendar API serves the full list of market days from 1970 to 2029. It can also be queried by specifying a start and/or end time to narrow down the results.
func calendar(queryParameters: Calendar.QueryParameters? = nil) -> AnyPublisher<[Calendar], Error>
The account API serves important information related to an account, including account status, funds available for trade, funds available for withdrawal, and various flags relevant to an account’s ability to trade.
@discardableResult public func account(_ completion: @escaping (Result<Account, Error>) -> Void) -> Cancel
Retrieves a list of orders for the account, filtered by the supplied query parameters.
@discardableResult public func orders(queryParameters: Order.QueryParameters? = nil, _ completion: @escaping (Result<[Order], Error>) -> Void) -> Cancel
Retrieves a single order for the given order ID.
@discardableResult public func order(id: String, _ completion: @escaping (Result<Order, Error>) -> Void) -> Cancel
Retrieves a single order for the given client order ID.
@discardableResult public func order(clientID: String, _ completion: @escaping (Result<Order, Error>) -> Void) -> Cancel
Places a new order for the given account.
@discardableResult public func place(order: OrderRequest, _ completion: @escaping (Result<Order, Error>) -> Void) -> Cancel
An order request may be rejected if the account is not authorized for trading, or if the tradable balance is insufficient to fill the order.
Replaces a single order with updated parameters. Each parameter overrides the corresponding attribute of the existing order.
@discardableResult public func replace(order id: String, with order: OrderRequest, _ completion: @escaping (Result<Order, Error>) -> Void) -> Cancel
A success return code from a replaced order does NOT guarantee the existing open order has been replaced. If the existing open order is filled before the replacing (new) order reaches the execution venue, the replacing (new) order is rejected, and these events are sent in the trade_updates stream channel. While an order is being replaced, buying power is reduced by the larger of the two orders that have been placed (the old order being replaced, and the newly placed order to replace it). If you are replacing a buy entry order with a higher limit price than the original order, the buying power is calculated based on the newly placed order. If you are replacing it with a lower limit price, the buying power is calculated based on the old order.
Attempts to cancel an open order.
@discardableResult public func cancelOrder(id: String, _ completion: @escaping (Result<String, Error>) -> Void) -> Cancel
If the order is no longer cancelable (example: status=orderFilled
),
the server will respond with status 422, and reject the request.
Attempts to cancel all open orders.
@discardableResult public func cancelAllOrders(_ completion: @escaping (Result<[OrderCancellation], Error>) -> Void) -> Cancel
A response will be provided for each order that is attempted to be cancelled. If an order is no longer cancelable, the server will respond with status 500 and reject the request.
Retrieves a list of the account’s open positions.
@discardableResult public func positions(_ completion: @escaping (Result<[Position], Error>) -> Void) -> Cancel
Retrieves the account’s open position for the given symbol
.
@discardableResult public func position(symbol: String, _ completion: @escaping (Result<Position, Error>) -> Void) -> Cancel
Closes (liquidates) all of the account’s open long and short positions. A response will be provided for each order that is attempted to be cancelled. If an order is no longer cancelable, the server will respond with status 500 and reject the request.
@discardableResult public func closeAllPositions(_ completion: @escaping (Result<[PositionLiquidation], Error>) -> Void) -> Cancel
Closes (liquidates) the account’s open position for the given symbol
. Works for both long and short positions.
@discardableResult public func closePosition(symbol: String, _ completion: @escaping (Result<Order, Error>) -> Void) -> Cancel
The assets API serves as the master list of assets available for trade and data consumption from Alpaca.
@discardableResult public func assets(queryParameters: Asset.QueryParameters? = nil, _ completion: @escaping (Result<[Asset], Error>) -> Void) -> Cancel
Assets are sorted by asset class, exchange and symbol.
Some assets are only available for data consumption via Polygon, and are not tradable with Alpaca.
These assets will be marked with the flag tradable
=false
.
Get an asset for the given symbol (or asset ID).
@discardableResult public func asset(symbol: String, _ completion: @escaping (Result<Asset, Error>) -> Void) -> Cancel
The calendar API serves the full list of market days from 1970 to 2029. It can also be queried by specifying a start and/or end time to narrow down the results.
@discardableResult public func calendar(queryParameters: Calendar.QueryParameters? = nil, _ completion: @escaping (Result<[Calendar], Error>) -> Void) -> Cancel
The clock API serves the current market timestamp, whether or not the market is currently open, as well as the times of the next market open and close.
@discardableResult public func clock(_ completion: @escaping (Result<Clock, Error>) -> Void) -> Cancel
Generated at 2020-05-22T00:57:11+0000 using swift-doc 1.0.0-beta.3.
Types
- Account
- AccountStatus
- Alpaca
- Alpaca.Key
- Alpaca.Mode
- Alpaca.Version
- AlpacaAPI
- AlpacaAPI.Path
- AlpacaError
- Asset
- Asset.QueryParameters
- AssetClass
- AssetStatus
- Calendar
- Calendar.QueryParameters
- Cancel
- Clock
- Currency
- Direction
- Exchange
- Money
- Order
- Order.QueryParameters
- OrderCancellation
- OrderClass
- OrderRequest
- OrderSide
- OrderStatus
- OrderStatusFilter
- OrderType
- Position
- PositionLiquidation
- PositionSide
- Quantity
- StopLoss
- TakeProfit
- TimeInForce