Giter VIP home page Giter VIP logo

gofetch's Introduction

Fetch stock market data asynchronously

This package utilises concurrency capabilities of Google's Go language to fetch stock market data from YahooFinance API.

When fetching 7 stock tickers ("aapl", "msft", "tsla", "amzn", "goog", "nflx", "meta") there was approximatedly 2.66x speedup, actual speedup will vary on the parallel capabilities of your machine.

Installation

$ go get -u github.com/MartinKratochvilProgramy/gofetch

Quick Start

Add this import line to the file you're working in:

import "github.com/MartinKratochvilProgramy/gofetch"

Define your tickers in a string array, ticker names should correspond to the names found on yahoo.finance.com. Function gofetch.FetchAsync() returns array of structs TickerInfo{ticker string, price float64}. To get the ticker name or price, use the GetTicker() or GetPrice() functions.

tickers := []string{"aapl", "msft", "tsla", "amzn", "goog", "nflx", "meta"}

info := gofetch.FetchAsync(tickers)

for _, item := range info {
    fmt.Println(item.GetTicker(), item.GetPrice())
}

The above code prints ticker names and previous day close prices into console:

meta 177.16
goog 97.1
aapl 155.33
msft 269.32
amzn 101.16
nflx 361.42
tsla 214.24

Using the FetchPrevClose function

If you do not wish to load ticker information into an array of structs, use the gofetch.FetchPrevClose() which returns previous day close price for individual stock.

info := gofetch.FetchPrevClose("aapl")
fmt.Println(info.GetTicker(), info.GetPrice())

Returns:

aapl 155.33

gofetch's People

Contributors

martinkratochvilprogramy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.