accounts

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: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountService

type AccountService struct {
	ID string
	// contains filtered or unexported fields
}

AccountService interacts with accounts and assets repositories

func NewAccountService

func NewAccountService(ID string, repository *Repository, assetsRepository domain.AssetsRepository) (*AccountService, error)

NewAccountService returns an instance of account service

func (*AccountService) CheckAssetWithCloserPriceExists

func (a *AccountService) CheckAssetWithCloserPriceExists(price, limit float32) (bool, error)

CheckAssetWithCloserPriceExists verifies whether account already has asset with a price close to the one passed by argument

func (*AccountService) CreateAsset

func (a *AccountService) CreateAsset(amount, price float32, time time.Time) (*domain.Asset, error)

CreateAsset creates an asset hold by the account

func (*AccountService) Deposit

func (a *AccountService) Deposit(amount float32) error

Deposit increments an amount to an account

func (*AccountService) FindAllAssets

func (a *AccountService) FindAllAssets() (*[]domain.Asset, error)

FindAllAssets returns all assets hold by the account

func (*AccountService) FindPendingAssets

func (a *AccountService) FindPendingAssets() (*[]domain.Asset, error)

FindPendingAssets returns account assets awaiting to be sold

func (*AccountService) GetAmount

func (a *AccountService) GetAmount() (float32, error)

GetAmount returns the amount hold by the account

func (*AccountService) GetBalance

func (a *AccountService) GetBalance(startDate, endDate time.Time) (float32, error)

GetBalance returns the balance between two dates

func (*AccountService) SellAsset

func (a *AccountService) SellAsset(assetID string, price float32, time time.Time) error

SellAsset updates asset status to sold

func (*AccountService) Withdraw

func (a *AccountService) Withdraw(amount float32) error

Withdraw decrements an amount from an account

type AccountServiceInMemory

type AccountServiceInMemory struct {
	Amount float32

	ID string
	// contains filtered or unexported fields
}

AccountServiceInMemory emulates an account service by saving data in memory

func NewAccountServiceInMemory

func NewAccountServiceInMemory(initialAmount float32, assetsRepository domain.AssetsRepository) *AccountServiceInMemory

NewAccountServiceInMemory returns an instance of AccountServiceInMemory

func (*AccountServiceInMemory) CheckAssetWithCloserPriceExists

func (a *AccountServiceInMemory) CheckAssetWithCloserPriceExists(price, limit float32) (bool, error)

func (*AccountServiceInMemory) CreateAsset

func (a *AccountServiceInMemory) CreateAsset(amount, price float32, time time.Time) (*domain.Asset, error)

func (*AccountServiceInMemory) Deposit

func (a *AccountServiceInMemory) Deposit(amount float32) error

Deposit increases account amount

func (*AccountServiceInMemory) FindAllAssets

func (a *AccountServiceInMemory) FindAllAssets() (*[]domain.Asset, error)

func (*AccountServiceInMemory) FindPendingAssets

func (a *AccountServiceInMemory) FindPendingAssets() (*[]domain.Asset, error)

func (*AccountServiceInMemory) GetAmount

func (a *AccountServiceInMemory) GetAmount() (float32, error)

GetAmount returns amount value

func (*AccountServiceInMemory) GetBalance

func (a *AccountServiceInMemory) GetBalance(startDate, endDate time.Time) (float32, error)

func (*AccountServiceInMemory) SellAsset

func (a *AccountServiceInMemory) SellAsset(assetID string, price float32, time time.Time) error

func (*AccountServiceInMemory) Withdraw

func (a *AccountServiceInMemory) Withdraw(amount float32) error

Withdraw decreases account amount

type Repository

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

Repository stores and gets accounts from database

func NewRepository

func NewRepository(repo domain.Repository) *Repository

NewRepository returns an instance of accounts repository

func (*Repository) Create

func (r *Repository) Create(broker string, amount float32) (*domain.Account, error)

Create inserts a new account in collection

func (*Repository) Deposit

func (r *Repository) Deposit(id string, amount float32) error

Deposit increments an amount to the account

func (*Repository) FindByBroker

func (r *Repository) FindByBroker(broker string) (*domain.Account, error)

FindByBroker returns an account with the broker passed by argument

func (*Repository) FindById

func (r *Repository) FindById(id string) (*domain.Account, error)

FindById returns an account with the id passed by argument

func (*Repository) Withdraw

func (r *Repository) Withdraw(id string, amount float32) error

Withdraw decrements an amount from the account

Jump to

Keyboard shortcuts

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