db

package
v0.0.0-...-c46be8d Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package db contains position related CRUD functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

Agent manages the set of API's for candle access.

func NewAgent

func NewAgent(log *zap.SugaredLogger, db *sqlx.DB) Agent

NewAgent constructs a data for api access.

func (Agent) Create

func (s Agent) Create(ctx context.Context, pos Position) error

Create inserts a new position into the database.

func (Agent) Query

func (s Agent) Query(ctx context.Context, pageNumber int, rowsPerPage int) ([]Position, error)

Query retrieves a list of existing positions from the database.

func (Agent) QueryByID

func (s Agent) QueryByID(ctx context.Context, posID string) (Position, error)

QueryByID gets the specified position from the database.

func (Agent) QueryByUser

func (s Agent) QueryByUser(ctx context.Context, pageNumber int, rowsPerPage int, usrID string) ([]Position, error)

QueryByUser gets the specified candles from the database.

func (Agent) Tran

func (s Agent) Tran(tx sqlx.ExtContext) Agent

Tran return new Agent with transaction in it.

func (Agent) Update

func (s Agent) Update(ctx context.Context, pos Position) error

Update modifies data about a Position. It will error if the specified ID is invalid or does not reference an existing Position. When updating a position, it only makes sense to change its status from open to closed.

func (Agent) WithinTran

func (s Agent) WithinTran(ctx context.Context, fn func(sqlx.ExtContext) error) error

WithinTran runs passed function and do commit/rollback at the end.

type Position

type Position struct {
	ID           string    `db:"position_id"`   // Position ID
	SymbolID     string    `db:"symbol_id"`     // Symbol this position is trading on
	UserID       string    `db:"user_id"`       // User who created this position
	Side         string    `db:"side"`          // Position side: SELL / BUY
	Status       string    `db:"status"`        // Status open / closed
	CreationTime time.Time `db:"creation_time"` // CreationTime of the position
	User         string    `db:"user"`
	Symbol       string    `db:"symbol"`
	Orders       string    `db:"orders"`
}

Position is the amount of a security, asset, or property that is owned (or sold short) by some individual or other entity. A trader or investor takes a position when they make a purchase through

Jump to

Keyboard shortcuts

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