How To Get Stock Data In Swift
SwiftStock
is the simplest way to add real-time Yahoo! Finance stock marketplace information to your Swift app. It's a major Swift upgrade for my previous contribution, MAStockGraph. For simplicity, the example projection (SwiftStockExample.xcworkspace) I built has the Alamofire cocoapod included for networking with the Yahoo Finance APIs. Run pod install
every bit usual if information technology complains. Please open bug on the project if you run into snags!
SwiftStock
consists of 3 parts-
- A predictive stock quote search API.
- A comprehensive financial instrument API with all the best data points :D.
- A charting API that yields a full set up of time-and-sales data over various time frames (including the elusive intraday
😊 )
Requirements
SwiftStock
uses Swift 2.ane with ARC and requires iOS 9.0+. It also requires Alamofire be installed.
Installation
Manual
Copy the swift file SwiftStockKit
to your project.
Cocoapods
Supported in a later update.
Usage
Quote Search
// Laissez passer in your search term SwiftStockKit.fetchStocksFromSearchTerm(term: searchText) { (stockInfoArray) -> () in // And it returns an array of results of blazon struct StockSearchResult { var symbol: String ? var name: String ? var exchange: String ? var assetType: Cord ? } }
Get a stock from a symbol
// Laissez passer in your symbol SwiftStockKit.fetchStockForSymbol(symbol: stockSymbol) { (stock) -> () in //And it returns a stock object that looks like this struct Stock { var ask: String ? var averageDailyVolume: String ? var bid: String ? var bookValue: String ? var changeNumeric: String ? var changePercent: String ? var dayHigh: String ? var dayLow: Cord ? var dividendShare: String ? var dividendYield: Cord ? var ebitda: String ? var epsEstimateCurrentYear: String ? var epsEstimateNextQtr: String ? var epsEstimateNextYr: String ? var eps: Cord ? var fiftydayMovingAverage: String ? var lastTradeDate: Cord ? var last: String ? var lastTradeTime: String ? var marketCap: String ? var companyName: String ? var oneYearTarget: Cord ? var open: String ? var pegRatio: String ? var peRatio: String ? var previousClose: String ? var priceBook: String ? var priceSales: Cord ? var shortRatio: String ? var stockExchange: String ? var symbol: Cord ? var twoHundreddayMovingAverage: String ? var volume: String ? var yearHigh: String ? var yearLow: String ? //this has everything neatly packaged to get into a datasource var dataFields: [[String : String]] } }
Charting
// Pass in your symbol and nautical chart time range (enum) SwiftStockKit.fetchChartPoints(symbol: stockSymbol, range: range) { (chartPoints) -> () in // And it returns an array of results of type struct ChartPoint { var date: NSDate? var volume: Int ? var open: CGFloat? var close: CGFloat? var low: CGFloat? var high: CGFloat? } // Perfect for making candles 😊 }
In the example I included a quick piddling swift charting library that accepts the assortment of ChartPoint's. Feel gratuitous to use that if you wish as well! (Bonus points for upgrading it with candles back up and opening a pull asking)
To-Exercise
- UI Updates to the new styles- Apple keeps changing their listen about they want autolayout to work.
- Cocoapods / Carthage Support
- Examination coverage and CI with Travis.
- Bug bullet-proofing.
License
The MIT License (MIT)
Copyright (c) 2016 Michael Ackley
Permission is hereby granted, free of accuse, to whatsoever person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to employ, re-create, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do and so, subject to the following conditions:
The higher up copyright notice and this permission notice shall exist included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, Limited OR IMPLIED, INCLUDING BUT Not LIMITED TO THE WARRANTIES OF MERCHANTABILITY, Fitness FOR A Item PURPOSE AND NONINFRINGEMENT. IN NO Upshot SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR Whatsoever CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE Apply OR OTHER DEALINGS IN THE SOFTWARE.
How To Get Stock Data In Swift,
Source: https://github.com/ackleymi/SwiftStock
Posted by: mannbrainitterem.blogspot.com
0 Response to "How To Get Stock Data In Swift"
Post a Comment