-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add venue-aware storage schema #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add venue-aware storage schema #53
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
recomma/storage/order_scalers.go
Lines 378 to 382 in cc77d12
| MultiplierUpdatedBy: params.MultiplierUpdatedBy, | |
| CreatedAtUtc: createdAt.UTC().UnixMilli(), | |
| SubmittedOrderID: params.SubmittedOrderID, | |
| Skipped: boolToInt(params.Skipped), | |
| SkipReason: params.SkipReason, |
The schema changes replaced the auto‑increment scaled_orders.id with the (venue_id, wallet, order_id) primary key and removed submitted_order_id, so sqlcgen.InsertScaledOrderParams no longer exposes SubmittedOrderID and the generated method now returns only error. InsertScaledOrderAudit still sets SubmittedOrderID on the params struct and assigns the result of InsertScaledOrder to id, which no longer compiles. The function needs to supply the new venue/wallet/order identifiers and drop the removed field and return value.
recomma/storage/order_scalers.go
Lines 446 to 450 in cc77d12
| func (s *Storage) ListScaledOrdersByMetadata(ctx context.Context, md metadata.Metadata) ([]ScaledOrderAudit, error) { | |
| s.mu.Lock() | |
| defer s.mu.Unlock() | |
| rows, err := s.queries.ListScaledOrdersByMetadata(ctx, md.Hex()) |
ListScaledOrdersByMetadata still invokes the generated query with a single md string, but the updated SQL now requires a struct containing both venue_id and md. This call (and the similar one for deals) will not compile until the caller is changed to pass the composite key.
Lines 329 to 333 in cc77d12
| params := sqlcgen.InsertHyperliquidStatusParams{ | |
| Md: md.Hex(), | |
| Status: raw, | |
| RecordedAtUtc: time.Now().UTC().UnixMilli(), | |
| } |
The new schema expects InsertHyperliquidStatusParams (and the create/modify/cancel upserts) to carry venue_id, wallet, order_id, payload_type, and payload_blob, but the storage layer still populates only Md and the old Status blob. The generated structs no longer have a Status field, so this code will fail to compile and would violate the NOT NULL/foreign key constraints even if it did. The caller needs to supply the new composite identifiers and payload metadata for each hyperliquid submission/status write.
ℹ️ 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".
|
@codex review, for context see |
There was a problem hiding this 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".
| CREATE TABLE IF NOT EXISTS venues ( | ||
| id TEXT PRIMARY KEY, | ||
| type TEXT NOT NULL, | ||
| display_name TEXT NOT NULL, | ||
| wallet TEXT NOT NULL, | ||
| flags JSON NOT NULL DEFAULT (CAST('{}' AS BLOB)), | ||
| CHECK (json_valid(flags)) | ||
| ); | ||
|
|
||
| CREATE UNIQUE INDEX IF NOT EXISTS idx_venues_type_wallet | ||
| ON venues(type, wallet); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS bot_venue_assignments ( | ||
| bot_id INTEGER NOT NULL, | ||
| venue_id TEXT NOT NULL, | ||
| is_primary INTEGER NOT NULL DEFAULT 0 CHECK(is_primary IN (0, 1)), | ||
| assigned_at_utc INTEGER NOT NULL DEFAULT (CAST(unixepoch('now','subsec') * 1000 AS INTEGER)), | ||
| PRIMARY KEY (bot_id, venue_id), | ||
| FOREIGN KEY(bot_id) REFERENCES threecommas_bots(bot_id) ON DELETE CASCADE, | ||
| FOREIGN KEY(venue_id) REFERENCES venues(id) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| CREATE UNIQUE INDEX IF NOT EXISTS idx_bot_venue_assignments_primary | ||
| ON bot_venue_assignments(bot_id) | ||
| WHERE is_primary = 1; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS hyperliquid_submissions ( | ||
| md TEXT PRIMARY KEY, | ||
| action_kind TEXT NOT NULL CHECK(action_kind IN ('create','modify','cancel')), | ||
| create_payload JSON, | ||
| modify_payloads JSON NOT NULL DEFAULT (CAST('[]' AS BLOB)), | ||
| cancel_payload JSON, | ||
| updated_at_utc INTEGER NOT NULL DEFAULT(unixepoch('now','subsec') * 1000), | ||
| botevent_row_id INTEGER NOT NULL, | ||
| CHECK (create_payload IS NULL OR json_valid(create_payload)), | ||
| CHECK (modify_payloads IS NULL OR json_valid(modify_payloads)), | ||
| CHECK (cancel_payload IS NULL OR json_valid(cancel_payload)) | ||
| venue_id TEXT NOT NULL, | ||
| wallet TEXT NOT NULL, | ||
| order_id TEXT NOT NULL, | ||
| md TEXT NOT NULL, | ||
| action_kind TEXT NOT NULL CHECK(action_kind IN ('create','modify','cancel')), | ||
| create_payload JSON, | ||
| modify_payloads JSON NOT NULL DEFAULT (CAST('[]' AS BLOB)), | ||
| cancel_payload JSON, | ||
| payload_type TEXT NOT NULL, | ||
| payload_blob BLOB NOT NULL, | ||
| updated_at_utc INTEGER NOT NULL DEFAULT(unixepoch('now','subsec') * 1000), | ||
| botevent_row_id INTEGER NOT NULL, | ||
| PRIMARY KEY (venue_id, wallet, order_id), | ||
| FOREIGN KEY(venue_id) REFERENCES venues(id) ON DELETE CASCADE, | ||
| CHECK (create_payload IS NULL OR json_valid(create_payload)), | ||
| CHECK (modify_payloads IS NULL OR json_valid(modify_payloads)), | ||
| CHECK (cancel_payload IS NULL OR json_valid(cancel_payload)) | ||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_hyperliquid_submissions_md | ||
| ON hyperliquid_submissions(md); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS hyperliquid_status_history ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| md TEXT NOT NULL, | ||
| status BLOB NOT NULL, | ||
| recorded_at_utc INTEGER NOT NULL DEFAULT(unixepoch('now','subsec') * 1000) | ||
| venue_id TEXT NOT NULL, | ||
| wallet TEXT NOT NULL, | ||
| order_id TEXT NOT NULL, | ||
| md TEXT NOT NULL, | ||
| payload_type TEXT NOT NULL, | ||
| payload_blob BLOB NOT NULL, | ||
| recorded_at_utc INTEGER NOT NULL DEFAULT(unixepoch('now','subsec') * 1000), | ||
| PRIMARY KEY (venue_id, wallet, order_id, recorded_at_utc), | ||
| FOREIGN KEY(venue_id, wallet, order_id) REFERENCES hyperliquid_submissions(venue_id, wallet, order_id) ON DELETE CASCADE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add migration for new venue columns
The schema now expects hyperliquid_submissions, hyperliquid_status_history, and scaled_orders to include venue_id, wallet, order_id, and typed payload columns, but the DDL still uses CREATE TABLE IF NOT EXISTS. On any existing database these statements will no-op and leave the old layout in place, while the regenerated queries immediately reference the new columns (UpsertHyperliquidCreate, InsertScaledOrder, etc.). Upgrading without manually dropping the tables will therefore cause runtime “no such column” errors. Consider adding an explicit migration/alter or recreating the tables so the new schema is applied automatically.
Useful? React with 👍 / 👎.
752edc0 to
f628030
Compare
|
@codex based on the spec in |
|
Summary
Testing
|
ea385fd to
e9f6c00
Compare
|
@codex please investigate why the go tests are failing and fix the root cause, I suspect the changes conflict. Check the |
|
Summary
Testing
|
|
|
@codex please provide a conventional commit + summary for all changes in this PR for the merge commit |
|
Conventional Commit Summary
Testing
|
b28522e
into
codex/investigate-multi-wallet-support-for-hyperliquid
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_690653d47af08326926a79832136ffb6