Documentation
¶
Index ¶
- Constants
- func IsRetryableError(err error) bool
- func IsRetryableStatusCode(statusCode int) bool
- type Attribution
- type CLOBEngine
- func (e *CLOBEngine) Cancel(ctx context.Context, req CancelRequest) (CancelResponse, error)
- func (e *CLOBEngine) Place(ctx context.Context, req PlaceRequest) (PlaceResponse, error)
- func (e *CLOBEngine) Query(ctx context.Context, req QueryRequest) (QueryResponse, error)
- func (e *CLOBEngine) Replay(ctx context.Context, req ReplayRequest) (ReplayResponse, error)
- type CancelRequest
- type CancelResponse
- type Engine
- type IdempotencyKey
- type IdempotencyKeyInput
- type IdempotencyParts
- type LifecycleEvent
- func EventFromCancelResponse(orderID string, cancel clobtypes.CancelResponse, source LifecycleSource, ...) (LifecycleEvent, error)
- func EventFromOrderResponse(order clobtypes.OrderResponse, source LifecycleSource) (LifecycleEvent, error)
- func NewCreatedEvent(orderID string, at time.Time, source LifecycleSource) (LifecycleEvent, error)
- type LifecycleSource
- type LifecycleState
- type PlaceRequest
- type PlaceResponse
- type QueryRequest
- type QueryResponse
- type ReplayRequest
- type ReplayResponse
- type RetryDecision
- type RetryPolicy
- type WSPolicy
Constants ¶
const ( HeaderAttributionBuilder = "X-Attribution-Builder" HeaderAttributionFunder = "X-Attribution-Funder" HeaderAttributionSource = "X-Attribution-Source" )
const (
// IdempotencyKeyVersionV1 is the initial stable spec for SDK-level idempotency keys.
IdempotencyKeyVersionV1 = "v1"
)
Variables ¶
This section is empty.
Functions ¶
func IsRetryableError ¶
IsRetryableError classifies retryable transport errors.
func IsRetryableStatusCode ¶
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 ¶
func (e *CLOBEngine) Cancel(ctx context.Context, req CancelRequest) (CancelResponse, error)
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 ¶
func (e *CLOBEngine) Replay(ctx context.Context, req ReplayRequest) (ReplayResponse, error)
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 ¶
IdempotencyKeyInput defines the minimal fields for key construction.
type IdempotencyParts ¶
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 ¶
RetryDecision is the evaluated action for a failed attempt.
type RetryPolicy ¶
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 ¶
IsHeartbeatExpired returns true when last pong exceeds timeout window.
func (WSPolicy) NextReconnectDelay ¶
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.