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

Skip to content

Conversation

@terwey
Copy link
Collaborator

@terwey terwey commented Nov 1, 2025

Summary

  • add venues and bot assignment tables to the storage schema and update hyperliquid tables to use composite identifiers
  • refresh sqlc queries to accept venue-aware arguments and regenerate models for the new schema

Testing

  • go generate ./gen/storage

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

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

MultiplierUpdatedBy: params.MultiplierUpdatedBy,
CreatedAtUtc: createdAt.UTC().UnixMilli(),
SubmittedOrderID: params.SubmittedOrderID,
Skipped: boolToInt(params.Skipped),
SkipReason: params.SkipReason,

P0 Badge Update scaled-order insert to match new composite key API

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.


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())

P0 Badge Adjust scaled-order listing calls for new sqlc signatures

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.


recomma/storage/storage.go

Lines 329 to 333 in cc77d12

params := sqlcgen.InsertHyperliquidStatusParams{
Md: md.Hex(),
Status: raw,
RecordedAtUtc: time.Now().UTC().UnixMilli(),
}

P0 Badge Hyperliquid persistence lacks venue and payload fields

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".

@terwey
Copy link
Collaborator Author

terwey commented Nov 1, 2025

@codex review, for context see specs/multi_venue_emission.adoc

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 49 to 108
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

Choose a reason for hiding this comment

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

P0 Badge 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 👍 / 👎.

@terwey terwey force-pushed the codex/investigate-multi-wallet-support-for-hyperliquid branch from 752edc0 to f628030 Compare November 2, 2025 16:59
@terwey
Copy link
Collaborator Author

terwey commented Nov 2, 2025

@codex based on the spec in specs/multi_venue_emission.adoc and the rename of metadata to orderid (git history shows this) fix the merge conflicts for merging codex/update-database-schema-and-queries-for-venues into codex/investigate-multi-wallet-support-for-hyperliquid

@chatgpt-codex-connector
Copy link

Summary

  • Dropped existing Hyperliquid submission/status tables before recreating them so the venue-aware schema (including payload metadata) is applied during upgrades. storage/sqlc/schema.sqlL75-L111
  • Dropped and recreated the scaled_orders table to ensure migrations pick up the composite venue/wallet/order identifiers required by the new schema. storage/sqlc/schema.sqlL173-L198

Testing

  • ⚠️ go test ./... (skipped: command terminated because required module downloads are unavailable in this environment)

View task →

@terwey terwey force-pushed the codex/update-database-schema-and-queries-for-venues branch from ea385fd to e9f6c00 Compare November 2, 2025 21:40
@terwey
Copy link
Collaborator Author

terwey commented Nov 2, 2025

@codex please investigate why the go tests are failing and fix the root cause, I suspect the changes conflict. Check the ./specs dir first if you have questions.

@chatgpt-codex-connector
Copy link

Summary

Testing

  • go generate ./gen/storage
  • ⚠️ go test ./storage -run Test -count=0 (terminated because Go module downloads hang in this environment)

View task →

@terwey
Copy link
Collaborator Author

terwey commented Nov 2, 2025

Summary

  • Ensured scaled order audits always persist the original 3Commas order identifier and added shared converters that map the new sqlc row wrappers (including legacy “#”-suffixed records) back into storage models.
  • Reintroduced an autoincrement primary key on scaled_orders and regenerated the sqlc query/result types that feed storage readers and audit lookups.
  • Updated the order log assembly to reuse the shared converter when emitting scaled order audit entries through the API.

@terwey
Copy link
Collaborator Author

terwey commented Nov 2, 2025

@codex please provide a conventional commit + summary for all changes in this PR for the merge commit

@chatgpt-codex-connector
Copy link

Conventional Commit
feat(storage): add venue-aware hyperliquid persistence

Summary

Testing

  • Not run (not requested)

View task →

@terwey terwey merged commit b28522e into codex/investigate-multi-wallet-support-for-hyperliquid Nov 2, 2025
1 check passed
@terwey terwey deleted the codex/update-database-schema-and-queries-for-venues branch November 2, 2025 22:25
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