order

package
Version: v0.0.0-...-6a9f9bf Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 7 Imported by: 0

README

GoCryptoTrader package Orders

Build Status Software License GoDoc Coverage Status Go Report Card

This orders package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progress on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Current Features for orders

  • This package services the exchanges package with order handling.
    • Creation of order
    • Deletion of order
    • Order tracking
Please click GoDocs chevron above to view current GoDoc information for this package

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSubmissionIsNil            = errors.New("order submission is nil")
	ErrPairIsEmpty                = errors.New("order pair is empty")
	ErrSideIsInvalid              = errors.New("order side is invalid")
	ErrTypeIsInvalid              = errors.New("order type is invalid")
	ErrAmountIsInvalid            = errors.New("order amount is invalid")
	ErrPriceMustBeSetIfLimitOrder = errors.New("order price must be set if limit order type is desired")
)

var error definitions

Functions

func FilterOrdersByCurrencies

func FilterOrdersByCurrencies(orders *[]Detail, currencies []currency.Pair)

FilterOrdersByCurrencies removes any order details that do not match the provided currency list. It is forgiving in that the provided currencies can match quote or base currencies

func FilterOrdersBySide

func FilterOrdersBySide(orders *[]Detail, side Side)

FilterOrdersBySide removes any order details that don't match the order status provided

func FilterOrdersByTickRange

func FilterOrdersByTickRange(orders *[]Detail, startTicks, endTicks time.Time)

FilterOrdersByTickRange removes any OrderDetails outside of the tick range

func FilterOrdersByType

func FilterOrdersByType(orders *[]Detail, orderType Type)

FilterOrdersByType removes any order details that don't match the order type provided

func SortOrdersByCurrency

func SortOrdersByCurrency(orders *[]Detail, reverse bool)

SortOrdersByCurrency the caller function to sort orders

func SortOrdersByDate

func SortOrdersByDate(orders *[]Detail, reverse bool)

SortOrdersByDate the caller function to sort orders

func SortOrdersByPrice

func SortOrdersByPrice(orders *[]Detail, reverse bool)

SortOrdersByPrice the caller function to sort orders

func SortOrdersBySide

func SortOrdersBySide(orders *[]Detail, reverse bool)

SortOrdersBySide the caller function to sort orders

func SortOrdersByType

func SortOrdersByType(orders *[]Detail, reverse bool)

SortOrdersByType the caller function to sort orders

Types

type ByCurrency

type ByCurrency []Detail

ByCurrency used for sorting orders by order currency

func (ByCurrency) Len

func (b ByCurrency) Len() int

func (ByCurrency) Less

func (b ByCurrency) Less(i, j int) bool

func (ByCurrency) Swap

func (b ByCurrency) Swap(i, j int)

type ByDate

type ByDate []Detail

ByDate used for sorting orders by order date

func (ByDate) Len

func (b ByDate) Len() int

func (ByDate) Less

func (b ByDate) Less(i, j int) bool

func (ByDate) Swap

func (b ByDate) Swap(i, j int)

type ByOrderSide

type ByOrderSide []Detail

ByOrderSide used for sorting orders by order side (buy sell)

func (ByOrderSide) Len

func (b ByOrderSide) Len() int

func (ByOrderSide) Less

func (b ByOrderSide) Less(i, j int) bool

func (ByOrderSide) Swap

func (b ByOrderSide) Swap(i, j int)

type ByOrderType

type ByOrderType []Detail

ByOrderType used for sorting orders by order type

func (ByOrderType) Len

func (b ByOrderType) Len() int

func (ByOrderType) Less

func (b ByOrderType) Less(i, j int) bool

func (ByOrderType) Swap

func (b ByOrderType) Swap(i, j int)

type ByPrice

type ByPrice []Detail

ByPrice used for sorting orders by price

func (ByPrice) Len

func (b ByPrice) Len() int

func (ByPrice) Less

func (b ByPrice) Less(i, j int) bool

func (ByPrice) Swap

func (b ByPrice) Swap(i, j int)

type Cancel

type Cancel struct {
	Price         float64
	Amount        float64
	Exchange      string
	ID            string
	ClientOrderID string
	AccountID     string
	ClientID      string
	WalletAddress string
	Type          Type
	Side          Side
	Status        Status
	AssetType     asset.Item
	Date          time.Time
	Pair          currency.Pair
	Trades        []TradeHistory
}

Cancel contains all properties that may be required to cancel an order on an exchange Each exchange has their own requirements, so not all fields are required to be populated

type CancelAllResponse

type CancelAllResponse struct {
	Status map[string]string
}

CancelAllResponse returns the status from attempting to cancel all orders on an exchange

type ClassificationError

type ClassificationError struct {
	Exchange string
	OrderID  string
	Err      error
}

ClassificationError returned when an order status side or type cannot be recognised

func (*ClassificationError) Error

func (o *ClassificationError) Error() string

type Detail

type Detail struct {
	ImmediateOrCancel bool
	HiddenOrder       bool
	FillOrKill        bool
	PostOnly          bool
	Leverage          string
	Price             float64
	Amount            float64
	LimitPriceUpper   float64
	LimitPriceLower   float64
	TriggerPrice      float64
	TargetAmount      float64
	ExecutedAmount    float64
	RemainingAmount   float64
	Fee               float64
	Exchange          string
	InternalOrderID   string
	ID                string
	ClientOrderID     string
	AccountID         string
	ClientID          string
	WalletAddress     string
	Type              Type
	Side              Side
	Status            Status
	AssetType         asset.Item
	Date              time.Time
	CloseTime         time.Time
	LastUpdated       time.Time
	Pair              currency.Pair
	Trades            []TradeHistory
}

Detail contains all properties of an order Each exchange has their own requirements, so not all fields are required to be populated

func (*Detail) UpdateOrderFromDetail

func (d *Detail) UpdateOrderFromDetail(m *Detail)

UpdateOrderFromDetail Will update an order detail (used in order management) by comparing passed in and existing values

func (*Detail) UpdateOrderFromModify

func (d *Detail) UpdateOrderFromModify(m *Modify)

UpdateOrderFromModify Will update an order detail (used in order management) by comparing passed in and existing values

type GetOrdersRequest

type GetOrdersRequest struct {
	Type       Type
	Side       Side
	StartTicks time.Time
	EndTicks   time.Time
	// Currencies Empty array = all currencies. Some endpoints only support
	// singular currency enquiries
	Pairs []currency.Pair
}

GetOrdersRequest used for GetOrderHistory and GetOpenOrders wrapper functions

type Modify

type Modify struct {
	ImmediateOrCancel bool
	HiddenOrder       bool
	FillOrKill        bool
	PostOnly          bool
	Leverage          string
	Price             float64
	Amount            float64
	LimitPriceUpper   float64
	LimitPriceLower   float64
	TriggerPrice      float64
	TargetAmount      float64
	ExecutedAmount    float64
	RemainingAmount   float64
	Fee               float64
	Exchange          string
	InternalOrderID   string
	ID                string
	ClientOrderID     string
	AccountID         string
	ClientID          string
	WalletAddress     string
	Type              Type
	Side              Side
	Status            Status
	AssetType         asset.Item
	Date              time.Time
	LastUpdated       time.Time
	Pair              currency.Pair
	Trades            []TradeHistory
}

Modify contains all properties of an order that may be updated after it has been created Each exchange has their own requirements, so not all fields are required to be populated

type ModifyResponse

type ModifyResponse struct {
	OrderID string
}

ModifyResponse is an order modifying return type

type Side

type Side string

Side enforces a standard for order sides across the code base

const (
	AnySide     Side = "ANY"
	Buy         Side = "BUY"
	Sell        Side = "SELL"
	Bid         Side = "BID"
	Ask         Side = "ASK"
	UnknownSide Side = "UNKNOWN"
)

Order side types

func StringToOrderSide

func StringToOrderSide(side string) (Side, error)

StringToOrderSide for converting case insensitive order side and returning a real Side

func (Side) Lower

func (s Side) Lower() string

Lower returns the side lower case string

func (Side) String

func (s Side) String() string

String implements the stringer interface

func (Side) Title

func (s Side) Title() string

Title returns the side titleized, eg "Buy"

type Status

type Status string

Status defines order status types

const (
	AnyStatus           Status = "ANY"
	New                 Status = "NEW"
	Active              Status = "ACTIVE"
	PartiallyCancelled  Status = "PARTIALLY_CANCELLED"
	PartiallyFilled     Status = "PARTIALLY_FILLED"
	Filled              Status = "FILLED"
	Cancelled           Status = "CANCELLED"
	PendingCancel       Status = "PENDING_CANCEL"
	InsufficientBalance Status = "INSUFFICIENT_BALANCE"
	MarketUnavailable   Status = "MARKET_UNAVAILABLE"
	Rejected            Status = "REJECTED"
	Expired             Status = "EXPIRED"
	Hidden              Status = "HIDDEN"
	UnknownStatus       Status = "UNKNOWN"
	Open                Status = "OPEN"
)

All order status types

func StringToOrderStatus

func StringToOrderStatus(status string) (Status, error)

StringToOrderStatus for converting case insensitive order status and returning a real Status

func (Status) String

func (s Status) String() string

String implements the stringer interface

type Submit

type Submit struct {
	ImmediateOrCancel bool
	HiddenOrder       bool
	FillOrKill        bool
	PostOnly          bool
	Leverage          string
	Price             float64
	Amount            float64
	LimitPriceUpper   float64
	LimitPriceLower   float64
	TriggerPrice      float64
	TargetAmount      float64
	ExecutedAmount    float64
	RemainingAmount   float64
	Fee               float64
	Exchange          string
	InternalOrderID   string
	ID                string
	AccountID         string
	ClientID          string
	ClientOrderID     string
	WalletAddress     string
	Type              Type
	Side              Side
	Status            Status
	AssetType         asset.Item
	Date              time.Time
	LastUpdated       time.Time
	Pair              currency.Pair
	Trades            []TradeHistory
}

Submit contains all properties of an order that may be required for an order to be created on an exchange Each exchange has their own requirements, so not all fields are required to be populated

func (*Submit) Validate

func (s *Submit) Validate() error

Validate checks the supplied data and returns whether or not it's valid

type SubmitResponse

type SubmitResponse struct {
	IsOrderPlaced bool
	FullyMatched  bool
	OrderID       string
}

SubmitResponse is what is returned after submitting an order to an exchange

type TradeHistory

type TradeHistory struct {
	Price       float64
	Amount      float64
	Fee         float64
	Exchange    string
	TID         string
	Description string
	Type        Type
	Side        Side
	Timestamp   time.Time
	IsMaker     bool
}

TradeHistory holds exchange history data

type Type

type Type string

Type enforces a standard for order types across the code base

const (
	AnyType           Type = "ANY"
	Limit             Type = "LIMIT"
	Market            Type = "MARKET"
	PostOnly          Type = "POST_ONLY"
	ImmediateOrCancel Type = "IMMEDIATE_OR_CANCEL"
	Stop              Type = "STOP"
	StopLimit         Type = "STOP LIMIT"
	TrailingStop      Type = "TRAILING_STOP"
	FillOrKill        Type = "FOK"
	IOS               Type = "IOS"
	UnknownType       Type = "UNKNOWN"
)

Defined package order types

func StringToOrderType

func StringToOrderType(oType string) (Type, error)

StringToOrderType for converting case insensitive order type and returning a real Type

func (Type) Lower

func (t Type) Lower() string

Lower returns the type lower case string

func (Type) String

func (t Type) String() string

String implements the stringer interface

func (Type) Title

func (t Type) Title() string

Title returns the type titleized, eg "Limit"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL