market

package
v0.12.10 Latest Latest
Warning

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

Go to latest
Published: May 9, 2022 License: MIT Imports: 11 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PairMappings = map[string]Pair{}/* 1951 elements not displayed */

Functions

func CalculateOverlap added in v0.12.8

func CalculateOverlap(obA, obB OrderBook) (float64, error)

func GetMinInterval added in v0.1.4

func GetMinInterval(candles []Candle) int

GetMinInterval - Returns the minimun period interval in minutes from an array of candles

func SaveCandlesToFile added in v0.7.9

func SaveCandlesToFile(candles *[]Candle, filepath string) error

Types

type ActionType

type ActionType string

ActionType determines if the action is to buy or to sell

const (
	// BuyAction is a purchase action
	BuyAction ActionType = "buy"
	// SellAction is a selling action
	SellAction ActionType = "sell"
)

type Asset

type Asset struct {
	Name      string `json:"name"`
	Symbol    string `json:"symbol"`
	AltSymbol string `json:"alt_symbol"`
}

Asset - A resource with economic value

func NewAsset

func NewAsset(symbol, name string) (asset Asset, err error)

NewAsset creates a new Asset from a name and a symbol

func NewCryptoAsset added in v0.1.6

func NewCryptoAsset(symbol string) (Asset, error)

func NewForexAsset added in v0.1.6

func NewForexAsset(symbol string) (Asset, error)

func NewStockAsset added in v0.1.6

func NewStockAsset(symbol string) (Asset, error)

func (*Asset) String added in v0.11.0

func (a *Asset) String() string

type AssetsSnapshot added in v0.11.0

type AssetsSnapshot struct {
	Time   float64   `json:"time"`
	Assets []Balance `json:"assets"`
}

AssetsSnapshot - An snapshot of the total amount of assets

func (*AssetsSnapshot) String added in v0.11.0

func (a *AssetsSnapshot) String() string

type Balance added in v0.1.5

type Balance struct {
	Asset  *Asset  `json:"asset"`
	Amount float64 `json:"amount"`
}

Balance - An asset and its unitary amount

func (*Balance) String added in v0.11.0

func (b *Balance) String() string

type BalanceSnapshot added in v0.1.5

type BalanceSnapshot struct {
	Balance    float64 `json:"balance"`
	Equity     float64 `json:"equity"`
	Margin     float64 `json:"margin"`
	FreeMargin float64 `json:"free_margin"`
}

BalanceSnapshot - An snapshot of the current balance of a user

func (*BalanceSnapshot) String added in v0.11.0

func (b *BalanceSnapshot) String() string

type Candle

type Candle struct {
	Time   int64   `json:"time"`
	Open   float64 `json:"open"`
	High   float64 `json:"high"`
	Low    float64 `json:"low"`
	Close  float64 `json:"close"`
	Volume float64 `json:"volume"`
}

Candle represents the high, low, open, and closing prices of an asset or security for a specific period

func LoadCandlesFromFile added in v0.7.9

func LoadCandlesFromFile(filepath string) ([]Candle, error)

func ModifyInterval

func ModifyInterval(candles []Candle, minuteInterval int) ([]Candle, error)

ModifyInterval - takes an array of candles and the desired interval in minutes and returns an array of candles with the market data resampled to fit the new interval

func (*Candle) String

func (p *Candle) String() string

type Order

type Order struct {
	ID             string      `json:"id"`
	Action         ActionType  `json:"action"`
	Type           OrderType   `json:"type"`
	Pair           *Pair       `json:"pair"`
	Price          float64     `json:"price"`
	Volume         float64     `json:"volume"`
	ExecutedVolume float64     `json:"executed_volume"`
	Fee            float64     `json:"fee"`
	Cost           float64     `json:"cost"`
	Status         OrderStatus `json:"status"`
	OpenTime       time.Time   `json:"open_time"`
	CloseTime      time.Time   `json:"close_time"`
	Trades         []string    `json:"trades"`
	TakeProfit     float64     `json:"take_profit"`
	StopLoss       float64     `json:"stop_loss"`
	PositionID     string      `json:"position_id"`
	ExecutionID    string      `json:"execution_id"`
}

Order - Set of instructions to purchase or sell an asset

func (*Order) GetID added in v0.3.3

func (o *Order) GetID() string

GetID returns the ID from the Order model

func (*Order) GetSchema added in v0.3.3

func (o *Order) GetSchema() *interfaces.Schema

GetSchema returns the database schema for the Order model

func (*Order) IsOpen added in v0.6.11

func (o *Order) IsOpen() bool

func (*Order) String

func (o *Order) String() string

func (*Order) Update added in v0.3.3

func (o *Order) Update(i interface{}) error

Update sets the value of the Order instance

type OrderBook

type OrderBook struct {
	Time     int64          `json:"time"`
	Asks     []OrderBookRow `json:"asks"` // ordered from highest to lowest
	Bids     []OrderBookRow `json:"bids"` // ordered from lowest to highest
	MaxDepth int            `json:"max_depth"`
}

OrderBook - A record of active buy and sell orders in a single market

func NewOrderBook added in v0.12.1

func NewOrderBook(asks, bids []OrderBookRow, maxDepth int) OrderBook

func (*OrderBook) ApplyUpdate added in v0.12.1

func (ob *OrderBook) ApplyUpdate(update OrderBookUpdate) error

func (*OrderBook) GetDepth added in v0.1.7

func (ob *OrderBook) GetDepth(price float64) (float64, error)

GetDepth - returns the accumulated volume from a determined price a price onwards

func (*OrderBook) Print added in v0.12.1

func (ob *OrderBook) Print()

func (*OrderBook) String added in v0.11.0

func (ob *OrderBook) String() string

type OrderBookRow

type OrderBookRow struct {
	Price       float64 `json:"price"`
	Volume      float64 `json:"volume"`
	AccumVolume float64 `json:"accum_volume"`
}

OrderBookRow - A single order from the order book

func (*OrderBookRow) String added in v0.11.0

func (obr *OrderBookRow) String() string

type OrderBookUpdate added in v0.12.1

type OrderBookUpdate struct {
	Price  float64 `json:"price"`
	Volume float64 `json:"volume"`
	Side   string  `json:"side"`
}

type OrderRequest added in v0.1.9

type OrderRequest struct {
	Action     ActionType
	Type       OrderType
	Pair       Pair
	Price      float64
	TakeProfit float64
	StopLoss   float64
	Quantity   float64
	Total      float64
}

OrderRequest - Request to create an order

func NewOrderRequest added in v0.1.15

func NewOrderRequest(pair Pair, action ActionType, orderType OrderType, quantity, price, total float64) (*OrderRequest, error)

NewOrderRequest - creates a valid new OrderRequest

func (*OrderRequest) CalculateFields added in v0.1.15

func (o *OrderRequest) CalculateFields(currentPrice float64) (*OrderRequest, error)

func (*OrderRequest) String added in v0.1.10

func (o *OrderRequest) String() string

type OrderStatus added in v0.1.9

type OrderStatus string

OrderStatus - determines the status of the order

const (
	// FulfilledOrder - The entirety of the order was filled
	FulfilledOrder OrderStatus = "fulfilled"
	// PartialyFilledOrder - A the order has been filled partialy
	PartialyFilledOrder OrderStatus = "partial_fill"
	// UnfilledOrder - The order has not been filled
	UnfilledOrder OrderStatus = "unfilled"
	// CanceledOrder - The order has been cancelled
	CanceledOrder OrderStatus = "canceled"
)

type OrderType

type OrderType string

OrderType determines the type of market order

const (
	// MarketOrder will buy or sell at whatever the current price is
	MarketOrder OrderType = "market"
	// ClosePosition will buy or sell at whatever the current price to close a position
	ClosePosition OrderType = "close_position"

	// LimitOrder will buy or sell at a specific price
	LimitOrder OrderType = "limit"
	// TakeProfit will buy or sell at a specific price
	TakeProfit OrderType = "take_profit"
	// StopLoss will buy or sell at a specific price
	StopLoss OrderType = "stop_loss"
)

type Pair

type Pair struct {
	Base  Asset `json:"base"`
	Quote Asset `json:"quote"`
}

Pair - Quotation of two different assets or currencies, with the value of one being quoted against the other.

func NewPair

func NewPair(base, quote Asset) Pair

NewPair creates a new Pair from two assets

func (*Pair) String added in v0.1.13

func (p *Pair) String() string

String - Implements Stringer interface

func (*Pair) Symbol added in v0.6.10

func (p *Pair) Symbol(separator string) string

Symbol - Gets the current symbol

type Position

type Position struct {
	ID          string             `json:"id"`
	Type        PositionType       `json:"type"`
	Pair        Pair               `json:"pair"`
	Open        bool               `json:"open"`
	TakeProfit  PositionCloseOrder `json:"take_profit"`
	StopLoss    PositionCloseOrder `json:"stop_loss"`
	OpenPrice   float64            `json:"open_price"`
	ClosePrice  float64            `json:"close_price"`
	Quantity    float64            `json:"quantity"`
	Profit      float64            `json:"profit"`
	OpenTime    time.Time          `json:"open_time"`
	CloseTime   time.Time          `json:"close_time"`
	Trades      []string           `json:"trades"`
	ExecutionID string             `json:"execution_id"`
	Data        string             `json:"data"`
}

Position represents a market position

func NewPosition

func NewPosition(trade *Trade) *Position

NewPosition creates a new Position

func (*Position) GetID added in v0.3.3

func (p *Position) GetID() string

GetID returns the ID from the Position model

func (*Position) GetSchema added in v0.3.3

func (p *Position) GetSchema() *interfaces.Schema

GetSchema returns the database schema for the Position model

func (*Position) Modify

func (p *Position) Modify(trade *Trade) error

Modify receives a new trade that updates the position

func (*Position) String

func (p *Position) String() string

func (*Position) UnrealizedProfit added in v0.7.5

func (p *Position) UnrealizedProfit(currentPrice float64) float64

UnrealizedProfit - Returns the current unrealized profit of the position

func (*Position) Update

func (p *Position) Update(i interface{}) error

Update sets the value of the Position instance

type PositionCloseOrder added in v0.6.8

type PositionCloseOrder struct {
	Price   float64 `json:"price"`
	OrderID string  `json:"order_id"`
}

PositionCloseOrder - A TakeProfit or StopLoss order to close the position

func (*PositionCloseOrder) String added in v0.11.0

func (p *PositionCloseOrder) String() string

type PositionType

type PositionType string

PositionType determines if its a long or short position

const (
	// LongPosition buy the asset
	LongPosition PositionType = "long"
	// ShortPosition sell the asset
	ShortPosition PositionType = "short"
)

type Ticker

type Ticker struct {
	Time   int64   `json:"time"`
	Ask    float64 `json:"ask"`
	Bid    float64 `json:"bid"`
	Last   float64 `json:"last"`
	Volume float64 `json:"volume"`
	VWAP   float64 `json:"vwap"`
}

Ticker - The Latest price data for an asset

func (*Ticker) String added in v0.11.0

func (t *Ticker) String() string

type Trade

type Trade struct {
	ID            string     `json:"id"`
	ExecutionTime time.Time  `json:"execution_time"`
	Action        ActionType `json:"action"`
	OrderType     OrderType  `json:"order_type"`
	Pair          Pair       `json:"pair"`
	Price         float64    `json:"price"`
	Quantity      float64    `json:"quantity"`
	Fee           float64    `json:"fee"`
	Cost          float64    `json:"cost"`
	ExecutionID   string     `json:"execution_id"`
}

Trade represents a market trade

func NewTrade

func NewTrade(id string, executionTime time.Time, actionType ActionType, orderType OrderType, pair Pair, price, quantity, cost float64) *Trade

NewTrade creates a new trade

func (*Trade) GetID added in v0.3.3

func (t *Trade) GetID() string

GetID returns the ID from the Trade model

func (*Trade) GetSchema added in v0.3.3

func (t *Trade) GetSchema() *interfaces.Schema

GetSchema returns the database schema for the Trade model

func (*Trade) String

func (t *Trade) String() string

func (*Trade) Update added in v0.3.3

func (t *Trade) Update(i interface{}) error

Update sets the value of the Trade instance

Jump to

Keyboard shortcuts

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