model

package module
v0.0.0-...-dee091a Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 5 Imported by: 0

README

trade-models

Models required for trading

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exchange

type Exchange string
const (
	ExchangeBitflyer Exchange = "bitflyer"
	ExchangeZero     Exchange = ""
)

func NewTradingViewToExchange

func NewTradingViewToExchange(e string) (Exchange, error)

NewTradingViewToExchange maps trading exchanges to exchanges that this system can read

type Exec

type Exec struct {
	// ID is the identifier for execution
	ID string

	// ExchangeExecID is an ID generated by the exchange. It may not exist
	ExchangeExecID string

	// ExchangeOrdID is the original order id. There can be 1 Order (OrdID) to n Exec
	OrdID string

	// Side of trade
	Side Side

	// Px is the price of trade
	Px string

	// Qty is the qty of trade
	Qty string

	// Timestamp is the time of execution
	Timestamp time.Time
}

Exec is a single Execution

func NewExec

func NewExec(px, qty string, side Side, t time.Time, oID string) (Exec, error)

NewExec creates new execution

func NewExecWithFloat

func NewExecWithFloat(px, qty float64, side Side, t time.Time, ordID string) (Exec, error)

NewExecWithFloat creates new execution from float value

func (Exec) GetFloatPx

func (e Exec) GetFloatPx() (float64, error)

func (Exec) GetFloatQty

func (e Exec) GetFloatQty() (float64, error)

type ExecList

type ExecList []Exec

func (ExecList) GetAvg

func (exec ExecList) GetAvg() (filledAvgPx float64, filledQty float64, err error)

type OrdStatus

type OrdStatus string
const (
	OrdStatusDraft           OrdStatus = "draft"
	OrdStatusPendingNew      OrdStatus = "pending_new"
	OrdStatusNew             OrdStatus = "new"
	OrdStatusPartiallyFilled OrdStatus = "partially_filled"
	OrdStatusFilled          OrdStatus = "filled"
	OrdStatusPendingCancel   OrdStatus = "pending_cancel"
	OrdStatusCanceled        OrdStatus = "canceled"
	OrdStatusRejected        OrdStatus = "rejected"
)

type Order

type Order struct {
	// ID is the identifier on the database
	ID string

	// account ID is the account of this user
	AccountID string

	// StrategyID is the strategy identifier
	StrategyID string

	// SignalID is the signal that is generated by the strategy
	SignalID string

	// ExchangeOrderID is the order ID on the exchange
	ExchangeOrderID string

	// OrderStatus is the status of the order
	OrderStatus OrdStatus

	// Side is the side of the trade
	Side Side

	// Symbol is the symbol to trade
	Symbol string

	// Qty is the quantity to be sent
	Qty string

	// FilledQty is the quantity that has been filled
	FilledQty string

	// Exchange is the exchange name
	Exchange Exchange

	// OrderStructure is the structure of the order on the exchange
	OrderStructure OrderStructure

	// OrderMethod is the native method in which orders are executed
	OrderMethod OrderMethod

	// Px is the price used for limit
	Px string

	// FilledPx is the average fill price
	FilledPx string

	// TriggerPx is the price used to trigger a stop
	TriggerPx string

	// IFDOCO is if-done-one-cancels-other order
	IFDOCO *OrderMethodParamIFDOCO

	// TimeInForce is the time limit of the order on the exchange
	TimeInForce TimeInForce
}

Order is an order planned or sent to the exchange

func NewchildOrder

func NewchildOrder(
	exch Exchange,
	symbol, signalID, strategyID string,
	om OrderMethod,
	side Side,
	px, qty string,
	tif TimeInForce,
	status OrdStatus,
) (*Order, error)

NewChildOrder creates a new child order

func (*Order) Validate

func (o *Order) Validate() error

type OrderChange

type OrderChange struct {
	Action string
	Order  Order
}

type OrderChangeAction

type OrderChangeAction string
const (
	OrderChangeActionNew            OrderChangeAction = "new"
	OrderChangeActionUpdate         OrderChangeAction = "update"
	OrderChangeActionCancel         OrderChangeAction = "cancel"
	OrderChangeActionCancelAndClose OrderChangeAction = "cancel_close"
)

type OrderMethod

type OrderMethod string
const (
	OrderMethodIFD    OrderMethod = "ifd"
	OrderMethodIFDOCO OrderMethod = "ifdoco"
	OrderMethodLimit  OrderMethod = "limit"
	OrderMethodStop   OrderMethod = "stop"
	OrderMethodMarket OrderMethod = "market"
)

type OrderMethodParamIFD

type OrderMethodParamIFD struct {
	IFD  Order
	Then Order
}

OrderMethodParamIFDOCO defines the parameter for IFDOCO order

type OrderMethodParamIFDOCO

type OrderMethodParamIFDOCO struct {
	IFD Order
	OCO []Order
}

OrderMethodParamIFDOCO defines the parameter for IFDOCO order

type OrderStructure

type OrderStructure string
const (
	OrderStructureParentOrder OrderStructure = "parent_order"
	OrderStructureChildOrder  OrderStructure = "child_order"
)

type Side

type Side string
const (
	SideLong  Side = "long"
	SideShort Side = "short"
)

type Signal

type Signal struct {

	// Src is the source of the signal. E.g. TradingView
	Src string

	// ID is a unique signal ID
	ID string

	// Px is the target price of the strategy
	Px string

	// Strategy is a grouping identifier for the strategy. E.g. my-strategy
	Strategy string

	// Side is either LONG or SHORT
	Side Side

	// Symbol is the symbol to trade
	Symbol string

	// Exchange is the exchange to send the order to
	Exchange Exchange

	// Extra is an additional parameter
	Extra string

	// Generated is the generated timestamp of the strategy signal
	Generated time.Time

	// PrevSignalID is a previous signal ID
	PrevSignalID string

	// Status is the signal status
	Status SignalStatus

	// TargetAvgEntryPx is the target avg entry px
	TargetAvgEntryPx string

	// TargetStopLossPx is the target stop loss px
	TargetStopLossPx string

	// TargetTakeProfitPx is the target take profit px
	TargetTakeProfitPx string

	// FilledEntryPx is the actual filled avg entry px
	FilledEntryPx string

	// FilledExitPx is the actual filled exit px
	FilledExitPx string

	// FilledQty is the actual filled qty
	FilledQty string

	// CancelCompleteOrdID is the cancel completed request's order IDs
	CancelCompleteOrdID map[string]bool

	// ClosePositionOrdID is the close position's order IDs
	ClosePositionOrdID map[string]bool
}

Signal is a generated instruction on what to trade

func NewSignalFromTradingView

func NewSignalFromTradingView(s string) (*Signal, error)

NewSignalFromTradingView generates signal from tradingview alert

func (Signal) IsAllCancelComplete

func (s Signal) IsAllCancelComplete() bool

IsAllCancelComplete returns true if all cancel complete requests are acked

func (Signal) IsAllClosePositionComplete

func (s Signal) IsAllClosePositionComplete() bool

IsAllClosePositionComplete returns true if all close position requests are acked

func (*Signal) Validate

func (s *Signal) Validate() error

Validate validates whether the signal is complete

type SignalStatus

type SignalStatus string
const (
	SignalStateDraft                      SignalStatus = "DRAFT"
	SignalStateOpen                       SignalStatus = "OPEN"
	SignalStateCloseInit                  SignalStatus = "CLOSE_INIT"
	SignalStateCloseWaitingOrderCancel    SignalStatus = "CLOSE_WAITING_ORDER_CANCEL"
	SignalStateCloseWaitingPositionCancel SignalStatus = "CLOSE_WAITING_POSITION_CLOSE"
	SignalStateCloseComplete              SignalStatus = "CLOSE_WAITING_POSITION_CLOSE"
)

type TimeInForce

type TimeInForce string
const (
	TimeInForceGTC TimeInForce = "gtc"
	TimeInForceFOC TimeInForce = "foc"
)

Jump to

Keyboard shortcuts

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