exchanges

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

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

Go to latest
Published: Dec 2, 2023 License: MIT Imports: 15 Imported by: 0

README

Exchanges

Development requirements

go get github.com/golang/mock/mockgen
go install github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest
go install github.com/russross/blackfriday-tool@latest

Notes

For Binance/Long we use GTC+Limit orders

Documentation for utils are stored in utils/doc.md and utils/doc.html.

Useful commands

bash generate.sh
websocat 'wss://stream.binance.com:9443/ws/!miniTicker@arr'

go get github.com/princjef/gomarkdoc/cmd/gomarkdoc # for Markdown documentation generation
go get github.com/russross/blackfriday-tool # for Markdown to HTML conversion

bash -c "while [ 1 ]; do ./show_data orders -symbol='LTCUSDT' -from-day='21-01-26'; sleep 5; done"
bash -c "while [ 1 ]; do ./show_data wsprice -symbol='LTCUSDT'; sleep 2; done"
bash -c "while [ 1 ]; do ./show_data wsorders -symbol='LTCUSDT'; sleep 2; done"
bash -c "while [ 1 ]; do ./show_data position; sleep 2; done"
bash -c "while [ 1 ]; do ./show_data getsymbols; sleep 2; done"
bash -c "while [ 1 ]; do ./show_data account 2>&1 | grep -E 'USDT|LTC'; sleep 1; done"
bash -c "while [ 1 ]; do ./show_data account 2>&1; sleep 1; done"
bash -c "while [ 1 ]; do ./show_data createorder -symbol='ETHUSDT'; sleep 2; done"
bash -c "while [ 1 ]; do ./show_data cancel -symbol='ETHUSDT' -coid='PCR8OyZ6qOTgqPldZgqQBL'; sleep 2; done"

websocat 'wss://stream.binance.com:9443/ws/ltcusdt@miniTicker' | jq "{s:.s,price:.c}"

./show_data cancel -symbol=LTCUSDT -coid="RUN200-573f0701"

Documentation

Overview

Package exchanges is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var NewOrderRejectedError = errors.New("new order was rejected")
View Source
var OrderExecutedError = errors.New("order was executed")
View Source
var OrderNotFoundError = errors.New("order not found")

Functions

func RevPrice

func RevPrice(p *apd.Decimal) *apd.Decimal

Types

type Account

type Account struct {
	AccountBalances  []AccountBalance
	AccountPositions []AccountPosition
}

type AccountBalance

type AccountBalance struct {
	Coin   string
	Free   *apd.Decimal
	Locked *apd.Decimal
}

type AccountPosition

type AccountPosition struct {
	Symbol           string
	UnrealizedProfit *apd.Decimal
	Leverage         *apd.Decimal
	EntryPrice       *apd.Decimal
	Size             *apd.Decimal
	MarkPrice        *apd.Decimal
	PositionValue    *apd.Decimal
	Side             string
	CumRealisedPnl   *apd.Decimal
	LiqPrice         *apd.Decimal
	Category         string
}

type BulkCancelExchange

type BulkCancelExchange interface {
	// can return `OrderExecutedError` in case of executed order.
	// can return `OrderNotFoundError` in case of not found order.
	BulkCancelOrder(symbol string, ids []string) ([]BulkCancelResult, error)
}

type BulkCancelResult

type BulkCancelResult struct {
	ID  string
	Err error
}

type Exchange

type Exchange interface {
	GetPrefix() string
	GetName() string

	RoundPrice(_ context.Context, symbol string, price *apd.Decimal, tickSize *string) (*apd.Decimal, error)
	RoundQuantity(_ context.Context, symbol string, qty *apd.Decimal) (*apd.Decimal, error)

	// This method should use `clientOrderID` if it's possible
	PlaceBuyOrder(
		_ context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, clientOrderID string,
	) (id string, e error)

	// This method should use `clientOrderID` if it's possible
	PlaceSellOrder(
		_ context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, clientOrderID string,
	) (id string, e error)

	// can return `OrderExecutedError` in case of executed order.
	// can return `OrderNotFoundError` in case of not found order.
	// It's important to have Canceled state if no error returned
	// !Always release order after cancellation
	CancelOrder(_ context.Context, symbol, id string) error

	// Order should be released after cancellation
	ReleaseOrder(_ context.Context, symbol, id string) error

	GetPrice(_ context.Context, symbol string) (*apd.Decimal, error)

	// `createdAt` can be omitted. But some exchanges can require it
	GetOrderInfo(_ context.Context, symbol, id string, createdAt *time.Time) (OrderInfo, error)
	GetOrderInfoByClientOrderID(_ context.Context, symbol, clientOrderID string, createdAt *time.Time) (OrderInfo, error)

	GetTradableSymbols(context.Context) ([]SymbolInfo, error)

	// Returns control immediately
	// If error is sent then channel will be closed automatically
	// Channel will be closed in two ways: by context and by disconnection
	WatchOrdersStatuses(context.Context) (<-chan OrderEvent, error)

	// Returns control immediately
	// If error is sent then channel will be closed automatically
	// Channel will be closed in two ways: by context and by disconnection
	WatchSymbolPrice(_ context.Context, symbol string) (<-chan PriceEvent, error)

	PlaceBuyOrderV2(
		_ context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, clientOrderID string, orderType string,
	) (id string, e error)

	PlaceSellOrderV2(
		_ context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, clientOrderID string, orderType string,
	) (id string, e error)

	WatchAccountPositions(context.Context) (<-chan PositionEvent, error)

	GetOpenOrders(context.Context) ([]OrderDetailInfo, error)

	GetOrders(ctx context.Context, filter OrderFilter) ([]OrderDetailInfo, error)

	GetAccount(context.Context) (Account, error)

	GenerateClientOrderID(ctx context.Context, identifierID string) (string, error)
}

`id` of orders placing result should be consistent (accept/return) with other methods.

The Exchange is responsible for all tryings to reconnect to WebSockets, the implementation should try the best to make connection reliable, but if for several retries it can't connect it should send error without closing the channel. Call an Unwatch method is not required in this case.

type MockBulkCancelExchange

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

MockBulkCancelExchange is a mock of BulkCancelExchange interface.

func NewMockBulkCancelExchange

func NewMockBulkCancelExchange(ctrl *gomock.Controller) *MockBulkCancelExchange

NewMockBulkCancelExchange creates a new mock instance.

func (*MockBulkCancelExchange) BulkCancelOrder

func (m *MockBulkCancelExchange) BulkCancelOrder(symbol string, ids []string) ([]BulkCancelResult, error)

BulkCancelOrder mocks base method.

func (*MockBulkCancelExchange) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

type MockBulkCancelExchangeMockRecorder

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

MockBulkCancelExchangeMockRecorder is the mock recorder for MockBulkCancelExchange.

func (*MockBulkCancelExchangeMockRecorder) BulkCancelOrder

func (mr *MockBulkCancelExchangeMockRecorder) BulkCancelOrder(symbol, ids interface{}) *gomock.Call

BulkCancelOrder indicates an expected call of BulkCancelOrder.

type MockExchange

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

MockExchange is a mock of Exchange interface.

func NewMockExchange

func NewMockExchange(ctrl *gomock.Controller) *MockExchange

NewMockExchange creates a new mock instance.

func (*MockExchange) CancelOrder

func (m *MockExchange) CancelOrder(arg0 context.Context, symbol, id string) error

CancelOrder mocks base method.

func (*MockExchange) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockExchange) GenerateClientOrderID

func (m *MockExchange) GenerateClientOrderID(ctx context.Context, identifierID string) (string, error)

GenerateClientOrderID mocks base method.

func (*MockExchange) GetAccount

func (m *MockExchange) GetAccount(arg0 context.Context) (Account, error)

GetAccount mocks base method.

func (*MockExchange) GetName

func (m *MockExchange) GetName() string

GetName mocks base method.

func (*MockExchange) GetOpenOrders

func (m *MockExchange) GetOpenOrders(arg0 context.Context) ([]OrderDetailInfo, error)

GetOpenOrders mocks base method.

func (*MockExchange) GetOrderInfo

func (m *MockExchange) GetOrderInfo(arg0 context.Context, symbol, id string, createdAt *time.Time) (OrderInfo, error)

GetOrderInfo mocks base method.

func (*MockExchange) GetOrderInfoByClientOrderID

func (m *MockExchange) GetOrderInfoByClientOrderID(arg0 context.Context, symbol, clientOrderID string, createdAt *time.Time) (OrderInfo, error)

GetOrderInfoByClientOrderID mocks base method.

func (*MockExchange) GetOrders

func (m *MockExchange) GetOrders(ctx context.Context, filter OrderFilter) ([]OrderDetailInfo, error)

GetOrders mocks base method.

func (*MockExchange) GetPrefix

func (m *MockExchange) GetPrefix() string

GetPrefix mocks base method.

func (*MockExchange) GetPrice

func (m *MockExchange) GetPrice(arg0 context.Context, symbol string) (*apd.Decimal, error)

GetPrice mocks base method.

func (*MockExchange) GetTradableSymbols

func (m *MockExchange) GetTradableSymbols(arg0 context.Context) ([]SymbolInfo, error)

GetTradableSymbols mocks base method.

func (*MockExchange) PlaceBuyOrder

func (m *MockExchange) PlaceBuyOrder(arg0 context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, clientOrderID string) (string, error)

PlaceBuyOrder mocks base method.

func (*MockExchange) PlaceBuyOrderV2

func (m *MockExchange) PlaceBuyOrderV2(arg0 context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, clientOrderID, orderType string) (string, error)

PlaceBuyOrderV2 mocks base method.

func (*MockExchange) PlaceSellOrder

func (m *MockExchange) PlaceSellOrder(arg0 context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, clientOrderID string) (string, error)

PlaceSellOrder mocks base method.

func (*MockExchange) PlaceSellOrderV2

func (m *MockExchange) PlaceSellOrderV2(arg0 context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, clientOrderID, orderType string) (string, error)

PlaceSellOrderV2 mocks base method.

func (*MockExchange) ReleaseOrder

func (m *MockExchange) ReleaseOrder(arg0 context.Context, symbol, id string) error

ReleaseOrder mocks base method.

func (*MockExchange) RoundPrice

func (m *MockExchange) RoundPrice(arg0 context.Context, symbol string, price *apd.Decimal, tickSize *string) (*apd.Decimal, error)

RoundPrice mocks base method.

func (*MockExchange) RoundQuantity

func (m *MockExchange) RoundQuantity(arg0 context.Context, symbol string, qty *apd.Decimal) (*apd.Decimal, error)

RoundQuantity mocks base method.

func (*MockExchange) WatchAccountPositions

func (m *MockExchange) WatchAccountPositions(arg0 context.Context) (<-chan PositionEvent, error)

WatchAccountPositions mocks base method.

func (*MockExchange) WatchOrdersStatuses

func (m *MockExchange) WatchOrdersStatuses(arg0 context.Context) (<-chan OrderEvent, error)

WatchOrdersStatuses mocks base method.

func (*MockExchange) WatchSymbolPrice

func (m *MockExchange) WatchSymbolPrice(arg0 context.Context, symbol string) (<-chan PriceEvent, error)

WatchSymbolPrice mocks base method.

type MockExchangeMockRecorder

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

MockExchangeMockRecorder is the mock recorder for MockExchange.

func (*MockExchangeMockRecorder) CancelOrder

func (mr *MockExchangeMockRecorder) CancelOrder(arg0, symbol, id interface{}) *gomock.Call

CancelOrder indicates an expected call of CancelOrder.

func (*MockExchangeMockRecorder) GenerateClientOrderID

func (mr *MockExchangeMockRecorder) GenerateClientOrderID(ctx, identifierID interface{}) *gomock.Call

GenerateClientOrderID indicates an expected call of GenerateClientOrderID.

func (*MockExchangeMockRecorder) GetAccount

func (mr *MockExchangeMockRecorder) GetAccount(arg0 interface{}) *gomock.Call

GetAccount indicates an expected call of GetAccount.

func (*MockExchangeMockRecorder) GetName

func (mr *MockExchangeMockRecorder) GetName() *gomock.Call

GetName indicates an expected call of GetName.

func (*MockExchangeMockRecorder) GetOpenOrders

func (mr *MockExchangeMockRecorder) GetOpenOrders(arg0 interface{}) *gomock.Call

GetOpenOrders indicates an expected call of GetOpenOrders.

func (*MockExchangeMockRecorder) GetOrderInfo

func (mr *MockExchangeMockRecorder) GetOrderInfo(arg0, symbol, id, createdAt interface{}) *gomock.Call

GetOrderInfo indicates an expected call of GetOrderInfo.

func (*MockExchangeMockRecorder) GetOrderInfoByClientOrderID

func (mr *MockExchangeMockRecorder) GetOrderInfoByClientOrderID(arg0, symbol, clientOrderID, createdAt interface{}) *gomock.Call

GetOrderInfoByClientOrderID indicates an expected call of GetOrderInfoByClientOrderID.

func (*MockExchangeMockRecorder) GetOrders

func (mr *MockExchangeMockRecorder) GetOrders(ctx, filter interface{}) *gomock.Call

GetOrders indicates an expected call of GetOrders.

func (*MockExchangeMockRecorder) GetPrefix

func (mr *MockExchangeMockRecorder) GetPrefix() *gomock.Call

GetPrefix indicates an expected call of GetPrefix.

func (*MockExchangeMockRecorder) GetPrice

func (mr *MockExchangeMockRecorder) GetPrice(arg0, symbol interface{}) *gomock.Call

GetPrice indicates an expected call of GetPrice.

func (*MockExchangeMockRecorder) GetTradableSymbols

func (mr *MockExchangeMockRecorder) GetTradableSymbols(arg0 interface{}) *gomock.Call

GetTradableSymbols indicates an expected call of GetTradableSymbols.

func (*MockExchangeMockRecorder) PlaceBuyOrder

func (mr *MockExchangeMockRecorder) PlaceBuyOrder(arg0, isRetry, symbol, price, qty, clientOrderID interface{}) *gomock.Call

PlaceBuyOrder indicates an expected call of PlaceBuyOrder.

func (*MockExchangeMockRecorder) PlaceBuyOrderV2

func (mr *MockExchangeMockRecorder) PlaceBuyOrderV2(arg0, isRetry, symbol, price, qty, clientOrderID, orderType interface{}) *gomock.Call

PlaceBuyOrderV2 indicates an expected call of PlaceBuyOrderV2.

func (*MockExchangeMockRecorder) PlaceSellOrder

func (mr *MockExchangeMockRecorder) PlaceSellOrder(arg0, isRetry, symbol, price, qty, clientOrderID interface{}) *gomock.Call

PlaceSellOrder indicates an expected call of PlaceSellOrder.

func (*MockExchangeMockRecorder) PlaceSellOrderV2

func (mr *MockExchangeMockRecorder) PlaceSellOrderV2(arg0, isRetry, symbol, price, qty, clientOrderID, orderType interface{}) *gomock.Call

PlaceSellOrderV2 indicates an expected call of PlaceSellOrderV2.

func (*MockExchangeMockRecorder) ReleaseOrder

func (mr *MockExchangeMockRecorder) ReleaseOrder(arg0, symbol, id interface{}) *gomock.Call

ReleaseOrder indicates an expected call of ReleaseOrder.

func (*MockExchangeMockRecorder) RoundPrice

func (mr *MockExchangeMockRecorder) RoundPrice(arg0, symbol, price, tickSize interface{}) *gomock.Call

RoundPrice indicates an expected call of RoundPrice.

func (*MockExchangeMockRecorder) RoundQuantity

func (mr *MockExchangeMockRecorder) RoundQuantity(arg0, symbol, qty interface{}) *gomock.Call

RoundQuantity indicates an expected call of RoundQuantity.

func (*MockExchangeMockRecorder) WatchAccountPositions

func (mr *MockExchangeMockRecorder) WatchAccountPositions(arg0 interface{}) *gomock.Call

WatchAccountPositions indicates an expected call of WatchAccountPositions.

func (*MockExchangeMockRecorder) WatchOrdersStatuses

func (mr *MockExchangeMockRecorder) WatchOrdersStatuses(arg0 interface{}) *gomock.Call

WatchOrdersStatuses indicates an expected call of WatchOrdersStatuses.

func (*MockExchangeMockRecorder) WatchSymbolPrice

func (mr *MockExchangeMockRecorder) WatchSymbolPrice(arg0, symbol interface{}) *gomock.Call

WatchSymbolPrice indicates an expected call of WatchSymbolPrice.

type OrderDetailInfo

type OrderDetailInfo struct {
	Symbol        string
	ID            string
	ClientOrderID *string
	Price         *apd.Decimal
	Quantity      *apd.Decimal
	ExecutedQty   *apd.Decimal
	Status        OrderStatusType
	OrderType     *OrderType
	Time          int64
	OrderSide     OrderSide
	TimeInForce   *OrderTimeInForce
	StopPrice     *apd.Decimal
	QuoteQuantity *apd.Decimal
}

type OrderEvent

type OrderEvent struct {
	DisconnectedWithErr error
	Reconnected         *struct{}
	Payload             *OrderEventPayload
}

Should be one of three In case of first connection no reconnection event should be sent

func (OrderEvent) String

func (ev OrderEvent) String() string

type OrderEventPayload

type OrderEventPayload struct {
	OrderID     string
	OrderStatus OrderStatusType
	Symbol      *string // Now it is optional. But it's better to fill it if possible
}

func (*OrderEventPayload) String

func (oep *OrderEventPayload) String() string

type OrderEventReconnector

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

func NewOrderEventReconnector

func NewOrderEventReconnector(
	connect OrderEventReconnectorFn, reconnectOpts []retry.Option, l *zap.Logger,
) *OrderEventReconnector

func (*OrderEventReconnector) Watch

func (r *OrderEventReconnector) Watch(
	ctx context.Context,
) (<-chan OrderEvent, error)

type OrderEventReconnectorFn

type OrderEventReconnectorFn func(context.Context) (<-chan OrderEvent, error)

type OrderFilter

type OrderFilter struct {
	Symbol        *string
	OrderID       *string
	ClientOrderID *string
}

type OrderInfo

type OrderInfo struct {
	ID            string
	ClientOrderID *string // optional
	Status        OrderStatusType
}

func (OrderInfo) String

func (oi OrderInfo) String() string

type OrderSide

type OrderSide string
const (
	BUY                OrderSide = "BUY"
	SELL               OrderSide = "SELL"
	UNKNOWN_ORDER_SIDE OrderSide = "UNKNOWN_ORDER_SIDE"
)

type OrderStatusType

type OrderStatusType int
const (
	UnknownOST         OrderStatusType = 0
	NewOST             OrderStatusType = 1 // NEW - The order has been accepted by the engine.
	PartiallyFilledOST OrderStatusType = 2 // PARTIALLY_FILLED - A part of the order has been filled.
	FilledOST          OrderStatusType = 3 // FILLED - The order has been completely filled.
	CanceledOST        OrderStatusType = 4 // CANCELED - The order has been canceled by the user.
	// PENDING_CANCEL (currently unused)
	RejectedOST OrderStatusType = 5 // REJECTED - The order was not accepted by the engine and not processed.
	ExpiredOST  OrderStatusType = 6 // EXPIRED - The order was canceled according to the order type's rules (e.g. LIMIT FOK orders with no fill, LIMIT IOC or MARKET orders that partially fill) or by the exchange, (e.g. orders canceled during liquidation, orders canceled during maintenance)
	OpenOST     OrderStatusType = 7 // OPEN status for FTX exchange
	ClosedOST   OrderStatusType = 8 // Closed status for FTX exchange
)

Defenition from Binance

func (OrderStatusType) IsFinalStatus

func (ost OrderStatusType) IsFinalStatus() bool

func (OrderStatusType) String

func (ost OrderStatusType) String() string

type OrderTimeInForce

type OrderTimeInForce string
const (
	GTC_TIME_IN_FORCE                 OrderTimeInForce = "GTC"
	IOC_TIME_IN_FORCE                 OrderTimeInForce = "IOC"
	FOK_TIME_IN_FORCE                 OrderTimeInForce = "FOK"
	DAY_TIME_IN_FORCE                 OrderTimeInForce = "DAY"
	GOOD_TILL_CANCEL_TIME_IN_FORCE    OrderTimeInForce = "GOOD_TILL_CANCEL"
	IMMEDIATE_OR_CANCEL_TIME_IN_FORCE OrderTimeInForce = "IMMEDIATE_OR_CANCEL"
	FILL_OR_KILL_TIME_IN_FORCE        OrderTimeInForce = "FILL_OR_KILL"
)

type OrderType

type OrderType string
const (
	LIMIT             OrderType = "LIMIT"
	MARKET            OrderType = "MARKET"
	LIMIT_MAKER       OrderType = "LIMIT_MAKER"
	STOP_LOSS         OrderType = "STOP_LOSS"
	STOP_LOSS_LIMIT   OrderType = "STOP_LOSS_LIMIT"
	TAKE_PROFIT       OrderType = "TAKE_PROFIT"
	TAKE_PROFIT_LIMIT OrderType = "TAKE_PROFIT_LIMIT"
	MARKET_IF_TOUCHED OrderType = "MARKET_IF_TOUCHED"
	LIMIT_IF_TOUCHED  OrderType = "LIMIT_IF_TOUCHED"
	PEGGED            OrderType = "PEGGED"
)

type PayloadType

type PayloadType generic.Type

type PositionEvent

type PositionEvent struct {
	DisconnectedWithErr error
	Reconnected         *struct{}
	Payload             []*PositionPayload
}

type PositionPayload

type PositionPayload struct {
	Value  *apd.Decimal
	Symbol string
}

type PriceEvent

type PriceEvent struct {
	DisconnectedWithErr error
	Reconnected         *struct{}
	Payload             *apd.Decimal
}

Should be one of three In case of first connection no reconnection event should be sent

func (PriceEvent) String

func (ev PriceEvent) String() string

type PriceEventReconnector

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

func NewPriceEventReconnector

func NewPriceEventReconnector(
	connect PriceEventReconnectorFn, reconnectOpts []retry.Option, l *zap.Logger,
) *PriceEventReconnector

func (*PriceEventReconnector) Watch

func (r *PriceEventReconnector) Watch(
	ctx context.Context,
) (<-chan PriceEvent, error)

type PriceEventReconnectorFn

type PriceEventReconnectorFn func(context.Context) (<-chan PriceEvent, error)

type RetryeableExchange

type RetryeableExchange struct {
	Target             Exchange
	RetryOptions       []retry.Option // optional
	CancelRetryOptions []retry.Option // optional
	Logger             *zap.Logger
}

All methods are retryeable except of watch/unwatch methods TODO: all methods shouldn't think result of `NotFound` error (or similar erorrs) should be retryed

func (*RetryeableExchange) CancelOrder

func (re *RetryeableExchange) CancelOrder(ctx context.Context, symbol, id string) error

func (*RetryeableExchange) GenerateClientOrderID

func (re *RetryeableExchange) GenerateClientOrderID(ctx context.Context, identifierID string) (string, error)

func (*RetryeableExchange) GetAccount

func (re *RetryeableExchange) GetAccount(ctx context.Context) (res Account, e error)

func (*RetryeableExchange) GetName

func (re *RetryeableExchange) GetName() string

func (*RetryeableExchange) GetOpenOrders

func (re *RetryeableExchange) GetOpenOrders(ctx context.Context) (res []OrderDetailInfo, e error)

func (*RetryeableExchange) GetOrderInfo

func (re *RetryeableExchange) GetOrderInfo(ctx context.Context, symbol, id string, createdAt *time.Time) (info OrderInfo, e error)

func (*RetryeableExchange) GetOrderInfoByClientOrderID

func (re *RetryeableExchange) GetOrderInfoByClientOrderID(ctx context.Context, symbol, clientOrderID string, createdAt *time.Time) (info OrderInfo, e error)

func (*RetryeableExchange) GetOrders

func (re *RetryeableExchange) GetOrders(ctx context.Context, filter OrderFilter) (res []OrderDetailInfo, e error)

func (*RetryeableExchange) GetPrefix

func (re *RetryeableExchange) GetPrefix() string

func (*RetryeableExchange) GetPrice

func (re *RetryeableExchange) GetPrice(ctx context.Context, symbol string) (price *apd.Decimal, e error)

func (*RetryeableExchange) GetTradableSymbols

func (re *RetryeableExchange) GetTradableSymbols(ctx context.Context) (info []SymbolInfo, e error)

func (*RetryeableExchange) PlaceBuyOrder

func (re *RetryeableExchange) PlaceBuyOrder(ctx context.Context,
	isRetry bool, symbol string, price, quantity *apd.Decimal, prefferedID string) (id string, e error)

func (*RetryeableExchange) PlaceBuyOrderV2

func (re *RetryeableExchange) PlaceBuyOrderV2(ctx context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, clientOrderID string, orderType string) (id string, e error)

func (*RetryeableExchange) PlaceSellOrder

func (re *RetryeableExchange) PlaceSellOrder(ctx context.Context,
	isRetry bool, symbol string, price, quantity *apd.Decimal, prefferedID string,
) (id string, e error)

func (*RetryeableExchange) PlaceSellOrderV2

func (re *RetryeableExchange) PlaceSellOrderV2(ctx context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, clientOrderID string, orderType string) (id string, e error)

func (*RetryeableExchange) ReleaseOrder

func (re *RetryeableExchange) ReleaseOrder(ctx context.Context, symbol, id string) error

func (*RetryeableExchange) RoundPrice

func (re *RetryeableExchange) RoundPrice(ctx context.Context, symbol string, price *apd.Decimal, tickSize *string) (result *apd.Decimal, e error)

func (*RetryeableExchange) RoundQuantity

func (re *RetryeableExchange) RoundQuantity(ctx context.Context, symbol string, quantity *apd.Decimal) (result *apd.Decimal, e error)

func (*RetryeableExchange) WatchAccountPositions

func (re *RetryeableExchange) WatchAccountPositions(ctx context.Context) (<-chan PositionEvent, error)

func (*RetryeableExchange) WatchOrdersStatuses

func (re *RetryeableExchange) WatchOrdersStatuses(ctx context.Context) (<-chan OrderEvent, error)

func (*RetryeableExchange) WatchSymbolPrice

func (re *RetryeableExchange) WatchSymbolPrice(ctx context.Context, symbol string) (<-chan PriceEvent, error)

type ReversedExchange

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

func NewReversedExchange

func NewReversedExchange(target Exchange, lg *zap.Logger) *ReversedExchange

func (*ReversedExchange) CancelOrder

func (re *ReversedExchange) CancelOrder(ctx context.Context, symbol, id string) error

func (*ReversedExchange) GetOrderInfo

func (re *ReversedExchange) GetOrderInfo(ctx context.Context, symbol, id string, createdAt *time.Time) (OrderInfo, error)

func (*ReversedExchange) GetOrderInfoByClientOrderID

func (re *ReversedExchange) GetOrderInfoByClientOrderID(
	ctx context.Context, symbol, clientOrderID string, createdAt *time.Time,
) (OrderInfo, error)

func (*ReversedExchange) GetPrice

func (re *ReversedExchange) GetPrice(ctx context.Context, symbol string) (*apd.Decimal, error)

func (*ReversedExchange) GetTradableSymbols

func (re *ReversedExchange) GetTradableSymbols(ctx context.Context) ([]SymbolInfo, error)

func (*ReversedExchange) PlaceBuyOrder

func (re *ReversedExchange) PlaceBuyOrder(
	ctx context.Context, isRetry bool, symbol string, price, quantity *apd.Decimal, prefferedID string,
) (id string, e error)

func (*ReversedExchange) PlaceSellOrder

func (re *ReversedExchange) PlaceSellOrder(
	ctx context.Context, isRetry bool, symbol string, price, quantity *apd.Decimal, prefferedID string,
) (id string, e error)

func (*ReversedExchange) WatchOrdersStatuses

func (re *ReversedExchange) WatchOrdersStatuses(
	ctx context.Context,
) (<-chan OrderEvent, error)

func (*ReversedExchange) WatchSymbolPrice

func (re *ReversedExchange) WatchSymbolPrice(
	ctx context.Context, symbol string,
) (<-chan PriceEvent, error)

type SequentialBulkCancelExchange

type SequentialBulkCancelExchange struct {
	Exchange
}

func (*SequentialBulkCancelExchange) BulkCancelOrder

func (this *SequentialBulkCancelExchange) BulkCancelOrder(
	ctx context.Context, symbol string, ids []string,
) ([]BulkCancelResult, error)

type SymbolInfo

type SymbolInfo struct {
	DisplayName    string // "BN-LTCBTC (LTC margin)"
	OriginalSymbol string // "LTC_BTC"
	Symbol         string // "BN-LTCBTC"
	Filters        []map[string]interface{}
}

type TypeEvent

type TypeEvent struct {
	DisconnectedWithErr error
	Reconnected         *struct{}
	Payload             *PayloadType
}

Should be one of three In case of first connection no reconnection event should be sent

type TypeEventReconnector

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

func NewTypeEventReconnector

func NewTypeEventReconnector(
	connect TypeEventReconnectorFn, reconnectOpts []retry.Option, l *zap.Logger,
) *TypeEventReconnector

func (*TypeEventReconnector) Watch

func (r *TypeEventReconnector) Watch(
	ctx context.Context,
) (<-chan TypeEvent, error)

type TypeEventReconnectorFn

type TypeEventReconnectorFn func(context.Context) (<-chan TypeEvent, error)

Jump to

Keyboard shortcuts

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