googlefinance

package module
v0.0.0-...-d7d9f52 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2014 License: MIT Imports: 6 Imported by: 1

README

googlefinance GoDoc

Package googlefinance implements a simple interface for fetching historical prices from google.com/finance.

Install

go get github.com/tiloso/googlefinance

Introduction

An example on how to use it:

package main

import (
  "fmt"
  "time"

  "github.com/tiloso/googlefinance"
)

type Quote struct {
  Date                    time.Time
  Open, High, Low, Close  float64
  Volume                  uint32
}

func main() {
  var qs []Quote
  d, _ := time.Parse("2-Jan-06", "22-Oct-14")

  if err := googlefinance.Date(d).Key("NASDAQ:GOOG").Get(&qs); err != nil {
    fmt.Printf("err: %v\n", err)
  }
  fmt.Printf("%+v\n", qs)
  // Output: [{Date:2014-10-22 00:00:00 +0000 UTC Open:529.89 High:539.8 Low:528.8 Close:532.71 Volume:2917183}]
}

For more details please take a look at godoc.org

Documentation

Overview

Package googlefinance implements a simple interface for fetching historical prices from google.com/finance.

Example
package main

import (
	"fmt"
	"time"

	"github.com/tiloso/googlefinance"
)

func main() {
	type Quote struct {
		Date                   time.Time
		Open, High, Low, Close float64
		Volume                 uint32
	}
	var qs []Quote
	d, _ := time.Parse("2-Jan-06", "22-Oct-14")

	if err := googlefinance.Date(d).Key("NASDAQ:GOOG").Get(&qs); err != nil {
		fmt.Printf("err: %v\n", err)
	}
	fmt.Printf("%+v\n", qs)
}
Output:

[{Date:2014-10-22 00:00:00 +0000 UTC Open:529.89 High:539.8 Low:528.8 Close:532.71 Volume:2917183}]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query encapsulates query details

func Date

func Date(d time.Time) *Query

Date returns a date based query

func Range

func Range(start, end time.Time) *Query

Range returns a range based query

Example
package main

import (
	"fmt"
	"time"

	"github.com/tiloso/googlefinance"
)

func main() {
	type Quote struct {
		Date                   time.Time
		Open, High, Low, Close float64
		Volume                 int
	}
	var qs []Quote
	start, _ := time.Parse("2006-Jan-02", "2014-Oct-13")
	end, _ := time.Parse("2006-Jan-02", "2014-Oct-14")

	if err := googlefinance.Range(start, end).Key("fra:dbk").Get(&qs); err != nil {
		fmt.Printf("err: %v\n", err)
	}

	fmt.Printf("%+v\n", qs)
}
Output:

[{Date:2014-10-14 00:00:00 +0000 UTC Open:24.84 High:25.22 Low:24.66 Close:25.07 Volume:44751} {Date:2014-10-13 00:00:00 +0000 UTC Open:25.03 High:25.34 Low:24.82 Close:25.15 Volume:49379}]

func (*Query) Get

func (q *Query) Get(v interface{}) error

Get executes the query and unmarshals fetched data into the provided interface

func (*Query) Key

func (q *Query) Key(k string) *Query

Key clones the query and sets the provided key on the new instance. Stocks' Keys often have following schema: `<exchange>:<symbol>` (e.g. "NASDAQ:GOOG" for Google Inc at NASAQ Stock Exchange) and can be found on google finance for stocks or other financial data. (Make sure historical prices are available as csv export.)

Directories

Path Synopsis
Package csvdecoding implements decoding of CSV streams (from googlefinance) into slices of Go structs.
Package csvdecoding implements decoding of CSV streams (from googlefinance) into slices of Go structs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL