aboutsummaryrefslogtreecommitdiffstats
path: root/service/src
Commit message (Collapse)AuthorAgeFilesLines
* tests: cover the ex-2 loader, order book trading and desktop stateHEAD2.0masterKostya11 days4-11/+800
| | | | | | | | | | | | | | | | | | | | | | | | | Add tests for the behaviour introduced in the last few commits, so later changes to matching, settlement or the UI state can't quietly break it. On the service side, Ex2LoaderTest loads the ex-2 fixtures and checks that every invalid file is rejected for its own reason, including events with no market maker or two of them, and v1 files. The order book tests cover buys and sells that match or rest in the ladder, self-trade prevention, cash and shares reserved by resting orders, price bounds, risk rejections, and resolution cancelling resting orders and paying the holders. A simulation checks that LMSR settlement conserves money. LedgerMapperTest used to pin the unmapped seq and at fields to their defaults. Now that the mapper fills them from the entry id and time, assert the real values and add a case for a null time. On the desktop side, AppStateTest drives the real ServiceEngine through loading, event creation, LMSR and order book trading, and checks that the observable state updates. Smaller tests check chart timestamps, money and probability formatting, and that every animation settles on its final frame, which is what the UI shows when animations are off.
* service: add sell orders, event lifecycle and order book matchingKostya13 days10-104/+853
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Carry the order side from the context through risk, the trading mechanisms, fulfillment and settlement, so users can sell shares as well as buy them. The order book now matches priced limit orders from named users, rests any unfilled remainder, and prevents self-trades. In a binary market with minting enabled, a buy can also match a bid on the other option to mint a new YES/NO pair, and a sell can match an ask there to merge a pair back into the pool. LMSR gains a sell that refunds the cost difference from the pool. Add createEvent and openEvent to the catalog. Events start as DRAFT and only take the market maker's subsidy when they are opened, which fails if the market maker can't cover it. Add LocalAccountContext to expose user ledgers. Tighten the risk checks: reject orders from blocked accounts, on events that aren't ACTIVE, and at prices outside (0, d). Sells need enough unreserved shares; buys need enough balance to cover commission and cash already committed to resting bids. Settlement now cancels resting orders, pays out on shares still held rather than shares ever bought, sends order book commission to the market maker, and returns unused LMSR subsidy. Events also track per-user cash flow, so the event detail can list participants with their holdings, fees and P&L next to the order books.
* service: add ex-2 XML loader and carry order side through matchingKostya2026-09-069-8/+391
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Ex-2 documents declare users and their market-maker assignments next to the events, and the loader has to reject files that are schema-valid but logically inconsistent, which the v1 loader has no notion of. Add XMLLoaderV2, which checks the extension, unmarshals the document, runs it through XMLValidatorV2 and only then replaces the event and user repositories, so a rejected file leaves the previous catalog intact. The validator enforces unique positive event ids, non-empty names and descriptions, commission within 0..90 with a known type, at least two distinct options, a positive LMSR b or order-book d with non-negative initial inventory, unique user names, positive initial cash, and exactly one existing event per market-maker reference. Let EventMapperV2 take the resolved market maker's name so it lands on the domain event. Give Order a side and the placing user, and Trade the seller, so an order book can match a buyer against a seller. Keep the previous constructors, defaulting to a BUY with no user or seller, so existing LMSR call sites stay unchanged. Route LocalMatchingEngine through the mechanism's placeOrder with side, user and limit price instead of buy(), and have cancelOrder take the order to cancel. Also add an isBlocked query to User and Ledger for accounts that went negative.
* ex-2: add invalid-input fixtures and wire ui-desktop to the serviceKostya2026-09-061-0/+13
| | | | | | | | | | | | | | | | | | | | | The ex-2 loader has to reject documents that are schema-valid but logically broken, and so far only error-2.xml and error-3.xml exercised that path. Add one fixture per validation rule under test-data/ex-2/invalid, each a copy of small.xml with a single defect described in a leading comment: a non-.xml extension, a duplicate event id, commission outside 0..90 on either side, a duplicate user name, zero or negative initial cash, a market maker referencing an unknown event, and an event with no market maker or with two. Teach LedgerMapper to map individual LedgerEntry records to LedgerEntryDTO, renaming id to seq and time to at and rendering the timestamp through InstantOptions.humanize, so callers can show a ledger history rather than only the account summary. Make ui-desktop depend on api and service in the build tooling and in its Eclipse classpath, since the desktop UI now talks to the service layer directly, and put lib/openjfx on java.library.path for the test run so tests touching JavaFX can load its native libraries.
* catalog: add generated v3 JAXB binding and ex-2 test dataKostya2026-09-069-0/+778
| | | | | | | | | | | | | | | | | | | | The ex-2 schema describes a nested Guess-Market/GM-events document in which every event carries its pricing mechanism inline, as either a GM-LMSR element holding the liquidity parameter b or a GM-order-book element holding the allow-mint, initial and d attributes, instead of naming a mechanism and passing its parameters separately. Add the xjc-generated classes for that schema under catalog.model.v3, along with the fixtures the loader will be tested against: small.xml with two events, one per mechanism, multiple.xml with four, and two negative cases -- error-2.xml, where a market maker is funded with zero initial cash, and error-3.xml, where a market maker points at event id 12, which no event declares -- so the cross-reference and funding checks have something to reject. The binding covers the GM-events subtree only. The GM-users half of the document and the per-event id element are not bound yet, so nothing reads these classes so far.
* model: relocate market DTOs out of the flat api packageKostya2026-08-236-30/+39
| | | | | | | | | | | | | | | | | | Move AccountDTO/MarketDTO/MarketStateDTO/PurchaseReceiptDTO/TradeRowDTO out of the catch-all api package into model.market (and LedgerDTO into model.ledger), matching the existing model.event convention so DTOs live next to the domain they describe rather than in the interface package. Relocate LedgerMapper from mapper.v2 to infrastructure.adapter to match the module's established package layout, and update all call sites and imports accordingly. Also register the ui-desktop module in the build tooling: add it to MODULES, add openjfx to the shipped runtime libs, and generalize package.sh so each executable module (ui-console, ui-desktop) gets its own Main-Class/Class-Path manifest and run script instead of special-casing ui-console. Fold long Class-Path manifest lines at 72 bytes per the JAR spec, since adding ui-desktop's dependencies pushed the line past the limit.
* Add MapStruct LedgerMapper and wire annotation processing into build.shKostya2026-08-202-0/+114
| | | | | build.sh now passes -processorpath/-s so MapStruct's generated impl compiles alongside hand-written sources.
* Move CommissionTiming and MechanismType into model.event packageKostya2026-08-2011-18/+18
| | | | | Groups them with the other event-domain enums instead of the general api package, and updates all call sites accordingly.
* Break down purchase receipts by cost/commission, harden XML validation and ↵Kostya2026-08-186-27/+485
| | | | | | | | | state I/O Adds a full pre-load validation pass for GM XML seeds (ids, names, options, commission, LMSR liquidity), replaces IO.print with System.out, and surfaces detailed error messages across load/save commands instead of generic failures.
* Wire event ledger movements, show winning market by name, seed LMSR subsidyKostya2026-08-189-16/+54
| | | | | | | | | | | | | - Event ledger now grows on purchase and shrinks on payout, mirroring the exact amounts moved on the buyer's ledger (it previously had a Ledger object that nothing ever wrote to). - Settlement and event-detail views now show the winning market's display name instead of its raw key; event details are viewable for settled events too (the picker previously excluded anything not ACTIVE). - LMSR events seed their ledger with a SUBSIDY entry for the market maker's worst-case loss (b * ln(outcomes)), reusing the existing cost() function rather than recomputing the formula.
* Add XML schema validation, split build scripts by module, rename ↵Kostya2026-08-1817-34/+371
| | | | | | | | | BuyMenuCommand to PlaceOrderMenuCommand Introduces XMLValidatorV1 and deserializer/adapter classes for events, ledgers, markets, users, and trading mechanisms. Replaces the monolithic build.bat/run.sh scripts with per-module tools (_util.sh, build.sh, package.sh, test.sh) that compile in dependency order.
* Replace order matching with risk/matching/fulfillment/settlement pipelineKostya2026-08-1773-2151/+1995
| | | | | | | | | Move XML loading infrastructure and models under service/catalog, and split order execution into a real pipeline: RiskEngine checks the order, MatchingEngine matches it, FulfillmentContext books the resulting trades, and SettlementContext resolves winning markets. GuessMarketContext.buyShares becomes placeOrder(price, quantity), and TradingMechanism.buy now returns matched trades directly instead of a single TradeExecution.
* Split DTOs into api/model, extract order matching into service/matchingKostya2026-08-1620-226/+118
| | | | | | | Moves Event/Ledger DTOs out of the flat api package into api/model/{event,ledger}, and moves LocalCatalogContext and order matching logic into dedicated service/catalog and service/matching packages, replacing TradingOperation/TradingOperationImpl.
* Rename Option/Account to Market/Ledger, add Result-based error handlingKostya2026-08-1618-133/+295
| | | | | | Split GuessMarketContext into a separate CatalogContext for read-only event listing, wrap fallible operations in Result<T> instead of throwing, and wire load/save of events and users through a JSON Wrapper.
* Implement LMSR and order-book trading logic, wire MarketContext facade and ↵Kostya2026-08-1521-95/+358
| | | | | | | | | | | new menu commands Fill in the previously stubbed cost/pricing math for both trading mechanisms, and give OrderBookTradingMechanism an actual matching engine with resting bid/ask books. Fold EventRepository/UserRepository access into a single MarketContext used by LocalGuessMarketContext, and move the repository package under infrastructure. Add Buy/EventDetails/LoadState/ SaveState/SettleEvent console commands and wire them into App/Menu.
* Switch TradingMechanism quantities to int, add yes/no and select promptsKostya2026-08-143-6/+6
| | | | | | | | | TradingMechanism's q/quantity params move from long/long[] to int/int[] to match the rest of the domain (Trade.quantity, Option counts, etc. are already int). Add InputProcessor.readYesNo and readSelect for upcoming menu commands that need a confirm prompt or a pick-from-list prompt.
* Collapse console I/O interfaces into InputProcessor, drop unneeded atomicsKostya2026-08-143-8/+5
| | | | | | | | | | | InputProvider/OutputProvider each had one implementation and no test exercised the seam, so fold Console{Input,Output}Provider straight into InputProcessor and update Menu/MenuCommand call sites accordingly. Account and Event both use AtomicInteger for a ledger/trade id counter that's only ever touched next to a plain, non-thread-safe ArrayList add in the same method - the atomic bought no real thread-safety. Swapped both to plain int with ++.
* Implement in-memory repositories, XML load validation, and menu exit/list ↵Kostya2026-08-1413-53/+201
| | | | | | | | | | | | | | commands - Add generic Repository<T> interface; EventRepository/UserRepository extend it - Implement InMemoryEventRepository/InMemoryUserRepository backed by ArrayList - Rename XMLLoader to XMLLoaderV1, add LoadValidator and mapper/v2 package - Add OrderBookTradingMechanism - Add User(String, int) convenience constructor - Add ListEventsMenuCommand and ExitMenuCommand, isExit() on MenuCommand - Menu now sizes selection range by max command index and exits on isExit() - LoadFileMenuCommand reports validation issues on failed loads - Untrack test-data/ and config.properties from .gitignore
* Move mapper/provider infra into v1 packages, add repository write methodsKostya2026-08-148-17/+82
| | | | | Correct Mapper's generic parameter order to <TModel, TDomain> and stub addEvent/addUser on the Event/User repositories.
* Wire buyShares and menu commands, replace factory interfaces with DIKostya2026-08-148-5/+116
| | | | | | | | Implement LocalGuessMarketContext.buyShares/loadEvents via a new TradingOperation and Loader, backed by in-memory repositories. Replace the ConsoleInputProviderFactory/ConsoleOutputProviderFactory pattern with picocontainer-injected providers, and drive the menu from a list of MenuCommand implementations instead of a hardcoded printout.
* Add ledgered credit/debit to Account and trade recording to EventKostya2026-08-146-26/+67
| | | | | | | Drops AccountType (accounts no longer need to self-identify), gives Account credit()/debit() that append LedgerEntry rows, adds Event.recordTrade()/tradeVolumeOf()/getCommission(), and implements LocalGuessMarketContext.listEvents() via the repository.
* Implement LMSR mechanism and Event/Account accessors, wire EventMapperV1Kostya2026-08-144-2/+176
| | | | | | Adds LmsrTradingMechanism, exposes Event/Account getters plus Event.toEventSummary() for DTO conversion, and implements EventMapperV1.toDomain() to build Event from the legacy XML model.
* Wire EventRepository into LocalGuessMarketContext, add mapper/provider infra ↵Kostya2026-08-147-3/+48
| | | | | | | and tests Removes the placeholder Mapper interface in favor of concrete mapper/provider implementations, fixes Menu.stop() to no-op instead of throwing.
* Add legacy XML model bindings, mapper infra, and normalize account balanceKostya2026-08-1328-4/+2277
| | | | | Rename repositories package to repository, add MarketAction domain type, and round Account.initialBalance through BigDecimalOptions.toMoney.
* Add domain model, repositories, and trading mechanism interfaces to service ↵Kostya2026-08-1311-0/+197
| | | | | | | module Introduces Account/Event/Trade/User/Option/LedgerEntry domain types plus EventRepository/UserRepository and TradingMechanism abstractions.
* Add service module with stubbed LocalGuessMarketContextKostya2026-08-131-0/+62
GuessMarketContext gained a richer surface (loadEvents/listEvents/ buyShares/closeEvent/account/save-restoreState) backed by new EventDetailDTO, MarketStateDTO, OptionStateDTO and PurchaseReceiptDTO. The old engine-module provider implemented the previous shape and is removed; market.guess.service.LocalGuessMarketContext replaces it as a stub, each method throwing UnsupportedOperationException pending a real implementation.