Skip to content

daytrader-go: trading - #8

Open
devin-ai-integration[bot] wants to merge 2 commits into
migration/daytrader-gofrom
devin/1794800000-go-trading
Open

devin-ai-integration[bot] wants to merge 2 commits into
migration/daytrader-gofrom
devin/1794800000-go-trading

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Ports the trading area of DayTrader 3 to the Go + PostgreSQL target: buy, sell, portfolio and order completion. Only daytrader-go/internal/features/trading/, daytrader-go/templates/trading_*.html and go.mod/go.sum (AWS SDK v2 for SQS) are touched.

What was ported

Legacy Go
TradeServletAction.doBuy / doSell / doPortfolio buy, sell, portfolio in handlers.go, registered for buy, sell, portfolio, portfolioNoEdge
TradeAction.buy/sell + TradeSLSBBean.buy/sell/createOrder/completeOrder/cancelOrder/queueOrder/updateQuotePriceVolume service in service.go
order.jsp, portfolio.jsp trading_order.html, trading_portfolio.html
DTBroker3MDB + jms/TradeBrokerQueue orderConsumer + orderQueue (queue.go, sqs.go)

Each trade is one app.Store.InTx:

lock quote (FOR UPDATE) -> createOrder (NextID "order", status open, fee 24.95)
buy : balance -= quantity x price + fee      sell: holding.purchasedate = epoch; balance += quantity x price - fee
sync : completeOrder in the same tx (buy: NextID "holding" + insert; sell: delete holding; order closed)
async: leave the order open, queue.send(orderID) as the last step before commit
updateQuotePriceVolume: price = round2(factor x price) (x600 for a 0.01 penny stock), volume += quantity

Money is decimal.Decimal throughout. portfolio.jsp prints BigDecimal.toString(), so the page keeps the Java scale (9.00 x 10 is 90.00, an empty total is 0).

Async mode (off by default)

ORDER_PROCESSING_MODE=async leaves the order open and queues its id; orderConsumer completes it in its own transaction. orderQueue has two implementations: memoryQueue (tests, and async mode without ORDER_QUEUE_URL) and sqsQueue (aws-sdk-go-v2/service/sqs, queue URL from ORDER_QUEUE_URL, default credential chain). The consumer is started without touching shared files: by the build function of web.RegisterRoute("GET /trading/orderQueue", ...) at start-up, and by the first handler call otherwise. That route answers with the mode, queue kind and whether the consumer runs. No test builds an AWS client; the SQS queue is tested against a fake.

Verification (observed)

  • gofmt -l . empty, go vet ./... clean, go test ./... ok on this branch.
  • Trading tests against PostgreSQL (TRADING_TEST_DATABASE_URL, private schema, skipped when unset): sync buy/sell, cancelled second sell, rollback on bad input, penny stock recovery, async buy/sell through the in-memory queue, rollback when the queue send fails. All pass against the compose database.
  • Legacy Liberty on :9083: make parity 13/13.
  • Go on :8080: make parity printed PASS for all 13 scenarios, including 05-buy, 06-sell, 07-portfolio, on a local throwaway branch (not pushed) that merged this branch with devin/1794800000-go-auth, -go-account, -go-market, -go-rest and -go-infra as they were on origin at that time. -go-tests was not on origin. This branch alone cannot run those scenarios (they need register, account and quotes).
  • Async smoke on the same combined build (ORDER_PROCESSING_MODE=async, in-memory queue): the buy page showed the order open, and /daytrader/trading/orderQueue reported the consumer running. Nothing was sent to AWS.

Deliberate differences from legacy

  • A sell of a holding that no longer exists renders the order page without the "New Order" block; the legacy page prints an order full of nulls.
  • doBuy with a non-numeric quantity forwards to home once with illegal argument:; the legacy servlet dispatches to home and then again to the order page.
  • A non-positive quantity is rejected as an illegal argument; legacy accepts it.
  • The consumer retries an order id it cannot see yet (the trade may not have committed) before leaving the message for redelivery; a failed completion is logged and the message removed, as the MDB did. There is no two-phase commit: the send is the last step of the trade, so a failed send rolls the trade back, but a failed commit after a successful send leaves a message for an order that does not exist.
  • updateQuotePriceVolume does not publish to the quote topic (PUBLISH_QUOTE_PRICE_CHANGE is off in the scaffold; DTStreamer3MDB is not part of this area).

Scaffold requests

  • templates/layout.html wraps Alert: The following Order(s) have completed. and for a quote or to trade. over two lines. The parity harness compares text per line, so every page using pageStart/pageEnd differs from the recording (this failed 04 to 07 before the workaround). trading_layout.html holds copies of the three layout blocks with those texts on one line; fix layout.html and delete that file.
  • store has no FOR UPDATE reads and exports no order column list, so the trading package carries its own SELECT ... FOR UPDATE statements for quote, holding and order.
  • There is no shutdown hook for background work: the consumer runs on context.Background() until the process exits.
  • App has no start-up hook; a RegisterRoute build function is used as one.

Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/9173727a95744fa0b6726d9c6531e7bf
Open in Devin Desktop: https://partner-workshops.devinenterprise.com/desktop/session/9173727a95744fa0b6726d9c6531e7bf?variant=devin
Requested by: @sumitshatwara

@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant