stockermart

package module
v0.0.0-...-6ea30cc Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

stockermart

Cloud Functions Stock market price downloader to BigQuery using Cloud Scheduler and Cloud PubSub.

Setup

Create PubSub topic

gcloud beta pubsub topics create stocker-schedule

Create BigQuery price table

bq query --use_legacy_sql=false "
  CREATE OR REPLACE TABLE stocker.price (
    symbol STRING NOT NULL,
    price FLOAT64 NOT NULL,
    closingPrice FLOAT64 NOT NULL,
    closingDate STRING NOT NULL,
    quotedAt TIMESTAMP NOT NULL
)"

Deploy

Create a Cloud Function to download and save the stock prices

gcloud functions deploy stocker-price \
  --entry-point GetStockPrices \
  --set-env-vars "PID=${GCP_PROJECT},STOCK_PRICER_API_KEY=${STOCK_PRICER_API_KEY}" \
  --memory 512MB \
  --region us-central1 \
  --runtime go112 \
  --trigger-topic stocker-schedule \
  --timeout=540s

Then create a Cloud Scheduler job to execute the above function every 30 min by publishing to the stocker-schedule topic.

gcloud beta scheduler jobs create pubsub stocker-price-scheduler \
  --schedule "*/30 * * * *" \
  --topic stocker-schedule \
  --message-body "refresh"

Cleanup

Deleting price function

gcloud functions delete stocker-price --region us-central1

Delete the source topics

gcloud pubsub topics delete stocker-schedule

Delete BigQuery content table

bq rm stocker.price

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStockPrices

func GetStockPrices(ctx context.Context, m PubSubMessage) error

GetStockPrices processes pubsub topic events

Types

type Company

type Company struct {
	Symbol  string `json:"symbol"`
	Aliases string `json:"aliases"`
}

Company represents externalize company object

type PubSubMessage

type PubSubMessage struct {
	Data []byte `json:"data"`
}

PubSubMessage is the payload of a Pub/Sub event

type Quote

type Quote struct {
	Symbol       string    `json:"symbol"`
	Price        float64   `json:"price"`
	ClosingPrice float64   `json:"closingPrice"`
	ClosingDate  string    `json:"closingDate"`
	QuotedAt     time.Time `json:"quotedAt"`
}

Quote represents externalize stock quote

Jump to

Keyboard shortcuts

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