assetsprices

package
v0.0.0-...-bc78c8b Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDatesPlusOneDay

func GetDatesPlusOneDay(startDate, endDate time.Time) (time.Time, time.Time)

GetDatesPlusOneDay returns the two dates passed by parameter with one more day

func SerializeDate

func SerializeDate(date time.Time) string

SerializeDate convert time to string formatted to be accepted on coindesk url as parameter

func TransverseDatesRange

func TransverseDatesRange(startDate, endDate time.Time, handle func(time.Time, time.Time) error)

TransverseDatesRange iterate every day in the dates range passed and call the callback function

Types

type AssetPrice

type AssetPrice = domain.AssetPrice

type CoindeskRemoteSource

type CoindeskRemoteSource struct {
	HTTPFetcher UrlDataFetcher
}

func NewCoindeskRemoteSource

func NewCoindeskRemoteSource(HTTPFetcher UrlDataFetcher) *CoindeskRemoteSource

func (*CoindeskRemoteSource) FetchRemoteAssetsPrices

func (c *CoindeskRemoteSource) FetchRemoteAssetsPrices(startDate, endDate time.Time, asset string) (*[]bson.M, error)

FetchRemoteAssetsPrices uses remote source to get asset prices

type FetchRemotePricesType

type FetchRemotePricesType = func(startDate, endDate time.Time, asset string) (*[]bson.M, error)

type Repository

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

Repository stores and gets assets prices

func NewRepository

func NewRepository(repo domain.Repository) *Repository

NewRepository returns an instance of AssetsPricesRepository

func (*Repository) Aggregate

func (r *Repository) Aggregate(pipeline mongo.Pipeline) (*[]bson.M, error)

Aggregate returns assets prices aggregated

func (*Repository) BulkCreate

func (r *Repository) BulkCreate(documents *[]bson.M) error

BulkCreate creates multiple assets prices

func (*Repository) Create

func (r *Repository) Create(ohlc *domain.OHLC, asset string) error

Create stores an asset price

func (*Repository) FindAll

func (r *Repository) FindAll(filter interface{}) (*[]domain.AssetPrice, error)

FindAll returns assets prices

func (*Repository) FindOne

func (r *Repository) FindOne(filter interface{}) (interface{}, error)

FindOne returns an asset price

func (*Repository) GetLastAssetsPrices

func (r *Repository) GetLastAssetsPrices(asset string, limit int) (*[]domain.AssetPrice, error)

GetLastAssetsPrices return the last asset price stored in DB

type RepositoryInMemory

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

RepositoryInMemory stores and gets assets prices in memory

func NewRepositoryInMemory

func NewRepositoryInMemory() *RepositoryInMemory

NewRepositoryInMemory returns assets prices repository mock

func (*RepositoryInMemory) Aggregate

func (r *RepositoryInMemory) Aggregate(pipeline mongo.Pipeline) (*[]bson.M, error)

Aggregate returns assets prices aggregated

func (*RepositoryInMemory) BulkCreate

func (r *RepositoryInMemory) BulkCreate(documents *[]bson.M) error

BulkCreate stub

func (*RepositoryInMemory) Create

func (r *RepositoryInMemory) Create(ohlc *domain.OHLC, asset string) error

Create stores an asset price

func (*RepositoryInMemory) FindAll

func (r *RepositoryInMemory) FindAll(filter interface{}) (*[]domain.AssetPrice, error)

FindAll returns assets prices

func (*RepositoryInMemory) FindOne

func (r *RepositoryInMemory) FindOne(date time.Time, value float32, asset string) (*domain.AssetPrice, error)

FindOne returns an asset price

func (*RepositoryInMemory) GetLastAssetsPrices

func (r *RepositoryInMemory) GetLastAssetsPrices(asset string, limit int) (*[]domain.AssetPrice, error)

GetLastAssetsPrices stub

type Service

type Service struct {
	FetchRemotePrices FetchRemotePricesType
	// contains filtered or unexported fields
}

Service provides assets prices methods

func NewService

func NewService(repo domain.AssetPriceRepository, fetchRemotePrices FetchRemotePricesType) *Service

NewService returns an instance of AssetsPricesService

func (*Service) Create

func (s *Service) Create(ohlc *domain.OHLC, asset string) error

Create creates an asset price in repository

func (*Service) FetchAndStoreAssetPrices

func (s *Service) FetchAndStoreAssetPrices(asset string, endDate time.Time) error

FetchAndStoreAssetPrices fetches asset prices remotely and save it in repository

func (*Service) GetLastAssetsPrices

func (s *Service) GetLastAssetsPrices(asset string, limit int) (*[]domain.AssetPrice, error)

GetLastAssetsPrices returns the last price of an asset in the repository

type UrlDataFetcher

type UrlDataFetcher func(url string) (resp *http.Response, err error)

Jump to

Keyboard shortcuts

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