Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ CREATE TABLE public.trades (
market_id uuid NOT NULL,
price bigint NOT NULL,
size bigint NOT NULL,
maker_fee bigint DEFAULT 0 NOT NULL,
taker_fee bigint DEFAULT 0 NOT NULL,
fee bigint DEFAULT 0 NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL
);

Expand Down
4 changes: 2 additions & 2 deletions internal/platform/affiliate/pg_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func insertTestTrade(t *testing.T, pool *pgxpool.Pool, matchID string) string {
err = pool.QueryRow(ctx,
`INSERT INTO trades (
match_id, maker_order_id, taker_order_id, maker_address,
taker_address, market_id, price, size, maker_fee, taker_fee
taker_address, market_id, price, size, fee
) VALUES ($1, $2, $3, '0xmaker1', '0xmaker2',
'00000000-0000-0000-0000-000000000000', 50, 100, 5, 5)
'00000000-0000-0000-0000-000000000000', 50, 100, 5)
RETURNING id`, matchID, orderID1, orderID2,
).Scan(&tradeID)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions internal/trading/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ type Trade struct {
MarketID string // Denormalized for query efficiency.
Price int64 // Execution price in integer cents (1-99).
Size int64 // Number of contracts traded.
MakerFee int64 // Fee charged to maker, in cents.
TakerFee int64 // Fee charged to taker, in cents.
Fee int64 // Fee charged on the trade, from taker order's feeRateBps.
CreatedAt time.Time // Set by database.
}

Expand Down
6 changes: 3 additions & 3 deletions internal/trading/pg_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ func (repo *PGRepository) SaveTrade(ctx context.Context, trade *Trade) error {
_, err = tx.Exec(ctx,
`INSERT INTO trades (
match_id, maker_order_id, taker_order_id, maker_address,
taker_address, market_id, price, size, maker_fee, taker_fee
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)`,
taker_address, market_id, price, size, fee
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)`,
trade.MatchID, trade.MakerOrderID, trade.TakerOrderID,
trade.MakerAddress, trade.TakerAddress, trade.MarketID,
trade.Price, trade.Size, trade.MakerFee, trade.TakerFee,
trade.Price, trade.Size, trade.Fee,
)
if err != nil {
return fmt.Errorf("saving trade: inserting row: %w", err)
Expand Down
3 changes: 1 addition & 2 deletions internal/trading/pg_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ func TestPGRepository_SaveTrade(t *testing.T) {
MarketID: marketID,
Price: 50,
Size: 10,
MakerFee: 1,
TakerFee: 2,
Fee: 2,
}

if err := repo.SaveTrade(ctx, trade); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions migrations/trading/000002_create_trades.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ CREATE TABLE IF NOT EXISTS trades (
market_id UUID NOT NULL,
price BIGINT NOT NULL,
size BIGINT NOT NULL,
maker_fee BIGINT NOT NULL DEFAULT 0,
taker_fee BIGINT NOT NULL DEFAULT 0,
fee BIGINT NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),

CONSTRAINT trades_match_id_unique UNIQUE (match_id)
Expand Down