# Commerce – Money, Shops and a Stock Exchange for Fabric

A Fabric mod for **Minecraft 26.3** that gives your world an economy:

- a **currency**, Eurodollars by default, with any name you like
- **coins** to carry, and **bank accounts** with statements, interest, loans and bank cards
- **shop counters** where anyone can sell anything, for cash or by card
- a **commodity market** that buys and sells raw goods at prices that react to supply and demand
- a **stock exchange** with real order books and a matching engine: a simulated market trades in the background, news moves prices, and companies pay dividends

![The stock terminal: quotes, a price chart, the order book and order entry](docs/img/exchange_stocks.jpg)

## Installing with Prism Launcher

1. Create an instance with Minecraft **26.3** and the **Fabric** loader (0.19.5 or newer).
2. Add **Fabric API** (Edit → Mods → Download mods).
3. Add `commerce-1.0.0.jar` (Edit → Mods → Add file).
4. On a server, put the jar and Fabric API into `mods/`. Every player needs the mod too.

The download site also offers an auto-updating Prism instance that brings all our mods, including this one.

## The currency

Money comes in two forms:

- **Coins** you carry in your inventory. The four coins are worth 1, 10, 100 and 1000 units. They are named after the server's currency, for example "10 Eurodollar Coin".
- **Book money** in your bank account. Every player gets an account when they first join, with a welcome bonus of 250.

The **currency's name**, plural and symbol are set in `config/commerce.json` (default `Eurodollar` / `Eurodollars` / `€$`). Clients get them from the server, so everyone sees the server's currency.

**Earning money in survival:**
- hostile mobs sometimes drop a few coins
- the commodity market buys wheat, wood, ores, diamonds and more
- shop counters let you sell to other players
- dividends and trading on the stock exchange

![Coins and a bank card; while you hold one, your money shows above the hotbar](docs/img/hud.jpg)

## Bank terminal

The bank terminal (ATM) is your branch:

- **Deposit all coins** puts every coin you carry into your account.
- **Withdraw** turns book money into coins, largest coins first.
- **Transfer** sends money to another player's account by name.
- **Borrow** and **Repay loan** handle credit. You can borrow up to 5,000; loans cost 0.5 % a day, added at dawn.
- **Bank card** issues a debit card in your name (5). It pays at shop counters and shows your balance when used. A card only works for its owner.

On the right is your **statement**, the last 40 bookings. Positive balances earn 0.05 % interest each Minecraft day.

![The bank terminal with balance, actions and statement](docs/img/bank.jpg)

## Shop counters

Place a shop counter and it is yours. As the **owner**:

- Drop an item from your cursor onto one of the nine offer cells. That item, with that stack size, becomes the lot you sell. Right-click a cell to clear it.
- Pick an offer, type a price, press **Set**.
- Fill the **stock** (27 slots) below with what you sell.
- Card payments go straight to your bank account. Cash goes into the **till**; **Collect** empties it into your inventory.

As a **customer**, pick an offer and the number of lots, then **Pay cash** or **Pay by card**. Cash is paid in whole coins and you get change back. Card payments need your own bank card in your inventory.

Other mods can run shops for accounts that aren't players: Civitas' bakeries and taverns are shop counters.

![A customer at a bakery counter](docs/img/shop.jpg)
![The owner's view: offers, stock and till](docs/img/shop_owner.jpg)

## The stock terminal

The stock terminal opens the exchange. It has four tabs.

### Stocks

- **On the left**, every listed company with its last price and today's change. Click one to select it.
- **The chart** shows the selected stock over the last two hours. One point is sampled every 30 seconds.
- **Under the chart** are the company's market value, daily dividend and today's volume.
- **The order book** shows the best bids (green) and asks (red), with bars for the size at each price.
- **Order entry**: type a quantity and press **BUY** or **SELL**.
  - With the limit field empty, it is a **market order**. It fills right away against the book, and stops before chasing the price more than 20 % away.
  - With a **limit price**, it fills what it can at that price or better. The rest **waits in the book** until the market comes to it. You are told in chat when it fills.
- **Trades** lists the latest trades: price, size and how long ago.

Every trade costs a 0.1 % broker fee. A buy limit order holds its money until it is filled or cancelled, so you can't spend it twice. Sell orders reserve the shares.

### How prices move

Every company has an underlying **value** that wanders randomly. Each company has its own volatility, 2–6 % a day.

- A **market maker** quotes bids and asks around the price, six levels deep on each side.
- **Simulated traders** buy and sell against those quotes, leaning toward the underlying value.
- **News** jumps the value up or down by 3–15 %. Big trades by players leave a lasting mark on it too.

So prices follow the news, wobble from trade to trade, and recover from sell-offs. Your resting orders get filled by the simulated traders as prices move.

### Dividends

At dawn every company pays its **dividend**, a percentage of the share price per share, into the accounts of all holders.

### Commodities

The market buys (**we pay**) and sells (**we ask**) raw goods for real items: wheat, bread, potatoes, carrots, beef, pork, leather, wool, logs, cobblestone, coal, iron, copper, gold, redstone, lapis, emeralds, diamonds and gunpowder.

- Selling a lot pushes the price down. Buying pushes it up.
- Prices drift back toward their base price over the day.
- **Sell all** sells every plain item of that kind you carry. The money goes to your bank account.

![The commodity market](docs/img/exchange_commodities.jpg)

### Portfolio and news

The portfolio shows your shares with average price, value and unrealised profit, and your open orders. Click ✕ to cancel an order. The news tab lists the latest headlines. When news concerns a company you hold, you also get it in chat.

![Portfolio](docs/img/exchange_portfolio.jpg)
![Market news](docs/img/exchange_news.jpg)

## Stock ticker

A wall-mounted LED band scrolls the latest prices and headlines. Place several side by side and they form one long display.

![A trading floor with a row of ticker boards and stock terminals](docs/img/floor.jpg)
![The ticker band up close](docs/img/ticker.jpg)

## Listed companies

The exchange opens with nine companies from around Funkstadt:

| Ticker | Company | Sector | Starting price |
|---|---|---|---|
| FUNK | Funkstadt Rundfunk AG | Media | 42.50 |
| GRID | Gridworks Energie | Utilities | 118.00 |
| FISS | Fission Kernkraft AG | Energy | 76.20 |
| RBTN | RedButton Defense Systems | Defense | 254.00 |
| RADX | Radex Dekontamination | Services | 18.75 |
| MONT | Montan Bergbau AG | Mining | 33.40 |
| HOFA | Funkenhof Agrar | Food | 27.10 |
| ATLS | Atlas Kartographie | Technology | 64.90 |
| BANK | Eurodollar Bank | Finance | 91.30 |

You can add, change or remove companies in the config. Other mods can list companies through the API: **Civitas** towns can go public.

## Commands

| Command | |
|---|---|
| `/money` | your balance, loan and the value of your shares |
| `/money pay <player> <amount>` | send money |
| `/money top` | the richest players (money plus shares) |
| `/money give\|take\|set <players> <amount>` | operators |
| `/exchange` | all quotes |
| `/exchange quote <ticker>` | details, best bid and ask |
| `/exchange buy\|sell <ticker> <qty> [limit]` | trade without a terminal (can be switched off) |
| `/exchange portfolio`, `/exchange orders`, `/exchange cancel <id>` | your holdings and orders |
| `/exchange news` | the latest headlines |
| `/exchange event <ticker> <percent>` | operators: make news |

## Configuration

`config/commerce.json`:

| Setting | Default | |
|---|---|---|
| `currencyName` / `currencyPlural` / `currencySymbol` | Eurodollar / Eurodollars / €$ | the currency |
| `startingBalance` | 250 | welcome money for new players |
| `savingsInterestPercentPerDay` | 0.05 | interest on positive balances |
| `loanInterestPercentPerDay` | 0.5 | interest on loans |
| `maxLoan` | 5000 | credit limit at the bank terminal |
| `bankCardPrice` | 5 | |
| `mobCoinDrops`, `mobCoinDropChance` | true, 0.25 | coins from hostile mobs |
| `commandTrading` | true | allow `/exchange buy/sell` |
| `exchange.stepTicks` | 20 | how often the market moves |
| `exchange.feePercent` | 0.1 | broker fee |
| `exchange.defaultVolatilityPercent` | 3 | daily volatility |
| `exchange.newsPerCompanyPerDay` | 0.4 | how often news breaks |
| `exchange.dividends` | true | |
| `exchange.commodityImpactPercent` | 1.0 | price move per lot sold or bought |
| `exchange.commoditySpreadPercent` | 6 | gap between bid and ask |
| `exchange.commodityReversionPerDay` | 0.5 | how fast prices return to base |
| `companies` | nine companies | ticker, name, sector, price, shares, dividend, volatility |
| `commodities` | 19 goods | item id, base price, lot size |

## For mod authors

`net.antwire.commerce.api.CommerceApi` gives other mods:
- accounts, transfers, minting and burning
- commodity prices, and selling to or buying from the market
- listing companies, reporting earnings, publishing news and setting dividends

`ShopBlockEntity` can belong to any account and sell to accounts without a player (`sellToAccount`). All amounts are in cents. Civitas is built on this API.

## Building from source

```
./gradlew build                 # build/libs/commerce-1.0.0.jar
./gradlew runClientGameTest     # bank, exchange, market and shop checks plus screenshots
```

Textures and models come from `tools/gen_assets.py`.

## License

MIT
