Documentation ¶
Index ¶
- Constants
- Variables
- func InitScalesSubscriber(lg *zap.Logger)
- func InsertToOrdersFetcherMultimap(m map[SymbolClientOrderID]map[string]struct{}, key SymbolClientOrderID, ...)
- func IsAPINotFoundError(err error) bool
- func ScaleToDivider(scale int) (*apd.Decimal, error)
- func SubscribeToOrders(ctx context.Context, client *phemex.Client, lg *zap.Logger) (<-chan WSOrderEvent, error)
- func SubscribeToPositions(ctx context.Context, client *phemex.Client, lg *zap.Logger) (<-chan WSPositionEvent, error)
- func SubscribeToPrice(ctx context.Context, symbol string, lg *zap.Logger) (<-chan exchanges.PriceEvent, error)
- func TakeFirstValueOfStringSet(s map[string]struct{}) string
- func ToFullSymbol(phemexSymbol string) string
- func ToOrderType(orderType string) krisa_phemex_fork.OrderType
- func ToPhemexSymbol(symbol string) string
- type CombinedOrdersFetcher
- func (cof *CombinedOrdersFetcher) GetHistoryOrders(ctx context.Context, symbol string, orderID *string, clientOrderID *string) (res []exchanges.OrderDetailInfo, err error)
- func (cof *CombinedOrdersFetcher) GetOpenOrders(ctx context.Context) (res []exchanges.OrderDetailInfo, err error)
- func (cof *CombinedOrdersFetcher) GetOrderInfoByClientOrderID(ctx context.Context, symbol, clientOrderID string) (exchanges.OrderInfo, *orderResponse, error)
- func (cof *CombinedOrdersFetcher) GetOrderInfoByOrderID(ctx context.Context, symbol, id string) (exchanges.OrderInfo, *orderResponse, error)
- func (cof *CombinedOrdersFetcher) Start(ctx context.Context) error
- type OldOrdersFetcher
- func (of *OldOrdersFetcher) GetActiveOrders(symbol string) ([]*krisa_phemex_fork.OrderResponse, error)
- func (of *OldOrdersFetcher) GetOrderInfoByClientOrderID(ctx context.Context, symbol, clientOrderID string, createdAt *time.Time) (exchanges.OrderInfo, *krisa_phemex_fork.OrderResponse, error)
- func (of *OldOrdersFetcher) GetOrderInfoByOrderID(ctx context.Context, symbol, id string) (exchanges.OrderInfo, *krisa_phemex_fork.OrderResponse, error)
- type OrderCanceller
- type OrderPlacer
- func (op *OrderPlacer) CreateOrderRequest(symbol string, price, quantity *apd.Decimal, clientOrderID string, ...) (*orderFields, error)
- func (op *OrderPlacer) CreateOrderRequestV2(symbol string, price, quantity *apd.Decimal, clientOrderID string, ...) (*orderFields, error)
- func (op *OrderPlacer) PlaceOrder(ctx context.Context, isRetry bool, symbol string, price, quantity *apd.Decimal, ...) (id string, e error)
- func (op *OrderPlacer) PlaceOrderV2(ctx context.Context, isRetry bool, symbol string, price, quantity *apd.Decimal, ...) (id string, e error)
- type PhemexContract
- func (pc *PhemexContract) CancelOrder(ctx context.Context, symbol, id string) error
- func (b *PhemexContract) GenerateClientOrderID(ctx context.Context, identifierID string) (string, error)
- func (pc *PhemexContract) GetAccount(ctx context.Context) (exchanges.Account, error)
- func (pc *PhemexContract) GetName() string
- func (pc *PhemexContract) GetOpenOrders(ctx context.Context) ([]exchanges.OrderDetailInfo, error)
- func (pc *PhemexContract) GetOrderInfo(ctx context.Context, symbol, id string, createdAt *time.Time) (exchanges.OrderInfo, error)
- func (pc *PhemexContract) GetOrderInfoByClientOrderID(ctx context.Context, symbol, clientOrderID string, createdAt *time.Time) (exchanges.OrderInfo, error)
- func (pc *PhemexContract) GetOrders(ctx context.Context, filter exchanges.OrderFilter) (res []exchanges.OrderDetailInfo, err error)
- func (pc *PhemexContract) GetPrefix() string
- func (pc *PhemexContract) GetPrice(ctx context.Context, symbol string) (*apd.Decimal, error)
- func (pc *PhemexContract) GetTradableSymbols(ctx context.Context) ([]exchanges.SymbolInfo, error)
- func (pc *PhemexContract) PlaceBuyOrder(ctx context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, ...) (id string, e error)
- func (pc *PhemexContract) PlaceBuyOrderV2(ctx context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, ...) (id string, e error)
- func (pc *PhemexContract) PlaceSellOrder(ctx context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, ...) (id string, e error)
- func (pc *PhemexContract) PlaceSellOrderV2(ctx context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, ...) (id string, e error)
- func (pc *PhemexContract) ReleaseOrder(_ context.Context, symbol, id string) error
- func (pc *PhemexContract) RoundPrice(_ context.Context, symbol string, price *apd.Decimal, tickSize *string) (*apd.Decimal, error)
- func (pc *PhemexContract) RoundQuantity(_ context.Context, symbol string, quantity *apd.Decimal) (*apd.Decimal, error)
- func (pc *PhemexContract) StartBackgroundJob(ctx context.Context) error
- func (pc *PhemexContract) WatchAccountPositions(ctx context.Context) (<-chan exchanges.PositionEvent, error)
- func (pc *PhemexContract) WatchOrdersStatuses(ctx context.Context) (<-chan exchanges.OrderEvent, error)
- func (pc *PhemexContract) WatchSymbolPrice(ctx context.Context, symbol string) (<-chan exchanges.PriceEvent, error)
- type PhemexGroupRateLimiter
- type PhemexRateLimiter
- type PositionFetcher
- type PriceResponse
- type PriceResponseWrapper
- type PriceSubscriber
- type ScalesSubscriber
- type SymbolClientOrderID
- type SymbolOrderID
- type SymbolScale
- type WSMarket24Data
- type WSMarket24Msg
- type WSOrderEvent
- type WSOrdersCache
- type WSPositionEvent
Constants ¶
const OrderNotFoundCode = 10002 // OM_ORDER_NOT_FOUND
const PHEMEX_PREFIX = "PHEMEX-"
Variables ¶
var PhemexOrderClearedError = errors.New("phemex order was cleared")
Functions ¶
func InitScalesSubscriber ¶
func InsertToOrdersFetcherMultimap ¶
func InsertToOrdersFetcherMultimap(m map[SymbolClientOrderID]map[string]struct{}, key SymbolClientOrderID, value string)
func IsAPINotFoundError ¶
func SubscribeToOrders ¶
func SubscribeToPositions ¶
func SubscribeToPrice ¶
func SubscribeToPrice(ctx context.Context, symbol string, lg *zap.Logger) (<-chan exchanges.PriceEvent, error)
No reconnection in case of error Returns control after connect
func ToFullSymbol ¶
func ToOrderType ¶
func ToOrderType(orderType string) krisa_phemex_fork.OrderType
func ToPhemexSymbol ¶
Types ¶
type CombinedOrdersFetcher ¶
type CombinedOrdersFetcher struct {
// contains filtered or unexported fields
}
func NewCombinedOrdersFetcher ¶
func NewCombinedOrdersFetcher(client *phemex.Client, forkClient *krisa_phemex_fork.Client, lim *PhemexRateLimiter, logger *zap.Logger) *CombinedOrdersFetcher
func (*CombinedOrdersFetcher) GetHistoryOrders ¶
func (cof *CombinedOrdersFetcher) GetHistoryOrders( ctx context.Context, symbol string, orderID *string, clientOrderID *string, ) (res []exchanges.OrderDetailInfo, err error)
func (*CombinedOrdersFetcher) GetOpenOrders ¶
func (cof *CombinedOrdersFetcher) GetOpenOrders(ctx context.Context) (res []exchanges.OrderDetailInfo, err error)
func (*CombinedOrdersFetcher) GetOrderInfoByClientOrderID ¶
func (*CombinedOrdersFetcher) GetOrderInfoByOrderID ¶
type OldOrdersFetcher ¶
type OldOrdersFetcher struct {
// contains filtered or unexported fields
}
func NewOldOrdersFetcher ¶
func NewOldOrdersFetcher(apiKey, secretKey string, lg *zap.Logger) *OldOrdersFetcher
func (*OldOrdersFetcher) GetActiveOrders ¶
func (of *OldOrdersFetcher) GetActiveOrders(symbol string) ([]*krisa_phemex_fork.OrderResponse, error)
func (*OldOrdersFetcher) GetOrderInfoByClientOrderID ¶
func (of *OldOrdersFetcher) GetOrderInfoByClientOrderID( ctx context.Context, symbol, clientOrderID string, createdAt *time.Time, ) (exchanges.OrderInfo, *krisa_phemex_fork.OrderResponse, error)
func (*OldOrdersFetcher) GetOrderInfoByOrderID ¶
func (of *OldOrdersFetcher) GetOrderInfoByOrderID( ctx context.Context, symbol, id string, ) (exchanges.OrderInfo, *krisa_phemex_fork.OrderResponse, error)
type OrderCanceller ¶
type OrderCanceller struct {
// contains filtered or unexported fields
}
func NewOrderCanceller ¶
func NewOrderCanceller( client *krisa_phemex_fork.Client, cof *CombinedOrdersFetcher, lim *PhemexRateLimiter, lg *zap.Logger, ) *OrderCanceller
func (*OrderCanceller) CancelOrder ¶
func (oc *OrderCanceller) CancelOrder(ctx context.Context, phemexSymbol, orderID string) error
type OrderPlacer ¶
type OrderPlacer struct {
// contains filtered or unexported fields
}
func NewOrderPlacer ¶
func NewOrderPlacer( client *krisa_phemex_fork.Client, cof *CombinedOrdersFetcher, lim *PhemexRateLimiter, lg *zap.Logger, ) *OrderPlacer
func (*OrderPlacer) CreateOrderRequest ¶
func (op *OrderPlacer) CreateOrderRequest( symbol string, price, quantity *apd.Decimal, clientOrderID string, side krisa_phemex_fork.SideType, ) (*orderFields, error)
Don't forget to floor `price` and `quantity`
func (*OrderPlacer) CreateOrderRequestV2 ¶
func (op *OrderPlacer) CreateOrderRequestV2(symbol string, price, quantity *apd.Decimal, clientOrderID string, side krisa_phemex_fork.SideType, orderType krisa_phemex_fork.OrderType) (*orderFields, error)
func (*OrderPlacer) PlaceOrder ¶
func (*OrderPlacer) PlaceOrderV2 ¶
func (op *OrderPlacer) PlaceOrderV2(ctx context.Context, isRetry bool, symbol string, price, quantity *apd.Decimal, clientOrderID string, side krisa_phemex_fork.SideType, orderType krisa_phemex_fork.OrderType) (id string, e error)
type PhemexContract ¶
type PhemexContract struct {
// contains filtered or unexported fields
}
func NewPhemexContract ¶
func NewPhemexContract(apiKey, secretKey string, lim *PhemexRateLimiter, lg *zap.Logger) *PhemexContract
func (*PhemexContract) CancelOrder ¶
func (pc *PhemexContract) CancelOrder(ctx context.Context, symbol, id string) error
CancelOrder can return `OrderExecutedError` in case of executed order. can return `OrderNotFoundError` in case of not found order.
func (*PhemexContract) GenerateClientOrderID ¶
func (*PhemexContract) GetAccount ¶
func (*PhemexContract) GetName ¶
func (pc *PhemexContract) GetName() string
func (*PhemexContract) GetOpenOrders ¶
func (pc *PhemexContract) GetOpenOrders(ctx context.Context) ([]exchanges.OrderDetailInfo, error)
func (*PhemexContract) GetOrderInfo ¶
func (*PhemexContract) GetOrderInfoByClientOrderID ¶
func (*PhemexContract) GetOrders ¶
func (pc *PhemexContract) GetOrders(ctx context.Context, filter exchanges.OrderFilter) (res []exchanges.OrderDetailInfo, err error)
func (*PhemexContract) GetPrefix ¶
func (pc *PhemexContract) GetPrefix() string
func (*PhemexContract) GetTradableSymbols ¶
func (pc *PhemexContract) GetTradableSymbols(ctx context.Context) ([]exchanges.SymbolInfo, error)
func (*PhemexContract) PlaceBuyOrder ¶
func (pc *PhemexContract) PlaceBuyOrder(ctx context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, clientOrderID string, ) (id string, e error)
PlaceBuyOrder This method should use `clientOrderID` if it's possible
func (*PhemexContract) PlaceBuyOrderV2 ¶
func (pc *PhemexContract) PlaceBuyOrderV2(ctx context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, clientOrderID string, orderType string, ) (id string, e error)
PlaceBuyOrderV2 This method use to PlaceOrder with Order Type as Parameter
func (*PhemexContract) PlaceSellOrder ¶
func (pc *PhemexContract) PlaceSellOrder(ctx context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, clientOrderID string, ) (id string, e error)
PlaceSellOrder This method should use `clientOrderID` if it's possible
func (*PhemexContract) PlaceSellOrderV2 ¶
func (pc *PhemexContract) PlaceSellOrderV2(ctx context.Context, isRetry bool, symbol string, price, qty *apd.Decimal, clientOrderID string, orderType string, ) (id string, e error)
PlaceSellOrderV2 This method use to PlaceOrder with OrderType as Parameter
func (*PhemexContract) ReleaseOrder ¶
func (pc *PhemexContract) ReleaseOrder(_ context.Context, symbol, id string) error
func (*PhemexContract) RoundPrice ¶
func (*PhemexContract) RoundQuantity ¶
func (*PhemexContract) StartBackgroundJob ¶
func (pc *PhemexContract) StartBackgroundJob(ctx context.Context) error
StartBackgroundJob Only one simultaneous job is allowed
func (*PhemexContract) WatchAccountPositions ¶
func (pc *PhemexContract) WatchAccountPositions(ctx context.Context) (<-chan exchanges.PositionEvent, error)
WatchAccountPositions 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
func (*PhemexContract) WatchOrdersStatuses ¶
func (pc *PhemexContract) WatchOrdersStatuses(ctx context.Context) (<-chan exchanges.OrderEvent, error)
WatchOrdersStatuses 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
func (*PhemexContract) WatchSymbolPrice ¶
func (pc *PhemexContract) WatchSymbolPrice(ctx context.Context, symbol string) (<-chan exchanges.PriceEvent, error)
WatchSymbolPrice 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
type PhemexGroupRateLimiter ¶
type PhemexGroupRateLimiter struct {
Lim *utils.ChangeableMinuteRateLimiter
}
func NewPhemexGroupRateLimiter ¶
func NewPhemexGroupRateLimiter(capacityPerMinute uint) *PhemexGroupRateLimiter
func (*PhemexGroupRateLimiter) Apply ¶
func (pgrl *PhemexGroupRateLimiter) Apply(rateLimHeaders *krisa_phemex_fork.RateLimiterHeaders)
type PhemexRateLimiter ¶
type PhemexRateLimiter struct { // Limits are there https://github.com/phemex/phemex-api-docs/blob/master/Generic-API-Info.en.md // Also take a look to rate-limits.txt file Contract *PhemexGroupRateLimiter Other *PhemexGroupRateLimiter Log *zap.Logger }
func NewPhemexRateLimiter ¶
func NewPhemexRateLimiter(lg *zap.Logger) *PhemexRateLimiter
func (*PhemexRateLimiter) Apply ¶
func (rl *PhemexRateLimiter) Apply(rateLimHeaders *krisa_phemex_fork.RateLimiterHeaders)
Can work in case of `rateLimHeaders == nil`
type PositionFetcher ¶
type PositionFetcher struct {
// contains filtered or unexported fields
}
func NewPositionFetcher ¶
func NewPositionFetcher(client *phemex.Client) *PositionFetcher
func (*PositionFetcher) GetAccountPosition ¶
type PriceResponse ¶
type PriceResponseWrapper ¶
type PriceResponseWrapper struct { Error json.RawMessage `json:"error"` // "error": null, Id *int64 `json:"id"` // "id": 0, Result *PriceResponse `json:"result"` // "result": {} }
type PriceSubscriber ¶
type PriceSubscriber struct{}
type ScalesSubscriber ¶
type ScalesSubscriber struct {
// contains filtered or unexported fields
}
TODO: it's better to store scales in persistent storage
var ScalesSubscriberInstance *ScalesSubscriber
func NewScalesSubscriber ¶
func NewScalesSubscriber(lg *zap.Logger) *ScalesSubscriber
func (*ScalesSubscriber) CheckOrUpdate ¶
func (ss *ScalesSubscriber) CheckOrUpdate(ctx context.Context) error
func (*ScalesSubscriber) GetLastScales ¶
func (ss *ScalesSubscriber) GetLastScales() map[string]SymbolScale
func (*ScalesSubscriber) GetLastSymbolScales ¶
func (ss *ScalesSubscriber) GetLastSymbolScales(symbol string) (SymbolScale, error)
func (*ScalesSubscriber) Start ¶
func (ss *ScalesSubscriber) Start(ctx context.Context)
type SymbolClientOrderID ¶
type SymbolClientOrderID struct {
Symbol, ClientOrderID string
}
type SymbolOrderID ¶
type SymbolOrderID struct {
Symbol, OrderID string
}
type SymbolScale ¶
type WSMarket24Data ¶
type WSMarket24Msg ¶
type WSMarket24Msg struct { Market24H *WSMarket24Data `json:"market24h"` Timestamp int64 `json:"timestamp"` }
type WSOrderEvent ¶
type WSOrderEvent struct {
// contains filtered or unexported fields
}
type WSOrdersCache ¶
type WSOrdersCache struct {
// contains filtered or unexported fields
}
func NewWSOrdersCache ¶
func NewWSOrdersCache() *WSOrdersCache
func (*WSOrdersCache) CopyFrom ¶
func (to *WSOrdersCache) CopyFrom(from *WSOrdersCache)
func (*WSOrdersCache) GetByOrderID ¶
func (c *WSOrdersCache) GetByOrderID(orderIDSelector SymbolOrderID) *orderResponse
func (*WSOrdersCache) InsertOrder ¶
func (c *WSOrdersCache) InsertOrder( orderIDSelector SymbolOrderID, clientOrderIDSelector SymbolClientOrderID, or *orderResponse, )
type WSPositionEvent ¶
type WSPositionEvent struct {
// contains filtered or unexported fields
}