position

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

Documentation

Overview

Package position provides middleware utilities around positions. It wraps calls to the database and to the binance endpoints.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = errors.New("position not found")
	ErrInvalidID     = errors.New("ID is not in its proper form")
	ErrAlreadyClosed = errors.New("can't close a position that is already closed")

	CLOSED = "CLOSED"
	OPEN   = "OPEN"
)

Set of error variables for CRUD operations.

Functions

This section is empty.

Types

type Core

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

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

func NewCore

func NewCore(log *zap.SugaredLogger, sqlxDB *sqlx.DB) Core

NewCore constructs a core for user api access.

func (Core) Close

func (c Core) Close(ctx context.Context, posID string) error

Close closes a position identified by a given ID. Closing a position consist on figuring out the open balance and creating a position to set balance to 0.

func (Core) Create

func (c Core) Create(ctx context.Context, nPos NewPosition, now time.Time) (Position, error)

Create inserts a new position into the database.

func (Core) Query

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

Query gets the specified positions.

func (Core) QueryByID

func (c Core) QueryByID(ctx context.Context, posID string) (Position, error)

QueryByID gets the specified position from the database.

func (Core) QueryByUser

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

QueryByUser gets the specified position from the database given a userId.

type NewPosition

type NewPosition struct {
	UserID   string `json:"user_id"`
	SymbolID string `json:"symbol_id" validate:"required"`
	Side     string `json:"side" validate:"required"`
}

NewPosition contains information needed to create a new position

type Order

type Order struct {
	ID           string    `json:"order_id"`
	SymbolID     string    `json:"symbol_id"`
	PositionID   string    `json:"position_id"`
	CreationTime orderTime `json:"creation_time"`
	Price        float64   `json:"price"`
	Quantity     float64   `json:"quantity"`
	Status       string    `json:"status"`
	Type         string    `json:"type"`
	Side         string    `json:"side"`
}

Order represent an order in a position

type Position

type Position struct {
	ID           string    `json:"position_id"`   // Position ID
	SymbolID     string    `json:"-"`             // SymbolID this position is trading on, used to preload Symbol
	UserID       string    `json:"-"`             // UserID who created this position, used to preload User
	Side         string    `json:"side"`          // Position side: SELL / BUY
	Status       string    `json:"status"`        // Status open / closed
	CreationTime time.Time `json:"creation_time"` // CreationTime of the position
	User         string    `json:"user"`          // Name of the owner
	Symbol       string    `json:"symbol"`        // Symbol this position is trading on
	Orders       []Order   `json:"orders"`        // Orders belonging to this position
}

Position represents a single position

Directories

Path Synopsis
Package db contains position related CRUD functionality.
Package db contains position related CRUD functionality.

Jump to

Keyboard shortcuts

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