Skip to content

dijeferson/yahoo-finance-provider

Repository files navigation

Yahoo Finance Provider

Build Status Go Report Card GoDoc License MIT

Go client for YahooFinance stock quote historical and real time data.

Installation

go get -u github.com/dijeferson/yahoo-finance-provider

Usage and Examples

1. Historical stock quote data for MSFT

package main

import (
    "fmt"

    "github.com/dijeferson/yahoo-finance-provider"
)

func main() {
    response, _ := yahoofinance.FetchDailyHistoricQuote("MSFT")

    for _, stock := range response {
        fmt.Println(stock.ToJSON())
    }
}

2. Latest stock quote data for MSFT

Use the interval type to specify the aggregation. In the example below, the last 15 minutes of stock values for MSFT, aggregated by 5 min averages.

package main

import (
    "fmt"
    "time"
    "github.com/dijeferson/yahoo-finance-provider"
    "github.com/dijeferson/yahoo-finance-provider/interval"
)

func main() {
    // currentTime - 15 minutes
    start := time.Now().Unix() - 900
    response, _ := yahoofinance.FetchUntilNow("MSFT", start, interval.FiveMinutes)

    for _, stock := range response {
        fmt.Println(stock.ToJSON())
    }
}

Available Aggregation Intervals

  • OneMinutes
  • TwoMinutes
  • FiveMinutes
  • FifteenMinutes
  • ThirtyMinutes
  • SixtyMinutes
  • NinetyMinutes
  • OneHour
  • OneDays
  • FiveDays
  • SevenDays
  • ThirtyDays
  • NinetyDays