Documentation ¶
Overview ¶
Package position provides middleware utilities around positions. It wraps calls to the database and to the binance endpoints.
Index ¶
- Variables
- type Core
- func (c Core) Close(ctx context.Context, posID string) error
- func (c Core) Create(ctx context.Context, nPos NewPosition, now time.Time) (Position, error)
- func (c Core) Query(ctx context.Context, pageNumber int, rowsPerPage int) ([]Position, error)
- func (c Core) QueryByID(ctx context.Context, posID string) (Position, error)
- func (c Core) QueryByUser(ctx context.Context, pageNumber int, rowsPerPage int, usrID string) ([]Position, error)
- type NewPosition
- type Order
- type Position
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 ¶
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.
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
Click to show internal directories.
Click to hide internal directories.