Skip to content

levinishka/go-googlefinance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-googlefinance

A Golang package to fetch stock prices from Google Finance, by using the =GOOGLEFINANCE() function in Google Sheets.

🚀 Getting started

🔧 1. Prepare Your Google Cloud Project

  1. Go to the Google Cloud Console
  2. Create a new project
  3. Enable Google Sheets API for your project
  4. Create a service account
    • Follow Step 4 on that page to generate the service account and download the JSON key
  5. Save the key on the disk in JSON format

📄 2. Create a new Google Sheet and share access

  1. Go to Google Drive and create a new Google Sheet
  2. Copy the email address of your service account
  3. Share the sheet with that email and assign the Editor role
  4. Get your Google Sheet ID - it's the string in the URL between /d/ and /edit

🌍 3. Set environment variables

export GOOGLE_SHEETS_CREDENTIALS=/path/to/the/file/with/credentials
export GOOGLE_SHEETS_ID=YOUR_GOOGLE_SHEET_ID

📦 4. Installation

go get github.com/levinishka/go-googlefinance

🧪 Usage example

package main

import (
	"fmt"
	"log"
	"os"

	finance "github.com/levinishka/go-googlefinance"
)

func main() {
	config := &finance.Config{
		CredentialsPath:         os.Getenv("GOOGLE_SHEETS_CREDENTIALS"),
		SpreadsheetId:           os.Getenv("GOOGLE_SHEETS_ID"),
		TtlInSec:                300,
		BalancerNumberOfThreads: 3,
	}
	googleFinanceClient, err := finance.NewGoogleFinanceClient(config)
	if err != nil {
		log.Fatalf("Failed to create client: %v", err)
	}

	res, err := googleFinanceClient.ReadPrices([]string{"VTI", "VGT", "GE", "T"})
	if err != nil {
		log.Fatalf("Failed to read prices: %v", err)
	}
	fmt.Println(res)
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages