Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@terwey
Copy link
Collaborator

@terwey terwey commented Oct 30, 2025

feat(emitter,worker,filltracker): reconcile HyperLiquid orders and skip no-ops

Added ErrOrderAlreadySatisfied and taught both the order worker and fill tracker to treat it as a skipped submission.
Reworked the HyperLiquid emitter to reconcile against cached/live status, issue modifies for live orders, and short-circuit
when an existing order already matches the desired payload (including reduce-only transitions).

Area Change Rationale
API Introduce ErrOrderAlreadySatisfied Signal “no work needed” instead of logging a misleading success
Worker In cmd/recomma, treat ErrOrderAlreadySatisfied as skip Avoid false “sent” logs and queue churn
Fill tracker Log skipped when already satisfied Clearer observability
Emitter (create) Load latest stored submission; compare to cached HL status; short-circuit if matched; otherwise issue Modify Accurate reconciliation; prevents duplicate creates
Emitter (modify) Factor submitModify with shared rate-limit handling & persistence Dedup logic; consistent error/cooldown behavior
Matching Compare side/coin/size/price (ε=1e-9), reduce-only, and order-type details (limit TIF, trigger params) Prevents skipping required behavioral updates

Implementation notes:

  • New helpers: isLiveStatus, ordersMatch, orderTypesMatch, floatEquals, submitModify.
  • Create flow loads the most recent stored submission before reconciling; returns ErrOrderAlreadySatisfied when matched.

https://chatgpt.com/codex/tasks/task_e_6902ba833fd083268a0b9ec2e74e6868

@terwey terwey marked this pull request as ready for review October 30, 2025 01:32
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 282 to 318
func ordersMatch(status *hyperliquid.WsOrder, desired hyperliquid.CreateOrderRequest) bool {
if status == nil {
return false
}

if !strings.EqualFold(status.Order.Coin, desired.Coin) {
return false
}

side := strings.ToUpper(status.Order.Side)
if desired.IsBuy {
if side != "B" {
return false
}
} else {
if side != "S" {
return false
}
}

size, err := strconv.ParseFloat(status.Order.Sz, 64)
if err != nil {
return false
}
if !floatEquals(size, desired.Size) {
return false
}

price, err := strconv.ParseFloat(status.Order.LimitPx, 64)
if err != nil {
return false
}
if !floatEquals(price, desired.Price) {
return false
}

return true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Consider reduce-only when detecting satisfied orders

The new ordersMatch helper only compares coin, side, size and price before returning ErrOrderAlreadySatisfied. If the desired update only toggles flags such as ReduceOnly, the emitter now treats the order as already satisfied and skips emitting a modify, while filltracker still expects the reduce-only change to be applied. That leaves a live order in the wrong mode and can allow a take-profit that should be reduce-only to remain non–reduce-only. The equality check should include reduce-only (and other behavioural fields) before short-circuiting.

Useful? React with 👍 / 👎.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex go ahead and implement the fix

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

  • Loaded the most recent stored submission before comparing cached Hyperliquid status so that reconciliation can detect when an existing order already matches the desired payload, including reduce-only transitions. emitter/emitter.goL134-L165
  • Added matching logic for reduce-only flags and order type details when determining whether a live order satisfies the desired state, preventing behavioural updates from being skipped. emitter/emitter.goL295-L374

Testing

  • go test ./...

View task →

@terwey
Copy link
Collaborator Author

terwey commented Oct 30, 2025

@codex final review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Breezy!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@terwey terwey changed the title fix: restore emitter reconciliation comments feat(emitter,worker,filltracker): reconcile HyperLiquid orders and skip no-ops Oct 30, 2025
@terwey terwey merged commit 044154e into main Oct 30, 2025
1 check passed
@terwey terwey deleted the codex/fix-take-profit-reconciling-issues branch October 31, 2025 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants