Alpaca
is a type-safe Swift client for the Alpaca trade API.
Currently a work in progress. The currently implemented methods and types are documented on the Wiki.
Alpaca
defaults to paper
trading mode.
let alpaca = Alpaca(key: Alpaca.Key(key: "[YOUR-API-KEY]", secret: "[YOUR-API-SECRET]"))
Alpaca
is primarily a closure-based API, and provides a Result
type for API responses:
let order = OrderRequest(
symbol: "AAPL",
qty: 1,
side: .buy,
type: .limit,
timeInForce: .day,
limitPrice: 320,
extendedHours: false
)
alpaca.place(order: order) { result in
switch result {
case .success(let placedOrder):
print(placedOrder)
case .failure(let error):
print(error)
}
}
Alpaca
also offers a Combine interface:
var bag = Set<AnyCancellable>()
alpaca.place(order: order).sink(
receiveCompletion: { _ in },
receiveValue: { placedOrder in
print(placedOrder)
}
).store(in: &bag)