v1

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

Documentation

Overview

Package v1 do calls to machina api v1

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnexpectedCode occurs when a strategy tries opens or close a position, but the strategy's budget is out of fund.
	ErrUnexpectedCode = errors.New("unexpected code in response")
)

Functions

This section is empty.

Types

type Candle

type Candle struct {
	ID         string    `json:"id"`
	SymbolID   string    `json:"symbol_id"`
	Symbol     string    `json:"symbol"`
	Interval   string    `json:"interval"`
	OpenTime   time.Time `json:"open_time"`
	OpenPrice  float64   `json:"open_price"`
	ClosePrice float64   `json:"close_price"`
	CloseTime  time.Time `json:"close_time"`
	Low        float64   `json:"low"`
	High       float64   `json:"high"`
	Volume     float64   `json:"volume"`
}

Candle Candlestick charts are used by traders to determine possible price movement based on past patterns.

type Client

type Client struct {
	*retryablehttp.Client
	Username  string
	Password  string
	TraderAPI string

	PullInterval time.Duration
	// contains filtered or unexported fields
}

func (*Client) Authenticate

func (c *Client) Authenticate() error

Authenticate requests a token from the trader api

func (*Client) ClosePosition

func (c *Client) ClosePosition(id string) (p *Position, err error)

ClosePosition closes a position using the trader api

func (*Client) CreateOrder

func (c *Client) CreateOrder(no NewOrder) (o *Order, err error)

func (*Client) CreatePosition

func (c *Client) CreatePosition(np NewPosition, quantity float64) (p *Position, err error)

CreatePosition do a POST to the trader api and Creates a position

func (*Client) ListPositions

func (c *Client) ListPositions() (p []Position, err error)

ListPositions return all positions belonging to this username

func (*Client) RetrieveCandle

func (c *Client) RetrieveCandle(par string, interval string, pageNumber int, rowsPerPage int) (candle []Candle, err error)

func (*Client) RetrievePosition

func (c *Client) RetrievePosition() (p *Position, err error)

RetrievePosition return the last position belonging to this username

type NewOrder

type NewOrder struct {
	PositionID string  `json:"position_id"`
	Quantity   float64 `json:"quantity"`
	Side       string  `json:"side"`
}

NewOrder contains information needed to create a new Order.

type NewPosition

type NewPosition struct {
	SymbolID string `json:"symbol_id"`
	Side     string `json:"side"`
}

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 time.Time `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

Jump to

Keyboard shortcuts

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