execution

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderAttributionBuilder = "X-Attribution-Builder"
	HeaderAttributionFunder  = "X-Attribution-Funder"
	HeaderAttributionSource  = "X-Attribution-Source"
)
View Source
const (
	// IdempotencyKeyVersionV1 is the initial stable spec for SDK-level idempotency keys.
	IdempotencyKeyVersionV1 = "v1"
)

Variables

This section is empty.

Functions

func IsRetryableError

func IsRetryableError(err error) bool

IsRetryableError classifies retryable transport errors.

func IsRetryableStatusCode

func IsRetryableStatusCode(statusCode int) bool

IsRetryableStatusCode classifies retryable HTTP status codes.

Types

type Attribution

type Attribution struct {
	Builder string `json:"builder,omitempty"`
	Funder  string `json:"funder,omitempty"`
	Source  string `json:"source,omitempty"`
}

Attribution carries builder/funder/source metadata that upstream services can pass through.

func NormalizeAttribution

func NormalizeAttribution(in Attribution) Attribution

NormalizeAttribution returns a canonical form suitable for cross-service propagation.

func (Attribution) HeaderMap

func (a Attribution) HeaderMap() map[string]string

HeaderMap converts attribution fields to HTTP header map.

type CLOBEngine

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

CLOBEngine adapts a CLOB client to the unified execution Engine contract.

func NewCLOBEngine

func NewCLOBEngine(client clobExecutionClient) (*CLOBEngine, error)

NewCLOBEngine creates an Engine backed by CLOB REST APIs.

func (*CLOBEngine) Cancel

Cancel requests cancellation for an existing order.

func (*CLOBEngine) Place

func (e *CLOBEngine) Place(ctx context.Context, req PlaceRequest) (PlaceResponse, error)

Place submits one order to the exchange.

func (*CLOBEngine) Query

func (e *CLOBEngine) Query(ctx context.Context, req QueryRequest) (QueryResponse, error)

Query fetches current order state by order id.

func (*CLOBEngine) Replay

Replay fetches paginated order history that strategy and audit layers can replay.

type CancelRequest

type CancelRequest struct {
	OrderID     string
	Attribution Attribution
}

CancelRequest identifies the order to cancel.

type CancelResponse

type CancelResponse struct {
	Status      string
	Attribution Attribution
}

CancelResponse returns upstream cancel status.

type Engine

type Engine interface {
	Place(ctx context.Context, req PlaceRequest) (PlaceResponse, error)
	Cancel(ctx context.Context, req CancelRequest) (CancelResponse, error)
	Query(ctx context.Context, req QueryRequest) (QueryResponse, error)
	Replay(ctx context.Context, req ReplayRequest) (ReplayResponse, error)
}

Engine defines a unified execution contract for strategy/runtime layers.

The contract intentionally stays minimal:

  • Place submits an order
  • Cancel cancels an order
  • Query fetches a single order state
  • Replay fetches paginated order history for audit/replay loops

type IdempotencyKey

type IdempotencyKey struct {
	Version   string `json:"version"`
	Canonical string `json:"canonical"`
	Digest    string `json:"digest"`
	Value     string `json:"value"`
}

IdempotencyKey represents canonical + hashed key outputs.

func BuildIdempotencyKey

func BuildIdempotencyKey(input IdempotencyKeyInput) (IdempotencyKey, error)

BuildIdempotencyKey creates a deterministic key from tenant + strategy + client_order_id.

Canonical format: tenant=<tenant>;strategy=<strategy>;client_order_id=<clientOrderID>

Final value format: idem:<version>:<sha256(canonical)>

type IdempotencyKeyInput

type IdempotencyKeyInput struct {
	Tenant        string
	Strategy      string
	ClientOrderID string
}

IdempotencyKeyInput defines the minimal fields for key construction.

type IdempotencyParts

type IdempotencyParts struct {
	Tenant        string
	Strategy      string
	ClientOrderID string
}

IdempotencyParts are parsed from canonical representation.

func ParseIdempotencyCanonical

func ParseIdempotencyCanonical(canonical string) (IdempotencyParts, error)

ParseIdempotencyCanonical parses canonical form into typed parts.

type LifecycleEvent

type LifecycleEvent struct {
	OrderID    string          `json:"order_id"`
	State      LifecycleState  `json:"state"`
	Source     LifecycleSource `json:"source"`
	RawStatus  string          `json:"raw_status,omitempty"`
	OccurredAt time.Time       `json:"occurred_at"`
}

LifecycleEvent represents one normalized order lifecycle transition.

func EventFromCancelResponse

func EventFromCancelResponse(orderID string, cancel clobtypes.CancelResponse, source LifecycleSource, at time.Time) (LifecycleEvent, error)

EventFromCancelResponse maps cancel acknowledgement into the unified lifecycle model.

func EventFromOrderResponse

func EventFromOrderResponse(order clobtypes.OrderResponse, source LifecycleSource) (LifecycleEvent, error)

EventFromOrderResponse converts upstream order status to the unified lifecycle state.

func NewCreatedEvent

func NewCreatedEvent(orderID string, at time.Time, source LifecycleSource) (LifecycleEvent, error)

NewCreatedEvent emits a deterministic local "created" event.

type LifecycleSource

type LifecycleSource string

LifecycleSource marks where a lifecycle event was observed.

const (
	LifecycleSourcePlace  LifecycleSource = "place"
	LifecycleSourceCancel LifecycleSource = "cancel"
	LifecycleSourceQuery  LifecycleSource = "query"
	LifecycleSourceReplay LifecycleSource = "replay"
)

type LifecycleState

type LifecycleState string

LifecycleState is the unified order lifecycle model shared by strategy/runtime layers.

const (
	LifecycleStateCreated  LifecycleState = "created"
	LifecycleStateAccepted LifecycleState = "accepted"
	LifecycleStatePartial  LifecycleState = "partial"
	LifecycleStateFilled   LifecycleState = "filled"
	LifecycleStateCanceled LifecycleState = "canceled"
	LifecycleStateRejected LifecycleState = "rejected"
)

func NormalizeLifecycleState

func NormalizeLifecycleState(rawStatus string) (LifecycleState, error)

NormalizeLifecycleState collapses exchange-specific order status strings into the six-state model.

type PlaceRequest

type PlaceRequest struct {
	Order       *clobtypes.Order
	Attribution Attribution
}

PlaceRequest wraps a CLOB order for submission.

type PlaceResponse

type PlaceResponse struct {
	Order       clobtypes.OrderResponse
	Attribution Attribution
}

PlaceResponse returns upstream order details after submission.

type QueryRequest

type QueryRequest struct {
	OrderID     string
	Attribution Attribution
}

QueryRequest identifies the order to fetch.

type QueryResponse

type QueryResponse struct {
	Order       clobtypes.OrderResponse
	Attribution Attribution
}

QueryResponse returns current upstream order state.

type ReplayRequest

type ReplayRequest struct {
	Market      string
	Cursor      string
	Limit       int
	Attribution Attribution
}

ReplayRequest controls paginated order replay.

type ReplayResponse

type ReplayResponse struct {
	Orders      []clobtypes.OrderResponse
	NextCursor  string
	Count       int
	Limit       int
	Attribution Attribution
}

ReplayResponse returns replay pages and cursor.

type RetryDecision

type RetryDecision struct {
	Retry  bool
	Delay  time.Duration
	Reason string
}

RetryDecision is the evaluated action for a failed attempt.

type RetryPolicy

type RetryPolicy struct {
	MaxAttempts int
	BaseBackoff time.Duration
	MaxBackoff  time.Duration
}

RetryPolicy defines retry strategy for network/timeout/5xx failure classes.

func DefaultRetryPolicy

func DefaultRetryPolicy() RetryPolicy

DefaultRetryPolicy returns the SDK default retry policy.

func (RetryPolicy) ComputeBackoff

func (p RetryPolicy) ComputeBackoff(attempt int) time.Duration

ComputeBackoff returns exponential backoff for the given attempt, capped by MaxBackoff.

attempt is 1-based and corresponds to the just-failed attempt.

func (RetryPolicy) Decide

func (p RetryPolicy) Decide(attempt int, err error, statusCode int) RetryDecision

Decide evaluates whether the current failure should be retried.

attempt is 1-based and represents the just-failed attempt number.

type WSPolicy

type WSPolicy struct {
	DisablePing bool

	ReconnectEnabled     bool
	ReconnectBaseDelay   time.Duration
	ReconnectMaxDelay    time.Duration
	ReconnectMultiplier  float64
	ReconnectMaxAttempts int

	HeartbeatInterval time.Duration
	HeartbeatTimeout  time.Duration
}

WSPolicy defines shared websocket reconnect + heartbeat behavior.

func DefaultWSPolicy

func DefaultWSPolicy() WSPolicy

DefaultWSPolicy returns default reconnect + heartbeat parameters.

func (WSPolicy) IsHeartbeatExpired

func (p WSPolicy) IsHeartbeatExpired(lastPong, now time.Time) bool

IsHeartbeatExpired returns true when last pong exceeds timeout window.

func (WSPolicy) NextReconnectDelay

func (p WSPolicy) NextReconnectDelay(attempt int) (time.Duration, bool)

NextReconnectDelay returns delay for a reconnect attempt and whether reconnect should continue.

attempt is 1-based.

func (WSPolicy) ToCLOBConfig

func (p WSPolicy) ToCLOBConfig() ws.ClientConfig

ToCLOBConfig converts policy into clob ws client config.

Jump to

Keyboard shortcuts

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