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 order 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 order 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, odr Order) error

Create inserts a new order into the database.

func (Agent) Query

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

Query retrieves a list of existing orders from the database.

func (Agent) QueryByID

func (s Agent) QueryByID(ctx context.Context, odrID string) (Order, error)

QueryByID gets the specified order from the database.

func (Agent) QueryByPosition

func (s Agent) QueryByPosition(ctx context.Context, odrID string) ([]Order, error)

QueryByPosition retrieves all order for a given position.

func (Agent) QueryByUser

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

QueryByUser gets the specified order from the database.

func (Agent) Tran

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

Tran return new Store with transaction in it.

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 Order

type Order struct {
	ID           string    `db:"order_id"`      // Order ID
	SymbolID     string    `db:"symbol_id"`     // SymbolID ID, this orders trades on
	PositionID   string    `db:"position_id"`   // Order ID this order belongs to
	CreationTime time.Time `db:"creation_time"` // Order creation time
	Price        float64   `db:"price"`         // Price of the base asset
	Quantity     float64   `db:"quantity"`      // Amount of the base asset
	Status       string    `db:"status"`        // Status received from binance: FILLED, NEW, CANCELED
	Type         string    `db:"type"`          // For the moment only MARKET is supported
	Side         string    `db:"side"`          // Either SELL or BUY
}

Order defines a trading order

Jump to

Keyboard shortcuts

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