trading

package
v0.0.0-...-8690533 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePushConnection

func CreatePushConnection(addr, publicKey string, token string, logger *zap.Logger) (*zmqPushConnection, error)

CreatePushConnection create connection, connect, handle status and run send handles

func StartNewClient

func StartNewClient(logger *zap.Logger, push pushConnecter, xsub xsubConnecter) *zmqTrader

StartNewClient create trading trader and init it

Types

type ClientOrderId

type ClientOrderId [32]byte

func ClientOrderIdGenerate

func ClientOrderIdGenerate() ClientOrderId

func ClientOrderIdGenerateFast

func ClientOrderIdGenerateFast(id int) ClientOrderId

func ClientOrderIdStrToType

func ClientOrderIdStrToType(val string) (ClientOrderId, error)

func (ClientOrderId) MarshalJSON

func (co ClientOrderId) MarshalJSON() ([]byte, error)

func (ClientOrderId) String

func (co ClientOrderId) String() string

func (*ClientOrderId) UnmarshalJSON

func (co *ClientOrderId) UnmarshalJSON(data []byte) error

type ErrorResponse

type ErrorResponse uint8
const (
	ErrorUnknown ErrorResponse = iota
	ErrorDuplicateClientOrder
	ErrorNotFoundOrder
	ErrorExceedsLimit
	ErrorNotChanged
	ErrorBadQuantity
	ErrorBadPrice
	ErrorTradingNotStarted
	ErrorNoExpireTime
	ErrorTooLateToEnter
)

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

type MockTrader

type MockTrader struct {
	// contains filtered or unexported fields
}

func NewMockTrader

func NewMockTrader(logger *zap.Logger) *MockTrader

func (*MockTrader) CancelOrder

func (m *MockTrader) CancelOrder(ctx context.Context, userID uint64, clientOrderID ClientOrderId) (*OrderReport, error)

func (*MockTrader) GetOrder

func (m *MockTrader) GetOrder(ctx context.Context, userID uint64, clientOrderID ClientOrderId) (*OrderModel, error)

func (*MockTrader) GetSnapshot

func (m *MockTrader) GetSnapshot(ctx context.Context, userID uint64) ([]OrderModel, error)

func (*MockTrader) IsReady

func (m *MockTrader) IsReady() bool

func (*MockTrader) NewOrder

func (m *MockTrader) NewOrder(ctx context.Context, userID uint64, order *RequestOrderNew) (*OrderReport, []Trade, error)

func (*MockTrader) Ready

func (m *MockTrader) Ready() chan bool

func (*MockTrader) ReplaceOrder

func (m *MockTrader) ReplaceOrder(ctx context.Context, userID uint64, req RequestOrderReplace) (*OrderReport, error)

func (*MockTrader) SetReady

func (m *MockTrader) SetReady(val bool)

func (*MockTrader) SetupFixtures

func (m *MockTrader) SetupFixtures()

func (*MockTrader) StartHttpServer

func (m *MockTrader) StartHttpServer(addr string)

func (*MockTrader) Unsubscribe

func (m *MockTrader) Unsubscribe(userID uint64)

type OrderModel

type OrderModel struct {
	OrderID        uint64
	LatestOrderID  uint64
	ClientOrderID  ClientOrderId
	Type           OrderType
	TimeInForce    OrderTimeInForce
	Side           OrderSide
	OrderStatus    OrderStatus
	PostOnly       bool
	Symbol         string
	Price          string
	StopPrice      string
	ExpireTime     uint64
	Quantity       string
	LastQuantity   uint64
	LastPrice      string
	LeavesQuantity uint64
	CumQuantity    string
	AveragePrice   string
	Created        uint64
	Timestamp      uint64
}

type OrderReport

type OrderReport struct {
	OrderModel
	ReportType            ReportType
	OriginalClientOrderID ClientOrderId
	Timestamp             uint64
	TradeID               uint64
	FeeAmount             string
	FeeInstrument         string
}

type OrderSide

type OrderSide uint8
const (
	OrderSideSell OrderSide = iota
	OrderSideBuy
)

func OrderSideStrToType

func OrderSideStrToType(value string) (OrderSide, error)

func (OrderSide) MarshalJSON

func (ot OrderSide) MarshalJSON() ([]byte, error)

func (OrderSide) String

func (ot OrderSide) String() string

func (*OrderSide) UnmarshalJSON

func (ot *OrderSide) UnmarshalJSON(data []byte) error

type OrderStatus

type OrderStatus uint8
const (
	OrderStatusNew OrderStatus = iota
	OrderStatusSuspended
	OrderStatusPartiallyFilled
	OrderStatusFilled
	OrderStatusCanceled
	OrderStatusRejected
	OrderStatusExpired
)

func OrderStatusStrToType

func OrderStatusStrToType(value string) (OrderStatus, error)

func (OrderStatus) MarshalJSON

func (os OrderStatus) MarshalJSON() ([]byte, error)

func (OrderStatus) String

func (os OrderStatus) String() string

func (*OrderStatus) UnmarshalJSON

func (os *OrderStatus) UnmarshalJSON(data []byte) error

type OrderTimeInForce

type OrderTimeInForce uint8
const (
	OrderTimeInForceGTC OrderTimeInForce = iota // good till cancel. cancel only by user request of full filled
	OrderTimeInForceIOC                         // immediate or cancel. can be partially filled and then final status expired
	OrderTimeInForceFOK                         // fill or kill. fully filled or expired
	OrderTimeInForceDAY                         // Day. automatically expired at the end of the day (00 UTC)
	OrderTimeInForceGTD                         // good till date. automatically expired on a specified time

)

func OrderTimeInForceStrToType

func OrderTimeInForceStrToType(value string) (OrderTimeInForce, error)

func (OrderTimeInForce) MarshalJSON

func (tif OrderTimeInForce) MarshalJSON() ([]byte, error)

func (OrderTimeInForce) String

func (tif OrderTimeInForce) String() string

func (*OrderTimeInForce) UnmarshalJSON

func (tif *OrderTimeInForce) UnmarshalJSON(data []byte) error

type OrderType

type OrderType uint8
const (
	OrderTypeMarket OrderType = iota
	OrderTypeLimit
	OrderTypeStopMarket
	OrderTypeStopLimit
)

func OrderTypeStrToType

func OrderTypeStrToType(value string) (OrderType, error)

func (OrderType) MarshalJSON

func (ot OrderType) MarshalJSON() ([]byte, error)

func (OrderType) String

func (ot OrderType) String() string

func (*OrderType) UnmarshalJSON

func (ot *OrderType) UnmarshalJSON(data []byte) error

type ReportType

type ReportType uint8
const (
	ReportTypeNew ReportType = iota
	ReportTypeSuspended
	ReportTypeCanceled
	ReportTypeRejected
	ReportTypeExpired
	ReportTypeTrade
	ReportTypeStatus
	ReportTypeReplaced
)

func (ReportType) MarshalJSON

func (rt ReportType) MarshalJSON() ([]byte, error)

func (ReportType) String

func (rt ReportType) String() string

func (*ReportType) UnmarshalJSON

func (rt *ReportType) UnmarshalJSON(data []byte) error

type RequestOrderNew

type RequestOrderNew struct {
	ClientOrderID ClientOrderId    `json:"clientOrderId"`
	Type          OrderType        `json:"type"`
	Side          OrderSide        `json:"side"`
	TimeInForce   OrderTimeInForce `json:"timeInForce"`
	PostOnly      bool             `json:"participateDoNotInitiate"`
	Symbol        string           `json:"symbol"`
	Quantity      string           `json:"quantity"`
	Price         string           `json:"price,omitempty"`
	StopPrice     string           `json:"stopPrice,omitempty"`
	ExpireTime    uint64           `json:"expireTime,omitempty"`
	Login         string           `json:"login,omitempty"`
	WaitComplete  bool
}

type RequestOrderReplace

type RequestOrderReplace struct {
	ClientOrderID        ClientOrderId
	RequestClientOrderID ClientOrderId
	Quantity             string
	Price                string
}

type Trade

type Trade struct {
	ID            uint64
	Timestamp     uint64
	Quantity      uint64
	Price         string
	FeeAmount     string
	FeeInstrument string
}

type Trader

type Trader interface {
	Unsubscribe(userID uint64)
	GetSnapshot(ctx context.Context, userID uint64) ([]OrderModel, error)
	GetOrder(ctx context.Context, userID uint64, clientOrderID ClientOrderId) (*OrderModel, error)
	//NewOrder(ctx context.Context, userID uint64, order *RequestOrderNew) (*OrderReport, error)
	NewOrder(ctx context.Context, userID uint64, order *RequestOrderNew) (*OrderReport, []Trade, error)
	CancelOrder(ctx context.Context, userID uint64, clientOrderID ClientOrderId) (*OrderReport, error)
	ReplaceOrder(ctx context.Context, userID uint64, req RequestOrderReplace) (*OrderReport, error)
	IsReady() bool
	Ready() chan bool
}

func NewTrader

func NewTrader(logger *zap.Logger, dsn string) (Trader, error)

type UserWatcher

type UserWatcher struct {
	// contains filtered or unexported fields
}

func NewUserWatcher

func NewUserWatcher(trader Trader, duration time.Duration) *UserWatcher

func (*UserWatcher) Touch

func (w *UserWatcher) Touch(userID uint64)

Jump to

Keyboard shortcuts

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