ordersservice

package
v0.0.0-...-72dd2e1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuyOrder

type BuyOrder interface {
	// GetID returns the unique identifier used to identify this
	// record in persistent storage
	GetID() string

	// GetPrice returns the price the order was purchased at
	// in increments of 1/1000 of a penny
	GetPrice() int

	// GetQuantity returns the quantity of stock purchased
	GetQuantity() int

	// GetTicker returns the stock ticker code
	GetTicker() string

	// GetTimestamp returns the timestamp from when the order was made
	GetTimestamp() time.Time

	// GetUserID returns the user who will be paying the order
	GetUserID() string
}

BuyOrder represents a purchase order for a specific stock

func NewBuyOrder

func NewBuyOrder(userID, ticker string, quantity, price int, timestamp time.Time) BuyOrder

NewBuyOrder constructs a new order instance given a user, ticker, and price. it will also gain an ID, representing just this order instance

type OrdersService

type OrdersService interface {
	// CreateBuyOrder will persist a new order at the market rate
	// for the given ticker. The market rate will be subtracted
	// from the given profile's riches and the user's stock
	// quantity for this ticker will go up.
	CreateBuyOrder(userID, ticker string, quantity int) (BuyOrder, error)

	// GetBuyOrder will retrieve a buy order for a given user & id
	GetBuyOrder(userID, id string) (BuyOrder, error)

	// GetSellOrder will retrieve a sell order for a given user & id
	GetSellOrder(userID, id string) (SellOrder, error)

	// ListBuyOrders returns all orders for a user
	ListBuyOrders(userID string) ([]BuyOrder, error)

	// ListSellOrders returns all orders for a user
	ListSellOrders(userID string) ([]SellOrder, error)

	// CreateSellOrder will persist a new sell order at the market rate
	// for the given ticker. The market rate will be added
	// to the given user's riches and the user's stock quantity
	// for this ticker will go down. It will return an error if
	// the user doesn't own enough of the stock
	CreateSellOrder(userID, ticker string, quantity int) (SellOrder, error)
}

OrdersService manages CRUD for buy & sell orders

func New

func New(mongoDB *mgo.Session, usersService usersservice.UsersService) OrdersService

New constructs a new BuyOrdersService that will persist data using the provided mongo session

type SellOrder

type SellOrder interface {
	// GetID returns the unique identifier used to identify this
	// record in persistent storage
	GetID() string

	// GetPrice returns the price the order was purchased at
	// in increments of 1/1000 of a penny
	GetPrice() int

	// GetQuantity returns the quantity of stock sold
	GetQuantity() int

	// GetTicker returns the stock ticker code
	GetTicker() string

	// GetTimestamp returns the timestamp from when the order was created
	GetTimestamp() time.Time

	// GetUserID returns the user who will be paying the order
	GetUserID() string
}

SellOrder represents a sell order for a specific stock

func NewSellOrder

func NewSellOrder(userID, ticker string, quantity, price int, timestamp time.Time) SellOrder

NewSellOrder constructs a new order instance given a user, ticker, and price. it will also gain an ID, representing just this order instance

Jump to

Keyboard shortcuts

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