client

package
v0.0.0-...-23a414b Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartDeleveragingDaemonTaskLoop

func StartDeleveragingDaemonTaskLoop(
	client *Client,
	ctx context.Context,
	s SubTaskRunner,
	flags flags.DaemonFlags,
	ticker *time.Ticker,
	stop <-chan bool,
)

StartDeleveragingDaemonTaskLoop contains the logic to periodically run the deleveraging daemon task.

Types

type Client

type Client struct {
	// Query clients
	BlocktimeQueryClient      blocktimetypes.QueryClient
	SubaccountQueryClient     satypes.QueryClient
	DeleveragingServiceClient api.DeleveragingServiceClient

	// include HealthCheckable to track the health of the daemon.
	daemontypes.HealthCheckable
	// contains filtered or unexported fields
}

Client implements a daemon service client that periodically gets a list of all subaccounts with open positions on perpetuals

func NewClient

func NewClient(logger log.Logger) *Client

func (*Client) FetchSubaccountsAtBlockHeight

func (c *Client) FetchSubaccountsAtBlockHeight(
	ctx context.Context,
	blockHeight uint32,
	deleveragingFlags flags.DeleveragingFlags,
) (
	subaccounts []satypes.Subaccount,
	err error,
)

func (*Client) GetAllSubaccounts

func (c *Client) GetAllSubaccounts(
	ctx context.Context,
	pageLimit uint64,
) (
	subaccounts []satypes.Subaccount,
	err error,
)

GetAllSubaccounts queries a gRPC server and returns a list of subaccounts and their balances and open positions.

func (*Client) GetPreviousBlockInfo

func (c *Client) GetPreviousBlockInfo(
	ctx context.Context,
) (
	blockHeight uint32,
	err error,
)

GetPreviousBlockInfo queries a gRPC server using `QueryPreviousBlockInfoRequest` and returns the previous block height.

func (*Client) GetSubaccountOpenPositionInfo

func (c *Client) GetSubaccountOpenPositionInfo(
	subaccounts []satypes.Subaccount,
) (
	subaccountOpenPositionInfo map[uint32]*clobtypes.SubaccountOpenPositionInfo,
)

GetSubaccountOpenPositionInfo iterates over the given subaccounts and returns a map of perpetual id to open position info.

func (*Client) SendDeleveragingSubaccountIds

func (c *Client) SendDeleveragingSubaccountIds(
	ctx context.Context,
	openPositionInfoMap map[uint32]*clobtypes.SubaccountOpenPositionInfo,
) error

SendDeleveragingSubaccountIds sends a list of subaccounts with open positions for each perp to a gRPC server via `UpdateSubaccountsListForDeleveragingDaemon`.

func (*Client) Start

func (c *Client) Start(
	ctx context.Context,
	flags flags.DaemonFlags,
	appFlags appflags.Flags,
	grpcClient daemontypes.GrpcClient,
) error

Start begins a job that periodically: 1) Queries a gRPC server for all subaccounts including their open positions. 2) Sends a list of subaccount ids with open positions for each perpetual.

type SubTaskRunner

type SubTaskRunner interface {
	RunDeleveragingDaemonTaskLoop(
		ctx context.Context,
		client *Client,
		deleveragingFlags flags.DeleveragingFlags,
	) error
}

SubTaskRunner provides an interface that encapsulates the deleveraging daemon logic to gather subaccounts with open positions for each perp. This interface is used to mock the daemon logic in tests.

type SubTaskRunnerImpl

type SubTaskRunnerImpl struct{}

func (*SubTaskRunnerImpl) RunDeleveragingDaemonTaskLoop

func (s *SubTaskRunnerImpl) RunDeleveragingDaemonTaskLoop(
	ctx context.Context,
	daemonClient *Client,
	deleveragingFlags flags.DeleveragingFlags,
) error

RunDeleveragingDaemonTaskLoop contains the logic to communicate with various gRPC services to generate the list of subaccounts with open positions for each perpetual.

Jump to

Keyboard shortcuts

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