├── .gitignore ├── Tests ├── LinuxMain.swift └── AlpacaTests │ ├── XCTestManifests.swift │ └── AlpacaTests.swift ├── scripts └── docs.sh ├── .swiftpm └── xcode │ └── package.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── README.md ├── Sources └── Alpaca │ ├── AlpacaClient+Clock.swift │ ├── AlpacaDataClient.swift │ ├── AlpacaClient.swift │ ├── Environment.swift │ ├── AlpacaClient+Calendar.swift │ ├── AlpacaClient+PortfolioHistory.swift │ ├── AlpacaClient+AccountConfigurations.swift │ ├── Common.swift │ ├── AlpacaClient+Assets.swift │ ├── AlpacaClient+Account.swift │ ├── AlpacaClient+Positions.swift │ ├── AlpacaClient+Watchlists.swift │ ├── AlpacaDataClient+Bars.swift │ ├── Utils.swift │ ├── AlpacaClient+Orders.swift │ └── AlpacaClientProtocol.swift ├── Package.swift ├── LICENSE └── docs ├── EmptyResponse └── index.html ├── Environment └── index.html ├── StringRepresentable └── index.html ├── RequestError └── index.html ├── MultiResponse └── index.html ├── AlpacaClient_EmptyResponse └── index.html ├── Calendar └── index.html ├── AlpacaClient_Environment └── index.html ├── Clock └── index.html ├── AlpacaClientProtocol └── index.html ├── NumericString └── index.html ├── Bar └── index.html ├── AccountConfigurations └── index.html ├── Bar_Timeframe └── index.html ├── PortfolioHistory └── index.html ├── Asset_Class └── index.html ├── SortDirection └── index.html ├── Order_Side └── index.html ├── Watchlist └── index.html ├── Asset_Status └── index.html ├── Position_Side └── index.html ├── AccountConfigurations_TradeConfirmEmail └── index.html ├── Order_Class └── index.html ├── Order_OrderType └── index.html ├── index.html ├── AccountConfigurations_DayTradeBuyingPowerCheck └── index.html ├── Order_TimeInForce └── index.html └── PortfolioHistory_Timeframe └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | /*.xcodeproj 5 | xcuserdata/ 6 | -------------------------------------------------------------------------------- /Tests/LinuxMain.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | import AlpacaTests 4 | 5 | var tests = [XCTestCaseEntry]() 6 | tests += AlpacaTests.allTests() 7 | XCTMain(tests) 8 | -------------------------------------------------------------------------------- /scripts/docs.sh: -------------------------------------------------------------------------------- 1 | # Generate Documentation 2 | swift doc generate "Sources" --format "html" --module-name "Alpaca" --output "docs" --base-url "/alpaca-swift/" 3 | 4 | -------------------------------------------------------------------------------- /.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Tests/AlpacaTests/XCTestManifests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | #if !canImport(ObjectiveC) 4 | public func allTests() -> [XCTestCaseEntry] { 5 | return [ 6 | testCase(AlpacaTests.allTests), 7 | ] 8 | } 9 | #endif 10 | -------------------------------------------------------------------------------- /.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Alpaca Swift 2 | 3 | A fully-typed, Linux compatible, [Alpaca](https://alpaca.markets) library written in Swift 5.5. 4 | 5 | #### Features 6 | 7 | - Swift Package Manager 8 | - 100% async/await 9 | - SwiftNIO HTTP client via [AsyncHTTPClient](https://github.com/swift-server/async-http-client.git) 10 | - 100% Unit Test Coverage 11 | 12 | #### Documentation 13 | 14 | [https://andrewbarba.github.io/alpaca-swift/](https://andrewbarba.github.io/alpaca-swift/) 15 | -------------------------------------------------------------------------------- /Sources/Alpaca/AlpacaClient+Clock.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AlpacaClient+Clock.swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/15/20. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct Clock: Codable { 11 | public let timestamp: Date 12 | public let isOpen: Bool 13 | public let nextOpen: Date 14 | public let nextClose: Date 15 | } 16 | 17 | extension AlpacaClient { 18 | public func clock() async throws -> Clock { 19 | return try await get("clock") 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/Alpaca/AlpacaDataClient.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/25/20. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct AlpacaDataClient: AlpacaClientProtocol { 11 | 12 | public let environment: Environment 13 | 14 | public let timeoutInterval: TimeInterval 15 | 16 | internal init(key: String, secret: String, timeoutInterval: TimeInterval) { 17 | self.environment = .data(key: key, secret: secret) 18 | self.timeoutInterval = timeoutInterval 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/Alpaca/AlpacaClient.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public struct AlpacaClient: AlpacaClientProtocol { 4 | 5 | public let environment: Environment 6 | 7 | public let data: AlpacaDataClient 8 | 9 | public let timeoutInterval: TimeInterval 10 | 11 | public init(_ environment: Environment, timeoutInterval: TimeInterval = 10, dataTimeoutInterval: TimeInterval = 10) { 12 | self.environment = environment 13 | self.timeoutInterval = timeoutInterval 14 | self.data = AlpacaDataClient(key: environment.key, secret: environment.secret, timeoutInterval: dataTimeoutInterval) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.5 2 | 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "Alpaca", 7 | platforms: [ 8 | .iOS("15.0"), 9 | .macOS("12.0"), 10 | .tvOS("15.0"), 11 | .watchOS("8.0") 12 | ], 13 | products: [ 14 | .library(name: "Alpaca", targets: ["Alpaca"]) 15 | ], 16 | dependencies: [], 17 | targets: [ 18 | .target( 19 | name: "Alpaca", 20 | dependencies: [] 21 | ), 22 | .testTarget( 23 | name: "AlpacaTests", 24 | dependencies: ["Alpaca"] 25 | ) 26 | ], 27 | swiftLanguageVersions: [.version("5.5")] 28 | ) 29 | -------------------------------------------------------------------------------- /Sources/Alpaca/Environment.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/25/20. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct Environment { 11 | public let api: String 12 | public let key: String 13 | public let secret: String 14 | 15 | internal static func data(key: String, secret: String) -> Self { 16 | Environment(api: "https://data.alpaca.markets/v1", key: key, secret: secret) 17 | } 18 | 19 | public static func live(key: String, secret: String) -> Self { 20 | Environment(api: "https://api.alpaca.markets/v2", key: key, secret: secret) 21 | } 22 | 23 | public static func paper(key: String, secret: String) -> Self { 24 | Environment(api: "https://paper-api.alpaca.markets/v2", key: key, secret: secret) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sources/Alpaca/AlpacaClient+Calendar.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AlpacaClient+Calendar.swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/15/20. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct Calendar: Codable { 11 | public let date: Date 12 | public let open: String 13 | public let close: String 14 | } 15 | 16 | extension AlpacaClient { 17 | public func calendar(start: String? = nil, end: String? = nil) async throws -> [Calendar] { 18 | return try await get("calendar", searchParams: ["start": start, "end": end]) 19 | } 20 | 21 | public func calendar(start: Date? = nil, end: Date? = nil) async throws -> [Calendar] { 22 | return try await calendar( 23 | start: start.map(Utils.iso8601DateOnlyFormatter.string), 24 | end: end.map(Utils.iso8601DateOnlyFormatter.string) 25 | ) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Andrew Barba 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Sources/Alpaca/AlpacaClient+PortfolioHistory.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AlpacaClient+PortfolioHistory.swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/15/20. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct PortfolioHistory: Codable { 11 | public enum Timeframe: String, Codable, CaseIterable { 12 | case oneMin = "1Min" 13 | case fiveMin = "5Min" 14 | case fifteenMin = "15Min" 15 | case oneHour = "1H" 16 | case oneDay = "1D" 17 | } 18 | 19 | public let timestamp: [Int] 20 | public let equity: [Double] 21 | public let profitLoss: [Double] 22 | public let profitLossPct: [Double] 23 | public let baseValue: Double 24 | public let timeframe: Timeframe 25 | } 26 | 27 | extension AlpacaClient { 28 | public func portfolioHistory(period: String? = nil, timeframe: PortfolioHistory.Timeframe? = nil, dateEnd: Date? = nil, extendedHours: Bool? = nil) async throws -> PortfolioHistory { 29 | return try await get("account/portfolio/history", searchParams: [ 30 | "period": period, 31 | "timeframe": timeframe?.rawValue, 32 | "date_end": dateEnd.map(Utils.iso8601DateOnlyFormatter.string), 33 | "extended_hours": extendedHours.map(String.init) 34 | ]) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Sources/Alpaca/AlpacaClient+AccountConfigurations.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AlpacaClient+AccountConfiguration.swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/15/20. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct AccountConfigurations: Codable { 11 | public enum DayTradeBuyingPowerCheck: String, Codable, CaseIterable { 12 | case both = "both" 13 | case entry = "entry" 14 | case exit = "exit" 15 | } 16 | 17 | public enum TradeConfirmEmail: String, Codable, CaseIterable { 18 | case all = "all" 19 | case none = "none" 20 | } 21 | 22 | public var dtbpCheck: DayTradeBuyingPowerCheck 23 | public var noShorting: Bool 24 | public var suspendTrade: Bool 25 | public var tradeConfirmEmail: TradeConfirmEmail 26 | } 27 | 28 | extension AlpacaClient { 29 | public func accountConfigurations() async throws -> AccountConfigurations { 30 | return try await get("account/configurations") 31 | } 32 | 33 | public func saveAccountConfigurations(_ configurations: AccountConfigurations) async throws -> AccountConfigurations { 34 | return try await patch("account/configurations", body: configurations) 35 | } 36 | 37 | public func saveAccountConfigurations(dtbpCheck: AccountConfigurations.DayTradeBuyingPowerCheck? = nil, noShorting: Bool? = nil, suspendTrade: Bool? = nil, tradeConfirmEmail: AccountConfigurations.TradeConfirmEmail? = nil) async throws -> AccountConfigurations { 38 | return try await patch("account/configurations", body: [ 39 | "dtbp_check": dtbpCheck?.rawValue, 40 | "no_shorting": noShorting, 41 | "suspend_trade": suspendTrade, 42 | "trade_confirm_email": tradeConfirmEmail?.rawValue 43 | ]) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/Alpaca/Common.swift: -------------------------------------------------------------------------------- 1 | // 2 | // swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/15/20. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct EmptyResponse: Decodable { 11 | internal static let jsonData = try! JSONSerialization.data(withJSONObject: [:], options: []) 12 | } 13 | 14 | public enum RequestError: Error { 15 | case invalidURL 16 | case status(Int) 17 | } 18 | 19 | public struct MultiResponse: Codable where T: Codable { 20 | public let status: Int 21 | public let body: T 22 | } 23 | 24 | public enum SortDirection: String, Codable, CaseIterable { 25 | case asc = "asc" 26 | case desc = "desc" 27 | } 28 | 29 | public protocol StringRepresentable: CustomStringConvertible { 30 | init?(_ string: String) 31 | } 32 | 33 | extension Double: StringRepresentable {} 34 | 35 | extension Float: StringRepresentable {} 36 | 37 | extension Int: StringRepresentable {} 38 | 39 | public struct NumericString: Codable { 40 | public var value: Value 41 | 42 | public init(from decoder: Decoder) throws { 43 | let container = try decoder.singleValueContainer() 44 | let string = try container.decode(String.self) 45 | 46 | guard let value = Value(string) else { 47 | throw DecodingError.dataCorruptedError( 48 | in: container, 49 | debugDescription: """ 50 | Failed to convert an instance of \(Value.self) from "\(string)" 51 | """ 52 | ) 53 | } 54 | 55 | self.value = value 56 | } 57 | 58 | public func encode(to encoder: Encoder) throws { 59 | var container = encoder.singleValueContainer() 60 | try container.encode(value.description) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Sources/Alpaca/AlpacaClient+Assets.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AlpacaClient+Assets.swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/15/20. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct Asset: Codable, Identifiable { 11 | public enum Class: String, Codable, CaseIterable { 12 | case usEquity = "us_equity" 13 | } 14 | 15 | public enum Exchange: String, Codable, CaseIterable { 16 | case amex = "AMEX" 17 | case arca = "ARCA" 18 | case bats = "BATS" 19 | case nyse = "NYSE" 20 | case nasdaq = "NASDAQ" 21 | case nyseArca = "NYSEARCA" 22 | case otc = "OTC" 23 | } 24 | 25 | public enum Status: String, Codable, CaseIterable { 26 | case active = "active" 27 | case inactive = "inactive" 28 | } 29 | 30 | public let id: UUID 31 | public let `class`: Class 32 | public let exchange: Exchange 33 | public let symbol: String 34 | public let name: String 35 | public let status: Status 36 | public let tradable: Bool 37 | public let marginable: Bool 38 | public let shortable: Bool 39 | public let easyToBorrow: Bool 40 | } 41 | 42 | extension AlpacaClient { 43 | public func assets(status: Asset.Status? = nil, assetClass: Asset.Class? = nil) async throws -> [Asset] { 44 | return try await get("assets", searchParams: ["status": status?.rawValue, "asset_class": assetClass?.rawValue]) 45 | } 46 | 47 | public func asset(id: String) async throws -> Asset { 48 | return try await get("assets/\(id)") 49 | } 50 | 51 | public func asset(id: UUID) async throws -> Asset { 52 | return try await get("assets/\(id.uuidString)") 53 | } 54 | 55 | public func asset(symbol: String) async throws -> Asset { 56 | return try await get("assets/\(symbol)") 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Sources/Alpaca/AlpacaClient+Account.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AlpacaClient+Account.swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/15/20. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct Account: Codable, Identifiable { 11 | public enum Status: String, Codable, CaseIterable { 12 | case onboarding = "ONBOARDING" 13 | case submissionFailed = "SUBMISSION_FAILED" 14 | case submitted = "SUBMITTED" 15 | case accountUpdated = "ACCOUNT_UPDATED" 16 | case approvalPending = "APPROVAL_PENDING" 17 | case active = "ACTIVE" 18 | case rejected = "REJECTED" 19 | } 20 | 21 | public let id: UUID 22 | public let accountNumber: String 23 | public let currency: String 24 | public let cash: NumericString 25 | public let status: Status 26 | public let patternDayTrader: Bool 27 | public let tradeSuspendedByUser: Bool 28 | public let tradingBlocked: Bool 29 | public let transfersBlocked: Bool 30 | public let accountBlocked: Bool 31 | public let createdAt: Date 32 | public let shortingEnabled: Bool 33 | public let longMarketValue: NumericString 34 | public let shortMarketValue: NumericString 35 | public let equity: NumericString 36 | public let lastEquity: NumericString 37 | public let multiplier: NumericString 38 | public let buyingPower: NumericString 39 | public let initialMargin: NumericString 40 | public let maintenanceMargin: NumericString 41 | public let sma: NumericString 42 | public let daytradeCount: Int 43 | public let lastMaintenanceMargin: NumericString 44 | public let daytradingBuyingPower: NumericString 45 | public let regtBuyingPower: NumericString 46 | } 47 | 48 | extension AlpacaClient { 49 | public func account() async throws -> Account { 50 | return try await get("account") 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Sources/Alpaca/AlpacaClient+Positions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AlpacaClient+Positions.swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/16/20. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct Position: Codable { 11 | public enum Side: String, Codable, CaseIterable { 12 | case long = "long" 13 | case short = "short" 14 | } 15 | 16 | public let assetId: UUID 17 | public let symbol: String 18 | public let exchange: Asset.Exchange 19 | public let assetClass: Asset.Class 20 | public let avgEntryPrice: NumericString 21 | public let qty: NumericString 22 | public let side: Side 23 | public let marketValue: NumericString 24 | public let costBasis: NumericString 25 | public let unrealizedPl: NumericString 26 | public let unrealizedPlpc: NumericString 27 | public let unrealizedIntradayPl: NumericString 28 | public let unrealizedIntradayPlpc: NumericString 29 | public let currentPrice: NumericString 30 | public let lastdayPrice: NumericString 31 | public let changeToday: NumericString 32 | } 33 | 34 | extension AlpacaClient { 35 | public func positions() async throws -> [Position] { 36 | return try await get("positions") 37 | } 38 | 39 | public func position(assetId: String) async throws -> Position { 40 | return try await get("positions/\(assetId)") 41 | } 42 | 43 | public func position(assetId: UUID) async throws -> Position { 44 | return try await get("positions/\(assetId.uuidString)") 45 | } 46 | 47 | public func position(symbol: String) async throws -> Position { 48 | return try await get("positions/\(symbol)") 49 | } 50 | 51 | public func closePositions() async throws -> [MultiResponse] { 52 | return try await delete("positions") 53 | } 54 | 55 | public func closePosition(assetId: String) async throws -> Order { 56 | return try await delete("positions/\(assetId)") 57 | } 58 | 59 | public func closePosition(assetId: UUID) async throws -> Order { 60 | return try await delete("positions/\(assetId.uuidString)") 61 | } 62 | 63 | public func closePosition(symbol: String) async throws -> Order { 64 | return try await delete("positions/\(symbol)") 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Sources/Alpaca/AlpacaClient+Watchlists.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/17/20. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct Watchlist: Codable, Identifiable { 11 | public let id: UUID 12 | public let accountId: UUID 13 | public let name: String 14 | public let createdAt: Date 15 | public let updatedAt: Date 16 | public let assets: [Asset]? 17 | } 18 | 19 | extension AlpacaClient { 20 | public func watchlists() async throws -> [Watchlist] { 21 | return try await get("watchlists") 22 | } 23 | 24 | public func createWatchlist(name: String, symbols: [String]) async throws -> Watchlist { 25 | return try await post("watchlists", body: ["name": name, "symbols": symbols]) 26 | } 27 | 28 | public func watchlist(id: String) async throws -> Watchlist { 29 | return try await get("watchlists/\(id)") 30 | } 31 | 32 | public func watchlist(id: UUID) async throws -> Watchlist { 33 | return try await get("watchlists/\(id.uuidString)") 34 | } 35 | 36 | public func updateWatchlist(id: String, name: String? = nil, symbols: [String]? = nil) async throws -> Watchlist { 37 | return try await put("watchlists/\(id)", body: ["name": name, "symbols": symbols]) 38 | } 39 | 40 | public func updateWatchlist(id: UUID, name: String? = nil, symbols: [String]? = nil) async throws -> Watchlist { 41 | return try await put("watchlists/\(id.uuidString)", body: ["name": name, "symbols": symbols]) 42 | } 43 | 44 | public func updateWatchlist(id: String, add symbol: String) async throws -> Watchlist { 45 | return try await post("watchlists/\(id)", body: ["symbol": symbol]) 46 | } 47 | 48 | public func updateWatchlist(id: UUID, add symbol: String) async throws -> Watchlist { 49 | return try await post("watchlists/\(id.uuidString)", body: ["symbol": symbol]) 50 | } 51 | 52 | public func updateWatchlist(id: String, remove symbol: String) async throws -> Watchlist { 53 | return try await delete("watchlists/\(id)/\(symbol)") 54 | } 55 | 56 | public func updateWatchlist(id: UUID, remove symbol: String) async throws -> Watchlist { 57 | return try await delete("watchlists/\(id.uuidString)/\(symbol)") 58 | } 59 | 60 | public func deleteWatchlist(id: String) async throws -> EmptyResponse { 61 | return try await delete("watchlists/\(id)") 62 | } 63 | 64 | public func deleteWatchlist(id: UUID) async throws -> EmptyResponse { 65 | return try await delete("watchlists/\(id.uuidString)") 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Sources/Alpaca/AlpacaDataClient+Bars.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/25/20. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct Bar: Codable { 11 | public enum Timeframe: String, CaseIterable { 12 | case oneMin = "1Min" 13 | case fiveMin = "5Min" 14 | case fifteenMin = "15Min" 15 | case oneDay = "1D" 16 | } 17 | 18 | private let t: Double 19 | public var timeframe: Double { t } 20 | 21 | private let o: Double 22 | public var open: Double { o } 23 | 24 | private let h: Double 25 | public var high: Double { h } 26 | 27 | private let l: Double 28 | public var low: Double { l } 29 | 30 | private let c: Double 31 | public var close: Double { c } 32 | 33 | private let v: Double 34 | public var volume: Double { v } 35 | } 36 | 37 | extension AlpacaDataClient { 38 | 39 | public func bars(_ timeframe: Bar.Timeframe, symbols: [String], limit: Int? = nil, start: Date? = nil, end: Date? = nil, after: Date? = nil, until: Date? = nil) async throws -> [String: [Bar]] { 40 | return try await get("bars/\(timeframe.rawValue)", searchParams: [ 41 | "symbols": symbols.joined(separator: ","), 42 | "limit": limit.map(String.init), 43 | "start": start.map(Utils.iso8601DateFormatter.string), 44 | "end": end.map(Utils.iso8601DateFormatter.string), 45 | "after": after.map(Utils.iso8601DateFormatter.string), 46 | "until": until.map(Utils.iso8601DateFormatter.string) 47 | ]) 48 | } 49 | 50 | public func bars(_ timeframe: Bar.Timeframe, symbol: String, limit: Int? = nil, start: Date? = nil, end: Date? = nil, after: Date? = nil, until: Date? = nil) async throws -> [Bar] { 51 | let res = try await bars(timeframe, symbols: [symbol], limit: limit, start: start, end: end, after: after, until: until) 52 | return res[symbol, default: []] 53 | } 54 | 55 | public func bars(_ timeframe: Bar.Timeframe, assets: [Asset], limit: Int? = nil, start: Date? = nil, end: Date? = nil, after: Date? = nil, until: Date? = nil) async throws -> [String: [Bar]] { 56 | return try await bars(timeframe, symbols: assets.map(\.symbol), limit: limit, start: start, end: end, after: after, until: until) 57 | } 58 | 59 | public func bars(_ timeframe: Bar.Timeframe, asset: Asset, limit: Int? = nil, start: Date? = nil, end: Date? = nil, after: Date? = nil, until: Date? = nil) async throws -> [Bar] { 60 | return try await bars(timeframe, symbol: asset.symbol, limit: limit, start: start, end: end, after: after, until: until) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Sources/Alpaca/Utils.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Utils.swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/15/20. 6 | // 7 | 8 | import Foundation 9 | 10 | internal enum Utils { 11 | 12 | static let iso8601DateFormatter: DateFormatter = { 13 | let formatter = DateFormatter() 14 | formatter.calendar = Foundation.Calendar(identifier: .iso8601) 15 | formatter.locale = Locale(identifier: "en_US_POSIX") 16 | formatter.timeZone = TimeZone(secondsFromGMT: 0) 17 | formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" 18 | return formatter 19 | }() 20 | 21 | static let iso8601DateOnlyFormatter: DateFormatter = { 22 | let formatter = DateFormatter() 23 | formatter.calendar = Foundation.Calendar(identifier: .iso8601) 24 | formatter.locale = Locale(identifier: "en_US_POSIX") 25 | formatter.timeZone = TimeZone(secondsFromGMT: 0) 26 | formatter.dateFormat = "yyyy-MM-dd" 27 | return formatter 28 | }() 29 | 30 | static let iso8601DateMillisecondsFormatter: DateFormatter = { 31 | let formatter = DateFormatter() 32 | formatter.calendar = Foundation.Calendar(identifier: .iso8601) 33 | formatter.locale = Locale(identifier: "en_US_POSIX") 34 | formatter.timeZone = TimeZone(secondsFromGMT: 0) 35 | formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" 36 | return formatter 37 | }() 38 | 39 | static let jsonEncoder: JSONEncoder = { 40 | let encoder = JSONEncoder() 41 | encoder.keyEncodingStrategy = .convertToSnakeCase 42 | encoder.dateEncodingStrategy = .iso8601 43 | return encoder 44 | }() 45 | 46 | static let jsonDecoder: JSONDecoder = { 47 | let decoder = JSONDecoder() 48 | decoder.keyDecodingStrategy = .convertFromSnakeCase 49 | decoder.nonConformingFloatDecodingStrategy = .convertFromString( 50 | positiveInfinity: "Infinity", 51 | negativeInfinity: "-Infinity", 52 | nan: "NaN" 53 | ) 54 | decoder.dateDecodingStrategy = .custom({ decoder in 55 | let container = try decoder.singleValueContainer() 56 | let value = try container.decode(String.self) 57 | if let date = Self.iso8601DateFormatter.date(from: value) { 58 | return date 59 | } 60 | if let date = Self.iso8601DateMillisecondsFormatter.date(from: value) { 61 | return date 62 | } 63 | if let date = Self.iso8601DateOnlyFormatter.date(from: value) { 64 | return date 65 | } 66 | throw DecodingError.dataCorruptedError(in: container, debugDescription: "Invalid date format: \(value)") 67 | }) 68 | return decoder 69 | }() 70 | } 71 | -------------------------------------------------------------------------------- /docs/EmptyResponse/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - EmptyResponse 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Structure 37 | Empty​Response 38 |

39 | 40 |
public struct EmptyResponse: Decodable
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | EmptyResponse 57 | 58 | 59 | EmptyResponse 60 | 61 | 62 | 63 | 64 | 65 | Decodable 66 | 67 | 68 | Decodable 69 | 70 | 71 | 72 | 73 | 74 | EmptyResponse->Decodable 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 |

Conforms To

85 |
86 |
Decodable
87 |
88 |
89 | 90 | 91 | 92 | 93 |
94 |
95 | 96 |
97 |

98 | Generated on using swift-doc 1.0.0-beta.3. 99 |

100 |
101 | 102 | 103 | -------------------------------------------------------------------------------- /Tests/AlpacaTests/AlpacaTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | @testable import Alpaca 3 | 4 | enum Environment: String { 5 | case alpacaApiKey = "ALPACA_API_KEY" 6 | case alpacaApiSecret = "ALPACA_API_SECRET" 7 | 8 | var value: String { 9 | return ProcessInfo.processInfo.environment[rawValue] ?? "" 10 | } 11 | } 12 | 13 | final class AlpacaTests: XCTestCase { 14 | 15 | let client = AlpacaClient(.paper(key: Environment.alpacaApiKey.value, secret: Environment.alpacaApiSecret.value)) 16 | 17 | func testClientAPI() { 18 | XCTAssertEqual(client.environment.api, "https://paper-api.alpaca.markets/v2") 19 | } 20 | 21 | func testAccountRequest() async throws { 22 | _ = try await client.account() 23 | } 24 | 25 | func testAccountConfigurationsRequest() async throws { 26 | _ = try await client.accountConfigurations() 27 | } 28 | 29 | func testAccountConfigurationsUpdateRequest() async throws { 30 | _ = try await client.saveAccountConfigurations(dtbpCheck: .exit) 31 | } 32 | 33 | func testAssetsRequest() async throws { 34 | _ = try await client.assets(status: .inactive) 35 | } 36 | 37 | func testAssetSymbolRequest() async throws { 38 | _ = try await client.asset(symbol: "AAPL") 39 | } 40 | 41 | func testClockRequest() async throws { 42 | _ = try await client.clock() 43 | } 44 | 45 | func testCalendarRequest() async throws { 46 | _ = try await client.calendar(start: "2020-01-01", end: "2020-01-07") 47 | } 48 | 49 | func testPortfolioHistoryRequest() async throws { 50 | _ = try await client.portfolioHistory() 51 | } 52 | 53 | func testPositionsRequest() async throws { 54 | _ = try await client.positions() 55 | } 56 | 57 | func testClosePositionsRequest() async throws { 58 | _ = try await client.closePositions() 59 | } 60 | 61 | func testOrdersRequest() async throws { 62 | _ = try await client.orders() 63 | } 64 | 65 | func testCreateOrderRequest() async throws { 66 | _ = try await client.createOrder(symbol: "AAPL", qty: 2, side: .buy, type: .market, timeInForce: .day) 67 | } 68 | 69 | func testCancelOrdersRequest() async throws { 70 | _ = try await client.cancelOrders() 71 | } 72 | 73 | func testWatchlistsRequest() async throws { 74 | _ = try await client.watchlists() 75 | } 76 | 77 | func testCreateAndDeleteWatchlistRequest() async throws { 78 | _ = try await client.createWatchlist(name: "[Swift] \(UUID().uuidString)", symbols: ["AAPL"]) 79 | } 80 | 81 | func testDataBarsRequest() async throws { 82 | _ = _ = try await client.data.bars(.oneDay, symbol: "AAPL", limit: 1) 83 | } 84 | 85 | func testDataBarsMultiRequest() async throws { 86 | _ = _ = try await client.data.bars(.oneDay, symbols: ["AAPL", "FSLY"], limit: 1) 87 | } 88 | 89 | static var allTests = [ 90 | ("testAccountRequest", testAssetsRequest), 91 | ("testAccountConfigurationsRequest", testAccountConfigurationsRequest), 92 | ("testAccountConfigurationsUpdateRequest", testAccountConfigurationsUpdateRequest), 93 | ("testAssetsRequest", testAssetsRequest), 94 | ("testAssetSymbolRequest", testAssetSymbolRequest), 95 | ("testClientAPI", testClientAPI), 96 | ("testCalendarRequest", testCalendarRequest), 97 | ("testClockRequest", testClockRequest), 98 | ("testPortfolioHistoryRequest", testPortfolioHistoryRequest), 99 | ("testPositionsRequest", testPositionsRequest), 100 | ("testClosePositionsRequest", testClosePositionsRequest), 101 | ("testOrdersRequest", testOrdersRequest), 102 | ("testCreateOrderRequest", testCreateOrderRequest), 103 | ("testCancelOrdersRequest", testCancelOrdersRequest), 104 | ("testWatchlistsRequest", testWatchlistsRequest), 105 | ("testCreateAndDeleteWatchlistRequest", testCreateAndDeleteWatchlistRequest), 106 | ("testDataBarsRequest", testDataBarsRequest), 107 | ("testDataBarsMultiRequest", testDataBarsMultiRequest) 108 | ] 109 | } 110 | -------------------------------------------------------------------------------- /docs/Environment/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - Environment 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Structure 37 | Environment 38 |

39 | 40 |
public struct Environment
41 | 42 |
43 |

Properties

44 | 45 |
46 |

47 | api 48 |

49 |
let api: String
50 |
51 |
52 |

53 | key 54 |

55 |
let key: String
56 |
57 |
58 |

59 | secret 60 |

61 |
let secret: String
62 |
63 |
64 |
65 |

Methods

66 | 67 |
68 |

69 | live(key:​secret:​) 70 |

71 |
public static func live(key: String, secret: String) -> Self
72 |
73 |
74 |

75 | paper(key:​secret:​) 76 |

77 |
public static func paper(key: String, secret: String) -> Self
78 |
79 |
80 | 81 | 82 | 83 |
84 |
85 | 86 |
87 |

88 | Generated on using swift-doc 1.0.0-beta.3. 89 |

90 |
91 | 92 | 93 | -------------------------------------------------------------------------------- /docs/StringRepresentable/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - StringRepresentable 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Protocol 37 | String​Representable 38 |

39 | 40 |
public protocol StringRepresentable: CustomStringConvertible
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | StringRepresentable 57 | 58 | 59 | StringRepresentable 60 | 61 | 62 | 63 | 64 | 65 | CustomStringConvertible 66 | 67 | 68 | CustomStringConvertible 69 | 70 | 71 | 72 | 73 | 74 | StringRepresentable->CustomStringConvertible 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 |

Conforms To

85 |
86 |
CustomStringConvertible
87 |
88 |
89 | 90 | 91 | 92 | 93 |
94 |
95 | 96 |
97 |

98 | Generated on using swift-doc 1.0.0-beta.3. 99 |

100 |
101 | 102 | 103 | -------------------------------------------------------------------------------- /docs/RequestError/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - RequestError 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Enumeration 37 | Request​Error 38 |

39 | 40 |
public enum RequestError
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | RequestError 57 | 58 | 59 | RequestError 60 | 61 | 62 | 63 | 64 | 65 | Error 66 | 67 | 68 | Error 69 | 70 | 71 | 72 | 73 | 74 | RequestError->Error 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 |

Conforms To

85 |
86 |
Error
87 |
88 |
89 |
90 |

Enumeration Cases

91 | 92 |
93 |

94 | invalid​URL 95 |

96 |
case invalidURL
97 |
98 |
99 |

100 | status 101 |

102 |
case status(: HTTPResponseStatus)
103 |
104 |
105 | 106 | 107 | 108 |
109 |
110 | 111 |
112 |

113 | Generated on using swift-doc 1.0.0-beta.3. 114 |

115 |
116 | 117 | 118 | -------------------------------------------------------------------------------- /docs/MultiResponse/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - MultiResponse 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Structure 37 | Multi​Response 38 |

39 | 40 |
public struct MultiResponse<T>: Codable where T: Codable
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | MultiResponse 57 | 58 | 59 | MultiResponse 60 | 61 | 62 | 63 | 64 | 65 | Codable 66 | 67 | 68 | Codable 69 | 70 | 71 | 72 | 73 | 74 | MultiResponse->Codable 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 |

Conforms To

85 |
86 |
Codable
87 |
88 |
89 |
90 |

Properties

91 | 92 |
93 |

94 | status 95 |

96 |
let status: Int
97 |
98 |
99 |

100 | body 101 |

102 |
let body: T
103 |
104 |
105 | 106 | 107 | 108 |
109 |
110 | 111 |
112 |

113 | Generated on using swift-doc 1.0.0-beta.3. 114 |

115 |
116 | 117 | 118 | -------------------------------------------------------------------------------- /docs/AlpacaClient_EmptyResponse/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - AlpacaClient.EmptyResponse 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Structure 37 | Alpaca​Client.​Empty​Response 38 |

39 | 40 |
public struct EmptyResponse: Decodable
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | AlpacaClient.EmptyResponse 57 | 58 | 59 | AlpacaClient.EmptyResponse 60 | 61 | 62 | 63 | 64 | 65 | Decodable 66 | 67 | 68 | Decodable 69 | 70 | 71 | 72 | 73 | 74 | AlpacaClient.EmptyResponse->Decodable 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 |

Member Of

85 |
86 |
AlpacaClient
87 |
88 |
89 |

Conforms To

90 |
91 |
Decodable
92 |
93 |
94 |
95 |

Properties

96 | 97 |
98 |

99 | json​Data 100 |

101 |
let jsonData = try! JSONSerialization.data(withJSONObject: [:], options: [])
102 |
103 |
104 | 105 | 106 | 107 |
108 |
109 | 110 |
111 |

112 | Generated on using swift-doc 1.0.0-beta.3. 113 |

114 |
115 | 116 | 117 | -------------------------------------------------------------------------------- /docs/Calendar/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - Calendar 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Structure 37 | Calendar 38 |

39 | 40 |
public struct Calendar: Codable
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | Calendar 57 | 58 | 59 | Calendar 60 | 61 | 62 | 63 | 64 | 65 | Codable 66 | 67 | 68 | Codable 69 | 70 | 71 | 72 | 73 | 74 | Calendar->Codable 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 |

Conforms To

85 |
86 |
Codable
87 |
88 |
89 |
90 |

Properties

91 | 92 |
93 |

94 | date 95 |

96 |
let date: Date
97 |
98 |
99 |

100 | open 101 |

102 |
let open: String
103 |
104 |
105 |

106 | close 107 |

108 |
let close: String
109 |
110 |
111 | 112 | 113 | 114 |
115 |
116 | 117 |
118 |

119 | Generated on using swift-doc 1.0.0-beta.3. 120 |

121 |
122 | 123 | 124 | -------------------------------------------------------------------------------- /docs/AlpacaClient_Environment/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - AlpacaClient.Environment 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Structure 37 | Alpaca​Client.​Environment 38 |

39 | 40 |
public struct Environment
41 |
42 | 43 | 44 |

Member Of

45 |
46 |
AlpacaClient
47 |
48 |
49 |
50 |
51 |

Properties

52 | 53 |
54 |

55 | api 56 |

57 |
let api: String
58 |
59 |
60 |

61 | key 62 |

63 |
let key: String
64 |
65 |
66 |

67 | secret 68 |

69 |
let secret: String
70 |
71 |
72 |
73 |

Methods

74 | 75 |
76 |

77 | data(key:​secret:​) 78 |

79 |
public static func data(key: String, secret: String) -> Self
80 |
81 |
82 |

83 | live(key:​secret:​) 84 |

85 |
public static func live(key: String, secret: String) -> Self
86 |
87 |
88 |

89 | paper(key:​secret:​) 90 |

91 |
public static func paper(key: String, secret: String) -> Self
92 |
93 |
94 | 95 | 96 | 97 |
98 |
99 | 100 |
101 |

102 | Generated on using swift-doc 1.0.0-beta.3. 103 |

104 |
105 | 106 | 107 | -------------------------------------------------------------------------------- /Sources/Alpaca/AlpacaClient+Orders.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AlpacaClient+Orders.swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/16/20. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct Order: Codable, Identifiable { 11 | public enum Class: String, Codable, CaseIterable { 12 | case simple = "simple" 13 | case bracket = "bracket" 14 | case oco = "oco" 15 | case oto = "oto" 16 | } 17 | 18 | public enum Side: String, Codable, CaseIterable { 19 | case buy = "buy" 20 | case sell = "sell" 21 | } 22 | 23 | public enum Status: String, Codable, CaseIterable { 24 | case new = "new" 25 | case partiallyFilled = "partially_filled" 26 | case filled = "filled" 27 | case doneForDay = "done_for_day" 28 | case canceled = "canceled" 29 | case expired = "expired" 30 | case replaced = "replaced" 31 | case pendingCancel = "pending_cancel" 32 | case pendingReplace = "pending_replace" 33 | case accepted = "accepted" 34 | case pendingNew = "pending_new" 35 | case acceptedForBidding = "accepted_for_bidding" 36 | case stopped = "stopped" 37 | case rejected = "rejected" 38 | case suspended = "suspended" 39 | case calculated = "calculated" 40 | 41 | // Used as query params 42 | public static let open = "open" 43 | public static let closed = "closed" 44 | public static let all = "all" 45 | } 46 | 47 | public enum OrderType: String, Codable, CaseIterable { 48 | case market = "market" 49 | case limit = "limit" 50 | case stop = "stop" 51 | case stopLimit = "stop_limit" 52 | } 53 | 54 | public enum TimeInForce: String, Codable, CaseIterable { 55 | case day = "day" 56 | case gtc = "gtc" 57 | case opg = "opg" 58 | case cls = "cls" 59 | case ioc = "ioc" 60 | case fok = "fok" 61 | } 62 | 63 | public let id: UUID 64 | public let clientOrderId: String 65 | public let createdAt: Date 66 | public let updatedAt: Date? 67 | public let submittedAt: Date? 68 | public let filledAt: Date? 69 | public let expiredAt: Date? 70 | public let canceledAt: Date? 71 | public let failedAt: Date? 72 | public let replacedAt: Date? 73 | public let replacedBy: UUID? 74 | public let replaces: UUID? 75 | public let assetId: UUID 76 | public let symbol: String 77 | public let assetClass: Asset.Class 78 | public let qty: NumericString 79 | public let filledQty: NumericString 80 | public let type: OrderType 81 | public let side: Side 82 | public let timeInForce: TimeInForce 83 | public let limitPrice: NumericString? 84 | public let stopPrice: NumericString? 85 | public let filledAvgPrice: NumericString? 86 | public let status: Status 87 | public let extendedHours: Bool 88 | public let legs: [Order]? 89 | } 90 | 91 | extension AlpacaClient { 92 | public func orders(status: String? = nil, limit: Int? = nil, after: Date? = nil, until: Date? = nil, direction: SortDirection? = nil, nested: Bool? = nil) async throws -> [Order] { 93 | return try await get("orders", searchParams: [ 94 | "status": status, 95 | "limit": limit.map(String.init), 96 | "after": after.map(Utils.iso8601DateFormatter.string), 97 | "until": until.map(Utils.iso8601DateFormatter.string), 98 | "direction": direction?.rawValue, 99 | "nested": nested.map(String.init) 100 | ]) 101 | } 102 | 103 | public func order(id: UUID, nested: Bool? = nil) async throws -> Order { 104 | return try await get("orders/\(id)", searchParams: ["nested": nested.map(String.init)]) 105 | } 106 | 107 | public func order(id: String, nested: Bool? = nil) async throws -> Order { 108 | return try await get("orders/\(id)", searchParams: ["nested": nested.map(String.init)]) 109 | } 110 | 111 | public func createOrder(symbol: String, qty: Double, side: Order.Side, type: Order.OrderType, timeInForce: Order.TimeInForce, limitPrice: Double? = nil, stopPrice: Double? = nil, extendedHours: Bool = false, `class`: Order.Class? = nil, takeProfitLimitPrice: Double? = nil, stopLoss: (stopPrice: Double, limitPrice: Double?)? = nil) async throws -> Order { 112 | return try await post("orders", body: [ 113 | "symbol": symbol, 114 | "qty": qty, 115 | "side": side.rawValue, 116 | "type": type.rawValue, 117 | "time_in_force": timeInForce.rawValue, 118 | "limit_price": limitPrice, 119 | "stop_price": stopPrice, 120 | "extended_hours": extendedHours, 121 | "order_class": `class`?.rawValue, 122 | "take_profit": takeProfitLimitPrice.map { ["limit_price": $0] }, 123 | "stop_loss": stopLoss.map { ["stop_price": $0.stopPrice, "limit_price": $0.limitPrice] } 124 | ]) 125 | } 126 | 127 | public func cancelOrders() async throws -> [MultiResponse] { 128 | return try await delete("orders") 129 | } 130 | 131 | public func cancelOrder(id: String) async throws -> Order { 132 | return try await delete("orders/\(id)") 133 | } 134 | 135 | public func cancelOrder(id: UUID) async throws -> Order { 136 | return try await delete("orders/\(id.uuidString)") 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /docs/Clock/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - Clock 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Structure 37 | Clock 38 |

39 | 40 |
public struct Clock: Codable
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | Clock 57 | 58 | 59 | Clock 60 | 61 | 62 | 63 | 64 | 65 | Codable 66 | 67 | 68 | Codable 69 | 70 | 71 | 72 | 73 | 74 | Clock->Codable 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 |

Conforms To

85 |
86 |
Codable
87 |
88 |
89 |
90 |

Properties

91 | 92 |
93 |

94 | timestamp 95 |

96 |
let timestamp: Date
97 |
98 |
99 |

100 | is​Open 101 |

102 |
let isOpen: Bool
103 |
104 |
105 |

106 | next​Open 107 |

108 |
let nextOpen: Date
109 |
110 |
111 |

112 | next​Close 113 |

114 |
let nextClose: Date
115 |
116 |
117 | 118 | 119 | 120 |
121 |
122 | 123 |
124 |

125 | Generated on using swift-doc 1.0.0-beta.3. 126 |

127 |
128 | 129 | 130 | -------------------------------------------------------------------------------- /Sources/Alpaca/AlpacaClientProtocol.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // 4 | // 5 | // Created by Andrew Barba on 8/25/20. 6 | // 7 | 8 | import Foundation 9 | #if canImport(FoundationNetworking) 10 | import FoundationNetworking 11 | #endif 12 | 13 | public typealias HTTPSearchParams = [String: String?] 14 | 15 | public typealias HTTPBodyParams = [String: Any?] 16 | 17 | public enum HTTPMethod: String { 18 | case get = "GET" 19 | case post = "POST" 20 | case put = "PUT" 21 | case patch = "PATCH" 22 | case delete = "DELETE" 23 | case options = "OPTIONS" 24 | } 25 | 26 | public protocol AlpacaClientProtocol { 27 | var environment: Environment { get } 28 | 29 | var timeoutInterval: TimeInterval { get } 30 | } 31 | 32 | // MARK: - Requests 33 | 34 | extension AlpacaClientProtocol { 35 | 36 | public func get(_ urlPath: String, searchParams: HTTPSearchParams? = nil) async throws -> T where T: Decodable { 37 | return try await request(.get, urlPath: urlPath, searchParams: searchParams) 38 | } 39 | 40 | public func delete(_ urlPath: String, searchParams: HTTPSearchParams? = nil) async throws -> T where T: Decodable { 41 | return try await request(.delete, urlPath: urlPath, searchParams: searchParams) 42 | } 43 | 44 | public func post(_ urlPath: String, searchParams: HTTPSearchParams? = nil) async throws -> T where T: Decodable { 45 | return try await request(.post, urlPath: urlPath, searchParams: searchParams) 46 | } 47 | 48 | public func post(_ urlPath: String, searchParams: HTTPSearchParams? = nil, body: V) async throws -> T where T: Decodable, V: Encodable { 49 | return try await request(.post, urlPath: urlPath, searchParams: searchParams, body: body) 50 | } 51 | 52 | public func post(_ urlPath: String, searchParams: HTTPSearchParams? = nil, body: HTTPBodyParams) async throws -> T where T: Decodable { 53 | return try await request(.post, urlPath: urlPath, searchParams: searchParams, body: body) 54 | } 55 | 56 | public func put(_ urlPath: String, searchParams: HTTPSearchParams? = nil) async throws -> T where T: Decodable { 57 | return try await request(.put, urlPath: urlPath, searchParams: searchParams) 58 | } 59 | 60 | public func put(_ urlPath: String, searchParams: HTTPSearchParams? = nil, body: V) async throws -> T where T: Decodable, V: Encodable { 61 | return try await request(.put, urlPath: urlPath, searchParams: searchParams, body: body) 62 | } 63 | 64 | public func put(_ urlPath: String, searchParams: HTTPSearchParams? = nil, body: HTTPBodyParams) async throws -> T where T: Decodable { 65 | return try await request(.put, urlPath: urlPath, searchParams: searchParams, body: body) 66 | } 67 | 68 | public func patch(_ urlPath: String, searchParams: HTTPSearchParams? = nil) async throws -> T where T: Decodable { 69 | return try await request(.patch, urlPath: urlPath, searchParams: searchParams) 70 | } 71 | 72 | public func patch(_ urlPath: String, searchParams: HTTPSearchParams? = nil, body: V) async throws -> T where T: Decodable, V: Encodable { 73 | return try await request(.patch, urlPath: urlPath, searchParams: searchParams, body: body) 74 | } 75 | 76 | public func patch(_ urlPath: String, searchParams: HTTPSearchParams? = nil, body: HTTPBodyParams) async throws -> T where T: Decodable { 77 | return try await request(.patch, urlPath: urlPath, searchParams: searchParams, body: body) 78 | } 79 | 80 | public func request(_ method: HTTPMethod, urlPath: String, searchParams: HTTPSearchParams? = nil) async throws -> T where T: Decodable { 81 | return try await request(method, urlPath: urlPath, searchParams: searchParams, httpBody: nil) 82 | } 83 | 84 | public func request(_ method: HTTPMethod, urlPath: String, searchParams: HTTPSearchParams? = nil, body: V) async throws -> T where T: Decodable, V: Encodable { 85 | let data = try Utils.jsonEncoder.encode(body) 86 | return try await request(method, urlPath: urlPath, searchParams: searchParams, httpBody: data) 87 | } 88 | 89 | public func request(_ method: HTTPMethod, urlPath: String, searchParams: HTTPSearchParams? = nil, body: HTTPBodyParams) async throws -> T where T: Decodable { 90 | let data = try JSONSerialization.data(withJSONObject: body.compactMapValues { $0 }, options: []) 91 | return try await request(method, urlPath: urlPath, searchParams: searchParams, httpBody: data) 92 | } 93 | 94 | private func request(_ method: HTTPMethod, urlPath: String, searchParams: HTTPSearchParams? = nil, httpBody: Data? = nil) async throws -> T where T: Decodable { 95 | var components = URLComponents(string: "\(environment.api)/\(urlPath)") 96 | components?.queryItems = searchParams?.compactMapValues { $0 }.map(URLQueryItem.init) 97 | 98 | guard let url = components?.url else { 99 | throw RequestError.invalidURL 100 | } 101 | 102 | var request = URLRequest(url: url) 103 | request.httpMethod = method.rawValue 104 | request.setValue(environment.key, forHTTPHeaderField: "APCA-API-KEY-ID") 105 | request.setValue(environment.secret, forHTTPHeaderField: "APCA-API-SECRET-KEY") 106 | request.setValue("application/json", forHTTPHeaderField: "Content-Type") 107 | request.setValue("alpaca-swift/1.0", forHTTPHeaderField: "User-Agent") 108 | request.httpBody = httpBody 109 | request.timeoutInterval = timeoutInterval 110 | 111 | let (data, _) = try await URLSession.shared.data(for: request) 112 | 113 | return try Utils.jsonDecoder.decode(T.self, from: data) 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /docs/AlpacaClientProtocol/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - AlpacaClientProtocol 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Protocol 37 | Alpaca​Client​Protocol 38 |

39 | 40 |
public protocol AlpacaClientProtocol
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | AlpacaClientProtocol 57 | 58 | 59 | AlpacaClientProtocol 60 | 61 | 62 | 63 | 64 | 65 | AlpacaDataClient 66 | 67 | 68 | AlpacaDataClient 69 | 70 | 71 | 72 | 73 | 74 | AlpacaDataClient->AlpacaClientProtocol 75 | 76 | 77 | 78 | 79 | 80 | AlpacaClient 81 | 82 | 83 | AlpacaClient 84 | 85 | 86 | 87 | 88 | 89 | AlpacaClient->AlpacaClientProtocol 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 |
99 |

Types Conforming to Alpaca​Client​Protocol

100 |
101 |
AlpacaClient
102 |
103 |
AlpacaDataClient
104 |
105 |
106 |
107 | 108 | 109 | 110 |
111 |

Requirements

112 | 113 |
114 |

115 | environment 116 |

117 |
var environment: Environment
118 |
119 |
120 |
121 |
122 | 123 |
124 |

125 | Generated on using swift-doc 1.0.0-beta.3. 126 |

127 |
128 | 129 | 130 | -------------------------------------------------------------------------------- /docs/NumericString/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - NumericString 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Structure 37 | Numeric​String 38 |

39 | 40 |
public struct NumericString<Value: StringRepresentable>: Codable
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | NumericString 57 | 58 | 59 | NumericString 60 | 61 | 62 | 63 | 64 | 65 | Codable 66 | 67 | 68 | Codable 69 | 70 | 71 | 72 | 73 | 74 | NumericString->Codable 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 |

Conforms To

85 |
86 |
Codable
87 |
88 |
89 |
90 |

Initializers

91 | 92 |
93 |

94 | init(from:​) 95 |

96 |
public init(from decoder: Decoder) throws
97 |
98 |
99 |
100 |

Properties

101 | 102 |
103 |

104 | value 105 |

106 |
var value: Value
107 |
108 |
109 |
110 |

Methods

111 | 112 |
113 |

114 | encode(to:​) 115 |

116 |
public func encode(to encoder: Encoder) throws
117 |
118 |
119 | 120 | 121 | 122 |
123 |
124 | 125 |
126 |

127 | Generated on using swift-doc 1.0.0-beta.3. 128 |

129 |
130 | 131 | 132 | -------------------------------------------------------------------------------- /docs/Bar/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - Bar 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Structure 37 | Bar 38 |

39 | 40 |
public struct Bar: Codable
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | Bar 57 | 58 | 59 | Bar 60 | 61 | 62 | 63 | 64 | 65 | Codable 66 | 67 | 68 | Codable 69 | 70 | 71 | 72 | 73 | 74 | Bar->Codable 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 |

Nested Types

85 |
86 |
Bar.Timeframe
87 |
88 |
89 |

Conforms To

90 |
91 |
Codable
92 |
93 |
94 |
95 |

Properties

96 | 97 |
98 |

99 | timeframe 100 |

101 |
var timeframe: Double
102 |
103 |
104 |

105 | open 106 |

107 |
var open: Double
108 |
109 |
110 |

111 | high 112 |

113 |
var high: Double
114 |
115 |
116 |

117 | low 118 |

119 |
var low: Double
120 |
121 |
122 |

123 | close 124 |

125 |
var close: Double
126 |
127 |
128 |

129 | volume 130 |

131 |
var volume: Double
132 |
133 |
134 | 135 | 136 | 137 |
138 |
139 | 140 |
141 |

142 | Generated on using swift-doc 1.0.0-beta.3. 143 |

144 |
145 | 146 | 147 | -------------------------------------------------------------------------------- /docs/AccountConfigurations/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - AccountConfigurations 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Structure 37 | Account​Configurations 38 |

39 | 40 |
public struct AccountConfigurations: Codable
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | AccountConfigurations 57 | 58 | 59 | AccountConfigurations 60 | 61 | 62 | 63 | 64 | 65 | Codable 66 | 67 | 68 | Codable 69 | 70 | 71 | 72 | 73 | 74 | AccountConfigurations->Codable 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 |

Nested Types

85 |
86 |
AccountConfigurations.DayTradeBuyingPowerCheck
87 |
88 |
AccountConfigurations.TradeConfirmEmail
89 |
90 |
91 |

Conforms To

92 |
93 |
Codable
94 |
95 |
96 |
97 |

Properties

98 | 99 |
100 |

101 | dtbp​Check 102 |

103 |
var dtbpCheck: DayTradeBuyingPowerCheck
104 |
105 |
106 |

107 | no​Shorting 108 |

109 |
var noShorting: Bool
110 |
111 |
112 |

113 | suspend​Trade 114 |

115 |
var suspendTrade: Bool
116 |
117 |
118 |

119 | trade​Confirm​Email 120 |

121 |
var tradeConfirmEmail: TradeConfirmEmail
122 |
123 |
124 | 125 | 126 | 127 |
128 |
129 | 130 |
131 |

132 | Generated on using swift-doc 1.0.0-beta.3. 133 |

134 |
135 | 136 | 137 | -------------------------------------------------------------------------------- /docs/Bar_Timeframe/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - Bar.Timeframe 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Enumeration 37 | Bar.​Timeframe 38 |

39 | 40 |
public enum Timeframe
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | Bar.Timeframe 57 | 58 | 59 | Bar.Timeframe 60 | 61 | 62 | 63 | 64 | 65 | String 66 | 67 | 68 | String 69 | 70 | 71 | 72 | 73 | 74 | Bar.Timeframe->String 75 | 76 | 77 | 78 | 79 | 80 | CaseIterable 81 | 82 | 83 | CaseIterable 84 | 85 | 86 | 87 | 88 | 89 | Bar.Timeframe->CaseIterable 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 |
99 |

Member Of

100 |
101 |
Bar
102 |
103 |
104 |

Conforms To

105 |
106 |
CaseIterable
107 |
String
108 |
109 |
110 |
111 |

Enumeration Cases

112 | 113 |
114 |

115 | one​Min 116 |

117 |
case oneMin
118 |
119 |
120 |

121 | five​Min 122 |

123 |
case fiveMin
124 |
125 |
126 |

127 | fifteen​Min 128 |

129 |
case fifteenMin
130 |
131 |
132 |

133 | one​Day 134 |

135 |
case oneDay
136 |
137 |
138 | 139 | 140 | 141 |
142 |
143 | 144 |
145 |

146 | Generated on using swift-doc 1.0.0-beta.3. 147 |

148 |
149 | 150 | 151 | -------------------------------------------------------------------------------- /docs/PortfolioHistory/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - PortfolioHistory 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Structure 37 | Portfolio​History 38 |

39 | 40 |
public struct PortfolioHistory: Codable
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | PortfolioHistory 57 | 58 | 59 | PortfolioHistory 60 | 61 | 62 | 63 | 64 | 65 | Codable 66 | 67 | 68 | Codable 69 | 70 | 71 | 72 | 73 | 74 | PortfolioHistory->Codable 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 |

Nested Types

85 |
86 |
PortfolioHistory.Timeframe
87 |
88 |
89 |

Conforms To

90 |
91 |
Codable
92 |
93 |
94 |
95 |

Properties

96 | 97 |
98 |

99 | timestamp 100 |

101 |
let timestamp: [Int]
102 |
103 |
104 |

105 | equity 106 |

107 |
let equity: [Double]
108 |
109 |
110 |

111 | profit​Loss 112 |

113 |
let profitLoss: [Double]
114 |
115 |
116 |

117 | profit​Loss​Pct 118 |

119 |
let profitLossPct: [Double]
120 |
121 |
122 |

123 | base​Value 124 |

125 |
let baseValue: Double
126 |
127 |
128 |

129 | timeframe 130 |

131 |
let timeframe: Timeframe
132 |
133 |
134 | 135 | 136 | 137 |
138 |
139 | 140 |
141 |

142 | Generated on using swift-doc 1.0.0-beta.3. 143 |

144 |
145 | 146 | 147 | -------------------------------------------------------------------------------- /docs/Asset_Class/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - Asset.Class 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Enumeration 37 | Asset.​Class 38 |

39 | 40 |
public enum Class
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | Asset.Class 57 | 58 | 59 | Asset.Class 60 | 61 | 62 | 63 | 64 | 65 | Codable 66 | 67 | 68 | Codable 69 | 70 | 71 | 72 | 73 | 74 | Asset.Class->Codable 75 | 76 | 77 | 78 | 79 | 80 | CaseIterable 81 | 82 | 83 | CaseIterable 84 | 85 | 86 | 87 | 88 | 89 | Asset.Class->CaseIterable 90 | 91 | 92 | 93 | 94 | 95 | String 96 | 97 | 98 | String 99 | 100 | 101 | 102 | 103 | 104 | Asset.Class->String 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 |

Member Of

115 |
116 |
Asset
117 |
118 |
119 |

Conforms To

120 |
121 |
CaseIterable
122 |
Codable
123 |
String
124 |
125 |
126 |
127 |

Enumeration Cases

128 | 129 |
130 |

131 | us​Equity 132 |

133 |
case usEquity
134 |
135 |
136 | 137 | 138 | 139 |
140 |
141 | 142 |
143 |

144 | Generated on using swift-doc 1.0.0-beta.3. 145 |

146 |
147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/SortDirection/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - SortDirection 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Enumeration 37 | Sort​Direction 38 |

39 | 40 |
public enum SortDirection
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | SortDirection 57 | 58 | 59 | SortDirection 60 | 61 | 62 | 63 | 64 | 65 | Codable 66 | 67 | 68 | Codable 69 | 70 | 71 | 72 | 73 | 74 | SortDirection->Codable 75 | 76 | 77 | 78 | 79 | 80 | CaseIterable 81 | 82 | 83 | CaseIterable 84 | 85 | 86 | 87 | 88 | 89 | SortDirection->CaseIterable 90 | 91 | 92 | 93 | 94 | 95 | String 96 | 97 | 98 | String 99 | 100 | 101 | 102 | 103 | 104 | SortDirection->String 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 |

Conforms To

115 |
116 |
CaseIterable
117 |
Codable
118 |
String
119 |
120 |
121 |
122 |

Enumeration Cases

123 | 124 |
125 |

126 | asc 127 |

128 |
case asc
129 |
130 |
131 |

132 | desc 133 |

134 |
case desc
135 |
136 |
137 | 138 | 139 | 140 |
141 |
142 | 143 |
144 |

145 | Generated on using swift-doc 1.0.0-beta.3. 146 |

147 |
148 | 149 | 150 | -------------------------------------------------------------------------------- /docs/Order_Side/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - Order.Side 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Enumeration 37 | Order.​Side 38 |

39 | 40 |
public enum Side
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | Order.Side 57 | 58 | 59 | Order.Side 60 | 61 | 62 | 63 | 64 | 65 | String 66 | 67 | 68 | String 69 | 70 | 71 | 72 | 73 | 74 | Order.Side->String 75 | 76 | 77 | 78 | 79 | 80 | CaseIterable 81 | 82 | 83 | CaseIterable 84 | 85 | 86 | 87 | 88 | 89 | Order.Side->CaseIterable 90 | 91 | 92 | 93 | 94 | 95 | Codable 96 | 97 | 98 | Codable 99 | 100 | 101 | 102 | 103 | 104 | Order.Side->Codable 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 |

Member Of

115 |
116 |
Order
117 |
118 |
119 |

Conforms To

120 |
121 |
CaseIterable
122 |
Codable
123 |
String
124 |
125 |
126 |
127 |

Enumeration Cases

128 | 129 |
130 |

131 | buy 132 |

133 |
case buy
134 |
135 |
136 |

137 | sell 138 |

139 |
case sell
140 |
141 |
142 | 143 | 144 | 145 |
146 |
147 | 148 |
149 |

150 | Generated on using swift-doc 1.0.0-beta.3. 151 |

152 |
153 | 154 | 155 | -------------------------------------------------------------------------------- /docs/Watchlist/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - Watchlist 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Structure 37 | Watchlist 38 |

39 | 40 |
public struct Watchlist: Codable, Identifiable
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | Watchlist 57 | 58 | 59 | Watchlist 60 | 61 | 62 | 63 | 64 | 65 | Codable 66 | 67 | 68 | Codable 69 | 70 | 71 | 72 | 73 | 74 | Watchlist->Codable 75 | 76 | 77 | 78 | 79 | 80 | Identifiable 81 | 82 | 83 | Identifiable 84 | 85 | 86 | 87 | 88 | 89 | Watchlist->Identifiable 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 |
99 |

Conforms To

100 |
101 |
Codable
102 |
Identifiable
103 |
104 |
105 |
106 |

Properties

107 | 108 |
109 |

110 | id 111 |

112 |
let id: UUID
113 |
114 |
115 |

116 | account​Id 117 |

118 |
let accountId: UUID
119 |
120 |
121 |

122 | name 123 |

124 |
let name: String
125 |
126 |
127 |

128 | created​At 129 |

130 |
let createdAt: Date
131 |
132 |
133 |

134 | updated​At 135 |

136 |
let updatedAt: Date
137 |
138 |
139 |

140 | assets 141 |

142 |
let assets: [Asset]?
143 |
144 |
145 | 146 | 147 | 148 |
149 |
150 | 151 |
152 |

153 | Generated on using swift-doc 1.0.0-beta.3. 154 |

155 |
156 | 157 | 158 | -------------------------------------------------------------------------------- /docs/Asset_Status/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - Asset.Status 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Enumeration 37 | Asset.​Status 38 |

39 | 40 |
public enum Status
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | Asset.Status 57 | 58 | 59 | Asset.Status 60 | 61 | 62 | 63 | 64 | 65 | Codable 66 | 67 | 68 | Codable 69 | 70 | 71 | 72 | 73 | 74 | Asset.Status->Codable 75 | 76 | 77 | 78 | 79 | 80 | String 81 | 82 | 83 | String 84 | 85 | 86 | 87 | 88 | 89 | Asset.Status->String 90 | 91 | 92 | 93 | 94 | 95 | CaseIterable 96 | 97 | 98 | CaseIterable 99 | 100 | 101 | 102 | 103 | 104 | Asset.Status->CaseIterable 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 |

Member Of

115 |
116 |
Asset
117 |
118 |
119 |

Conforms To

120 |
121 |
CaseIterable
122 |
Codable
123 |
String
124 |
125 |
126 |
127 |

Enumeration Cases

128 | 129 |
130 |

131 | active 132 |

133 |
case active
134 |
135 |
136 |

137 | inactive 138 |

139 |
case inactive
140 |
141 |
142 | 143 | 144 | 145 |
146 |
147 | 148 |
149 |

150 | Generated on using swift-doc 1.0.0-beta.3. 151 |

152 |
153 | 154 | 155 | -------------------------------------------------------------------------------- /docs/Position_Side/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - Position.Side 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Enumeration 37 | Position.​Side 38 |

39 | 40 |
public enum Side
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | Position.Side 57 | 58 | 59 | Position.Side 60 | 61 | 62 | 63 | 64 | 65 | String 66 | 67 | 68 | String 69 | 70 | 71 | 72 | 73 | 74 | Position.Side->String 75 | 76 | 77 | 78 | 79 | 80 | CaseIterable 81 | 82 | 83 | CaseIterable 84 | 85 | 86 | 87 | 88 | 89 | Position.Side->CaseIterable 90 | 91 | 92 | 93 | 94 | 95 | Codable 96 | 97 | 98 | Codable 99 | 100 | 101 | 102 | 103 | 104 | Position.Side->Codable 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 |

Member Of

115 |
116 |
Position
117 |
118 |
119 |

Conforms To

120 |
121 |
CaseIterable
122 |
Codable
123 |
String
124 |
125 |
126 |
127 |

Enumeration Cases

128 | 129 |
130 |

131 | long 132 |

133 |
case long
134 |
135 |
136 |

137 | short 138 |

139 |
case short
140 |
141 |
142 | 143 | 144 | 145 |
146 |
147 | 148 |
149 |

150 | Generated on using swift-doc 1.0.0-beta.3. 151 |

152 |
153 | 154 | 155 | -------------------------------------------------------------------------------- /docs/AccountConfigurations_TradeConfirmEmail/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - AccountConfigurations.TradeConfirmEmail 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Enumeration 37 | Account​Configurations.​Trade​Confirm​Email 38 |

39 | 40 |
public enum TradeConfirmEmail
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | AccountConfigurations.TradeConfirmEmail 57 | 58 | 59 | AccountConfigurations.TradeConfirmEmail 60 | 61 | 62 | 63 | 64 | 65 | String 66 | 67 | 68 | String 69 | 70 | 71 | 72 | 73 | 74 | AccountConfigurations.TradeConfirmEmail->String 75 | 76 | 77 | 78 | 79 | 80 | Codable 81 | 82 | 83 | Codable 84 | 85 | 86 | 87 | 88 | 89 | AccountConfigurations.TradeConfirmEmail->Codable 90 | 91 | 92 | 93 | 94 | 95 | CaseIterable 96 | 97 | 98 | CaseIterable 99 | 100 | 101 | 102 | 103 | 104 | AccountConfigurations.TradeConfirmEmail->CaseIterable 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 |

Member Of

115 |
116 |
AccountConfigurations
117 |
118 |
119 |

Conforms To

120 |
121 |
CaseIterable
122 |
Codable
123 |
String
124 |
125 |
126 |
127 |

Enumeration Cases

128 | 129 |
130 |

131 | all 132 |

133 |
case all
134 |
135 |
136 |

137 | none 138 |

139 |
case none
140 |
141 |
142 | 143 | 144 | 145 |
146 |
147 | 148 |
149 |

150 | Generated on using swift-doc 1.0.0-beta.3. 151 |

152 |
153 | 154 | 155 | -------------------------------------------------------------------------------- /docs/Order_Class/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - Order.Class 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Enumeration 37 | Order.​Class 38 |

39 | 40 |
public enum Class
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | Order.Class 57 | 58 | 59 | Order.Class 60 | 61 | 62 | 63 | 64 | 65 | String 66 | 67 | 68 | String 69 | 70 | 71 | 72 | 73 | 74 | Order.Class->String 75 | 76 | 77 | 78 | 79 | 80 | CaseIterable 81 | 82 | 83 | CaseIterable 84 | 85 | 86 | 87 | 88 | 89 | Order.Class->CaseIterable 90 | 91 | 92 | 93 | 94 | 95 | Codable 96 | 97 | 98 | Codable 99 | 100 | 101 | 102 | 103 | 104 | Order.Class->Codable 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 |

Member Of

115 |
116 |
Order
117 |
118 |
119 |

Conforms To

120 |
121 |
CaseIterable
122 |
Codable
123 |
String
124 |
125 |
126 |
127 |

Enumeration Cases

128 | 129 |
130 |

131 | simple 132 |

133 |
case simple
134 |
135 |
136 |

137 | bracket 138 |

139 |
case bracket
140 |
141 |
142 |

143 | oco 144 |

145 |
case oco
146 |
147 |
148 |

149 | oto 150 |

151 |
case oto
152 |
153 |
154 | 155 | 156 | 157 |
158 |
159 | 160 |
161 |

162 | Generated on using swift-doc 1.0.0-beta.3. 163 |

164 |
165 | 166 | 167 | -------------------------------------------------------------------------------- /docs/Order_OrderType/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - Order.OrderType 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Enumeration 37 | Order.​Order​Type 38 |

39 | 40 |
public enum OrderType
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | Order.OrderType 57 | 58 | 59 | Order.OrderType 60 | 61 | 62 | 63 | 64 | 65 | Codable 66 | 67 | 68 | Codable 69 | 70 | 71 | 72 | 73 | 74 | Order.OrderType->Codable 75 | 76 | 77 | 78 | 79 | 80 | CaseIterable 81 | 82 | 83 | CaseIterable 84 | 85 | 86 | 87 | 88 | 89 | Order.OrderType->CaseIterable 90 | 91 | 92 | 93 | 94 | 95 | String 96 | 97 | 98 | String 99 | 100 | 101 | 102 | 103 | 104 | Order.OrderType->String 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 |

Member Of

115 |
116 |
Order
117 |
118 |
119 |

Conforms To

120 |
121 |
CaseIterable
122 |
Codable
123 |
String
124 |
125 |
126 |
127 |

Enumeration Cases

128 | 129 |
130 |

131 | market 132 |

133 |
case market
134 |
135 |
136 |

137 | limit 138 |

139 |
case limit
140 |
141 |
142 |

143 | stop 144 |

145 |
case stop
146 |
147 |
148 |

149 | stop​Limit 150 |

151 |
case stopLimit
152 |
153 |
154 | 155 | 156 | 157 |
158 |
159 | 160 |
161 |

162 | Generated on using swift-doc 1.0.0-beta.3. 163 |

164 |
165 | 166 | 167 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - Alpaca 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |
36 |

Structures

37 |
38 |
39 | 40 | Account 41 | 42 |
43 |
44 | 45 |
46 |
47 | 48 | Account​Configurations 49 | 50 |
51 |
52 | 53 |
54 |
55 | 56 | Asset 57 | 58 |
59 |
60 | 61 |
62 |
63 | 64 | Calendar 65 | 66 |
67 |
68 | 69 |
70 |
71 | 72 | Clock 73 | 74 |
75 |
76 | 77 |
78 |
79 | 80 | Order 81 | 82 |
83 |
84 | 85 |
86 |
87 | 88 | Portfolio​History 89 | 90 |
91 |
92 | 93 |
94 |
95 | 96 | Position 97 | 98 |
99 |
100 | 101 |
102 |
103 | 104 | Watchlist 105 | 106 |
107 |
108 | 109 |
110 |
111 | 112 | Alpaca​Client 113 | 114 |
115 |
116 | 117 |
118 |
119 | 120 | Bar 121 | 122 |
123 |
124 | 125 |
126 |
127 | 128 | Alpaca​Data​Client 129 | 130 |
131 |
132 | 133 |
134 |
135 | 136 | Empty​Response 137 | 138 |
139 |
140 | 141 |
142 |
143 | 144 | Multi​Response 145 | 146 |
147 |
148 | 149 |
150 |
151 | 152 | Numeric​String 153 | 154 |
155 |
156 | 157 |
158 |
159 | 160 | Environment 161 | 162 |
163 |
164 | 165 |
166 |
167 |
168 |
169 |

Enumerations

170 |
171 |
172 | 173 | Account.​Status 174 | 175 |
176 |
177 | 178 |
179 |
180 | 181 | Account​Configurations.​Day​Trade​Buying​Power​Check 182 | 183 |
184 |
185 | 186 |
187 |
188 | 189 | Account​Configurations.​Trade​Confirm​Email 190 | 191 |
192 |
193 | 194 |
195 |
196 | 197 | Asset.​Class 198 | 199 |
200 |
201 | 202 |
203 |
204 | 205 | Asset.​Exchange 206 | 207 |
208 |
209 | 210 |
211 |
212 | 213 | Asset.​Status 214 | 215 |
216 |
217 | 218 |
219 |
220 | 221 | Order.​Class 222 | 223 |
224 |
225 | 226 |
227 |
228 | 229 | Order.​Side 230 | 231 |
232 |
233 | 234 |
235 |
236 | 237 | Order.​Status 238 | 239 |
240 |
241 | 242 |
243 |
244 | 245 | Order.​Order​Type 246 | 247 |
248 |
249 | 250 |
251 |
252 | 253 | Order.​Time​InForce 254 | 255 |
256 |
257 | 258 |
259 |
260 | 261 | Portfolio​History.​Timeframe 262 | 263 |
264 |
265 | 266 |
267 |
268 | 269 | Position.​Side 270 | 271 |
272 |
273 | 274 |
275 |
276 | 277 | Bar.​Timeframe 278 | 279 |
280 |
281 | 282 |
283 |
284 | 285 | Request​Error 286 | 287 |
288 |
289 | 290 |
291 |
292 | 293 | Sort​Direction 294 | 295 |
296 |
297 | 298 |
299 |
300 |
301 |
302 |

Protocols

303 |
304 |
305 | 306 | Alpaca​Client​Protocol 307 | 308 |
309 |
310 | 311 |
312 |
313 | 314 | String​Representable 315 | 316 |
317 |
318 | 319 |
320 |
321 |
322 |
323 |
324 | 325 |
326 |

327 | Generated on using swift-doc 1.0.0-beta.3. 328 |

329 |
330 | 331 | 332 | -------------------------------------------------------------------------------- /docs/AccountConfigurations_DayTradeBuyingPowerCheck/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - AccountConfigurations.DayTradeBuyingPowerCheck 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Enumeration 37 | Account​Configurations.​Day​Trade​Buying​Power​Check 38 |

39 | 40 |
public enum DayTradeBuyingPowerCheck
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | AccountConfigurations.DayTradeBuyingPowerCheck 57 | 58 | 59 | AccountConfigurations.DayTradeBuyingPowerCheck 60 | 61 | 62 | 63 | 64 | 65 | Codable 66 | 67 | 68 | Codable 69 | 70 | 71 | 72 | 73 | 74 | AccountConfigurations.DayTradeBuyingPowerCheck->Codable 75 | 76 | 77 | 78 | 79 | 80 | String 81 | 82 | 83 | String 84 | 85 | 86 | 87 | 88 | 89 | AccountConfigurations.DayTradeBuyingPowerCheck->String 90 | 91 | 92 | 93 | 94 | 95 | CaseIterable 96 | 97 | 98 | CaseIterable 99 | 100 | 101 | 102 | 103 | 104 | AccountConfigurations.DayTradeBuyingPowerCheck->CaseIterable 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 |

Member Of

115 |
116 |
AccountConfigurations
117 |
118 |
119 |

Conforms To

120 |
121 |
CaseIterable
122 |
Codable
123 |
String
124 |
125 |
126 |
127 |

Enumeration Cases

128 | 129 |
130 |

131 | both 132 |

133 |
case both
134 |
135 |
136 |

137 | entry 138 |

139 |
case entry
140 |
141 |
142 |

143 | exit 144 |

145 |
case exit
146 |
147 |
148 | 149 | 150 | 151 |
152 |
153 | 154 |
155 |

156 | Generated on using swift-doc 1.0.0-beta.3. 157 |

158 |
159 | 160 | 161 | -------------------------------------------------------------------------------- /docs/Order_TimeInForce/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - Order.TimeInForce 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Enumeration 37 | Order.​Time​InForce 38 |

39 | 40 |
public enum TimeInForce
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | Order.TimeInForce 57 | 58 | 59 | Order.TimeInForce 60 | 61 | 62 | 63 | 64 | 65 | Codable 66 | 67 | 68 | Codable 69 | 70 | 71 | 72 | 73 | 74 | Order.TimeInForce->Codable 75 | 76 | 77 | 78 | 79 | 80 | CaseIterable 81 | 82 | 83 | CaseIterable 84 | 85 | 86 | 87 | 88 | 89 | Order.TimeInForce->CaseIterable 90 | 91 | 92 | 93 | 94 | 95 | String 96 | 97 | 98 | String 99 | 100 | 101 | 102 | 103 | 104 | Order.TimeInForce->String 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 |

Member Of

115 |
116 |
Order
117 |
118 |
119 |

Conforms To

120 |
121 |
CaseIterable
122 |
Codable
123 |
String
124 |
125 |
126 |
127 |

Enumeration Cases

128 | 129 |
130 |

131 | day 132 |

133 |
case day
134 |
135 |
136 |

137 | gtc 138 |

139 |
case gtc
140 |
141 |
142 |

143 | opg 144 |

145 |
case opg
146 |
147 |
148 |

149 | cls 150 |

151 |
case cls
152 |
153 |
154 |

155 | ioc 156 |

157 |
case ioc
158 |
159 |
160 |

161 | fok 162 |

163 |
case fok
164 |
165 |
166 | 167 | 168 | 169 |
170 |
171 | 172 |
173 |

174 | Generated on using swift-doc 1.0.0-beta.3. 175 |

176 |
177 | 178 | 179 | -------------------------------------------------------------------------------- /docs/PortfolioHistory_Timeframe/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca - PortfolioHistory.Timeframe 7 | 8 | 9 | 10 |
11 | 12 | 13 | Alpaca 14 | 15 | Documentation 16 | 17 | Beta 18 |
19 | 20 | 25 | 26 | 32 | 33 |
34 |
35 |

36 | Enumeration 37 | Portfolio​History.​Timeframe 38 |

39 | 40 |
public enum Timeframe
41 |
42 | 43 |
44 | 45 | 47 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | PortfolioHistory.Timeframe 57 | 58 | 59 | PortfolioHistory.Timeframe 60 | 61 | 62 | 63 | 64 | 65 | String 66 | 67 | 68 | String 69 | 70 | 71 | 72 | 73 | 74 | PortfolioHistory.Timeframe->String 75 | 76 | 77 | 78 | 79 | 80 | Codable 81 | 82 | 83 | Codable 84 | 85 | 86 | 87 | 88 | 89 | PortfolioHistory.Timeframe->Codable 90 | 91 | 92 | 93 | 94 | 95 | CaseIterable 96 | 97 | 98 | CaseIterable 99 | 100 | 101 | 102 | 103 | 104 | PortfolioHistory.Timeframe->CaseIterable 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 |

Member Of

115 |
116 |
PortfolioHistory
117 |
118 |
119 |

Conforms To

120 |
121 |
CaseIterable
122 |
Codable
123 |
String
124 |
125 |
126 |
127 |

Enumeration Cases

128 | 129 |
130 |

131 | one​Min 132 |

133 |
case oneMin
134 |
135 |
136 |

137 | five​Min 138 |

139 |
case fiveMin
140 |
141 |
142 |

143 | fifteen​Min 144 |

145 |
case fifteenMin
146 |
147 |
148 |

149 | one​Hour 150 |

151 |
case oneHour
152 |
153 |
154 |

155 | one​Day 156 |

157 |
case oneDay
158 |
159 |
160 | 161 | 162 | 163 |
164 |
165 | 166 | 171 | 172 | 173 | --------------------------------------------------------------------------------