All Projects → AlexRoar → SwiftYFinance

AlexRoar / SwiftYFinance

Licence: MIT license
The best Yahoo Finance library with the power of Swift

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to SwiftYFinance

stock-market-scraper
Scraps historical stock market data from Yahoo Finance (https://finance.yahoo.com/)
Stars: ✭ 110 (+266.67%)
Mutual labels:  stock, yahoo-finance-api, stock-market, yahoo-finance, finance-api
AIPortfolio
Use AI to generate a optimized stock portfolio
Stars: ✭ 28 (-6.67%)
Mutual labels:  yahoo, stock, stock-market
Alpha Mind
quantitative security portfolio analysis. The analysis pipeline including data storage abstraction, alpha calculation, ML based alpha combining and portfolio calculation.
Stars: ✭ 171 (+470%)
Mutual labels:  stock, stock-market
Deep Rl Trading
playing idealized trading games with deep reinforcement learning
Stars: ✭ 228 (+660%)
Mutual labels:  stock, stock-market
Stocksera
Web application that provides alternative data to retail investors
Stars: ✭ 426 (+1320%)
Mutual labels:  stock, yahoo-finance
Zvt
modular quant framework.
Stars: ✭ 1,801 (+5903.33%)
Mutual labels:  stock, stock-market
Bovespastockratings
Crawler for Fundamental analysis platform for BOVESPA stocks, generating a score for each share according to the selected criteria on the indicators.
Stars: ✭ 154 (+413.33%)
Mutual labels:  stock, stock-market
node-yahoo-finance2
Unofficial API for Yahoo Finance
Stars: ✭ 155 (+416.67%)
Mutual labels:  yahoo, yahoo-finance
Algotrader
Simple algorithmic stock and option trading for Node.js.
Stars: ✭ 468 (+1460%)
Mutual labels:  stock, stock-market
BigBoard
An Elegant Financial Markets Library Written in Swift
Stars: ✭ 66 (+120%)
Mutual labels:  yahoo-finance-api, stock-market
Chase
Automatic trading bot (WIP)
Stars: ✭ 73 (+143.33%)
Mutual labels:  stock, stock-market
alpha-vantage-api
Alpha Vantage PHP Client
Stars: ✭ 57 (+90%)
Mutual labels:  stock, stock-market
Fooltrader
quant framework for stock
Stars: ✭ 960 (+3100%)
Mutual labels:  stock, stock-market
Sina Stock Crawler
Sina stock options crawler with CSV output 新浪上证ETF期权数据爬虫
Stars: ✭ 12 (-60%)
Mutual labels:  stock, stock-market
Financereactnative
[Deprecated] iOS's Stocks App clone written in React Native for demo purpose (available both iOS and Android).
Stars: ✭ 1,947 (+6390%)
Mutual labels:  stock, yahoo-finance
Ystockquote
Fetch stock quote data from Yahoo Finance
Stars: ✭ 502 (+1573.33%)
Mutual labels:  stock, stock-market
Finance Python
python tools for Finance with the functionality of indicator calculation, business day calculation and so on.
Stars: ✭ 238 (+693.33%)
Mutual labels:  stock, stock-market
Techan
Technical Analysis Library for Golang
Stars: ✭ 404 (+1246.67%)
Mutual labels:  stock, stock-market
Deepstock
Technical experimentations to beat the stock market using deep learning 📈
Stars: ✭ 422 (+1306.67%)
Mutual labels:  stock, stock-market
fundamentos
Download Bovespa Stock Market fundamentals with Python.
Stars: ✭ 80 (+166.67%)
Mutual labels:  stock-market, finance-api

SwiftYFinance

Language GitHub Workflow Status codecov CodeFactor Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first. Example project includes basic features demonstration.

You asked about this beautiful chart in the preview gif: AlexRoar/BeautyChart

Requirements

I used Swift 5.0 and backward compatibility is not guranteed. IOS 13+

Installation

SwiftYFinance is available through CocoaPods or Swift Package Manager.

CocoaPods

To install it, simply add the following line to your Podfile and run pod install:

pod 'SwiftYFinance'

Swift Package Manager

Add dependency to your Package file:

dependencies: [
    .package(url: "https://github.com/AlexRoar/SwiftYFinance", .upToNextMajor(from: "1.4.0")),
]

Or add dependency to your XCode project: File > Swift Packages > Add Package Dependency

https://github.com/AlexRoar/SwiftYFinance

Try it

You can try Example project on your device by running:

pod try SwiftYFinance

Basic Usage

Search

/*
* Main class of SwiftYFinance. Asynchronous method's callback always will
* have format: (Some Data?, Error?). If error is non-nil, then data is going to be nil.
* Review Error description to find out what's wrong.
* Synchronous API is also provided. The only difference is that it blocks the thread and
* returns data rather than passing it to the callback.
*/
import SwiftYFinance

// Searches quote in Yahoo finances and returns found results
SwiftYFinance.fetchSearchDataBy(searchTerm:"AAPL", quotesCount=20) {
    data, error in
    /*
    callback: ([YFQuoteSearchResult]?, Error?) -> Void
    struct YFQuoteSearchResult{
        var symbol: String?
        var shortname: String?
        var longname: String?
        var exchange: String?
        var assetType: String?
    }
    */
    if error == nil{
        return 
    }
    print(data!.longname ?? "No long name")
}

The same thing but synchronously:

let (data, error) = SwiftYFinance.syncFetchSearchDataBy(searchTerm:"AAPL", quotesCount=20)
if error == nil{
    return 
}
print(data!.longname ?? "No long name")

Even though executing commands in the main thread synchronously is not the best practice, I added this feature to the project. It's on your account to write fast, non-freezing apps, so use synchronous methods wisely.

Search for news is also awailable through fetchSearchDataBy(searchNews:String, ...)

Basic recent data

Fetches the most recent data about identifier collecting basic information.

SwiftYFinance.recentDataBy(identifier:"AAPL"){
    data, error in
    /*
    data ~>
    struct RecentStockData{
        var currency: String?
        var symbol: String?
        var exchangeName: String?
        var instrumentType: String?
        var firstTradeDate: Int?
        var regularMarketTime: Int?
        var gmtoffset: Int?
        var timezone: String?
        var exchangeTimezoneName: String?
        var regularMarketPrice: Float?
        var chartPreviousClose: Float?
        var previousClose: Float?
        var scale: Int?
        var priceHint: Int?
    }
    */
    if error == nil{
        return 
    }
    print(data!.regularMarketPrice ?? "No regularMarketPrice")
}

Chart data

Fetches chart data points

SwiftYFinance.chartDataBy(
        identifier:"AAPL",
        start: Date(...),
        end: Date(...),
        interval = .oneday){
    data, error in
    /*
    data ~>[
        struct StockChartData{
            var date: Date?
            var volume: Int?
            var open: Float?
            var close: Float?
            var adjclose: Float?
            var low: Float?
            var high: Float?
        }
    ]
    */
    if error == nil{
        return 
    }
    print(data![0]?.open ?? "Open price is unavailable")
}

Chart data at moment

Sometimes, you need to fetch data at some moment in the past. Use chartDataBy(..., moment: Date, ...) for that.

SwiftYFinance.chartDataBy(
        identifier:"AAPL",
        moment: Date(...),
        futureMargin: TimeInterval(...)
        ){
    data, error in
    /*
    data ~>[
        struct StockChartData{
            var date: Date?
            var volume: Int?
            var open: Float?
            var close: Float?
            var adjclose: Float?
            var low: Float?
            var high: Float?
        }
    ]
    */
    if error == nil{
        return 
    }
    print(data![0]?.open ?? "Open price is unavailable")
}

Identifier Summary

This part of API is MASSIVE. Yahoo Finance has a lot of summary modules and I implemented several of them. Still, you can fetch data from raw JSON parameter.

I will add new modules with every version. Currently, only essential modules are implemented.

Module Support Module Support
calendarEvents recommendationTrend
summaryProfile quoteType
industryTrend price
summaryDetail incomeStatementHistoryQuarterly
assetProfile balanceSheetHistoryQuarterly
incomeStatementHistory cashFlowStatementHistory
balanceSheetHistory cashFlowStatementHistoryQuarterly
financialData secFilings
upgradeDowngradeHistory institutionOwnership
fundOwnership majorDirectHolders
majorHoldersBreakdown insiderTransactions
insiderHolders netSharePurchaseActivity
sectorTrend earnings
companyOfficers earningsHistory
earningsTrend indexTrend
symbol fundProfile
topHoldings fundPerformance
defaultKeyStatistics

You can fetch modules by calling summaryDataBy(...)

SwiftYFinance.summaryDataBy(identifier: "AAPL", selection = .all){
data, error in
    if error != nil{
        return
    }
    print(data)
    /*
    data ~>
    struct IdentifierSummary {
        var recommendationTrend:RecommendationTrend?
        var summaryProfile:SummaryProfile?
        var quoteType:QuoteType?
        var price:Price?
        var indexTrend:IndexTrend?
        var calendarEvents:CalendarEvents?
        var summaryDetail:SummaryDetail?
        var dataStorage:JSON?
    }
    */

    // Raw JSON:
    print(data.dataStorage)
}

Several types of selection are available. .all will fetch every method, even not supported yet so that you can get data from raw JSON. You can select .supported, then only supported data will be fetched. Also, you can specify specific module (ex: .price) or list of modules (ex: [.price, .summaryDetail])

Author

Aleksandr Dremov, [email protected]

License

SwiftYFinance is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].