traderdb

package module
v0.0.0-...-798ab6b Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2020 License: MIT Imports: 4 Imported by: 2

README

Trader DB

Go module containing common traderdb queries and models.

Usage

package main

import "github.com/t73liu/trading-bot/lib/traderdb"

func main() {
	dbPool, err := pgxpool.Connect(context.Background(), os.Getenv("DATABASE_URL"))
	if err != nil {
		logger.Fatalln("Unable to connect to database:", err)
	}
	defer dbPool.Close()
	watchlists, err := traderdb.GetWatchlistsByUserId(dbPool, 1)
	// ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateWatchlist

func CreateWatchlist(db *pgxpool.Pool, userId int, watchlistName string, stockIds []int) (watchlistId int, err error)

func DeleteWatchlistById

func DeleteWatchlistById(db *pgxpool.Pool, watchlistId int) error

func GetNewsSourceIdsByUserId

func GetNewsSourceIdsByUserId(db *pgxpool.Pool, userId int) (newsSourceIds []string, err error)

func HasWatchlistWithIdAndUserId

func HasWatchlistWithIdAndUserId(db *pgxpool.Pool, watchlistId int, userId int) (bool, error)

func IsWithinNATradingHours

func IsWithinNATradingHours(moment time.Time) bool

Assuming location = "America/New_York"

func UpdateWatchlistById

func UpdateWatchlistById(db *pgxpool.Pool, watchlistId int, watchlistName string, stockIds []int) error

Types

type Candle

type Candle struct {
	OpenedAt    time.Time
	OpenMicros  int64
	HighMicros  int64
	LowMicros   int64
	CloseMicros int64
	Volume      int64
}

func GetTradingHourStockCandles

func GetTradingHourStockCandles(conn *pgx.Conn, symbol string) (candles []Candle, err error)

type NewsSource

type NewsSource struct {
	Id          string
	Name        string
	Description string
}

func GetNewsSourcesByUserId

func GetNewsSourcesByUserId(db *pgxpool.Pool, userId int) (newsSources []NewsSource, err error)

type Stock

type Stock struct {
	Id       int    `json:"id"`
	Symbol   string `json:"symbol"`
	Company  string `json:"company"`
	Exchange string `json:"exchange,omitempty"`
}

func GetTradableStocks

func GetTradableStocks(db *pgxpool.Pool) (stocks []Stock, err error)

func GetWatchlistStocksByUserId

func GetWatchlistStocksByUserId(db *pgxpool.Pool, userId int) (stocks []Stock, err error)

type Watchlist

type Watchlist struct {
	Id     int     `json:"id"`
	Name   string  `json:"name"`
	Stocks []Stock `json:"stocks"`
}

func GetWatchlistById

func GetWatchlistById(db *pgxpool.Pool, watchlistId int) (watchlist Watchlist, err error)

func GetWatchlistsByUserId

func GetWatchlistsByUserId(db *pgxpool.Pool, userId int) (watchlists []Watchlist, err error)

Jump to

Keyboard shortcuts

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