Build a fake stock market: five companies from the code whose prices move randomly every hour, /stocks shows the board with each company\'s last ten prices drawn as a small chart by the image model, /stocks buy and /stocks sell trade shares with MEE6 coins, and /portfolio shows a member\'s holdings and profit
A stock market game where members trade shares of five companies (TechCorp, EnergyCo, FinanceGroup, RetailMart, PharmaTech) using MEE6 coins. Hourly price updates start automatically when the creation is deployed; no setup command is needed. Prices update randomly every hour, and members can view their portfolio with profit/loss tracking.
Commands:
/stocks view — View current prices for all companies/stocks buy — Buy shares of a company/stocks sell — Sell shares of a company/portfolio — View your holdings and total profit/lossPrices move randomly between -10% and +10% each hour, with a floor of 10 coins to prevent crashes.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
Current prices for all companies
Price: 100 coins (opens on the next hourly tick)
Price: 75 coins (opens on the next hourly tick)
Price: 120 coins (opens on the next hourly tick)
Price: 50 coins (opens on the next hourly tick)
Price: 90 coins (opens on the next hourly tick)

✅ Purchased 2 shares of TECH at 100 coins each. Total: 200 coins.
✅ Purchased 3 shares of ENRG at 75 coins each. Total: 225 coins.
Current prices for all companies
Price: 110 coins 📈 +10
Price: 70 coins 📉 -5
Price: 116 coins 📉 -4
Price: 47 coins 📉 -3
Price: 90 coins ➡️ +0

Shares: 2 | Value: 220 coins | P/L: 📈 +20
✅ Sold 1 shares of TECH at 110 coins each. Total: 110 coins.
Shares: 3 | Value: 210 coins | P/L: 📉 -15
// Stock Market: trade shares with MEE6 coins, prices move randomly every hour
const COMPANIES = [
{ id: 'tech', name: 'TechCorp', ticker: 'TECH', basePrice: 100 },
{ id: 'energy', name: 'EnergyCo', ticker: 'ENRG', basePrice: 75 },
{ id: 'finance', name: 'FinanceGroup', ticker: 'FING', basePrice: 120 },
{ id: 'retail', name: 'RetailMart', ticker: 'RETL', basePrice: 50 },
{ id: 'pharma', name: 'PharmaTech', ticker: 'PHRM', basePrice: 90 },
];
interface PriceHistory {
prices: number[]; // last 10 prices
lastUpdate: number;
}
interface Portfolio {
[companyId: string]: number; // shares owned
}
/** Initialize prices if they don't exist */
async function initializePrices() {
for (const company of COMPANIES) {
const existing = await mee6.store.get<PriceHistory>(`price_${company.id}`);
if (!existing) {
await mee6.store.set(`price_${company.id}`, {
prices: [company.basePrice],
lastUpdate: Date.now(),
});
}
}
}
/** Update all prices with random movements */
async function updatePrices() {
for (const company of COMPANIES) {
const history = await mee6.store.get<PriceHistory>(`price_${company.id}`);
if (!history) continue;
const lastPrice = history.prices[history.prices.length - 1];
// Random movement: -10% to +10%
const change = (Math.random() - 0.5) * 0.2;
const newPrice = Math.max(10, Math.round(lastPrice * (1 + change)));
const newPrices = [...history.prices, newPrice].slice(-10); // keep last 10
await mee6.store.set(`price_${company.id}`, {
prices: newPrices,
lastUpdate: Date.now(),
});
}
}
// A call moves at most 1,000,000,000 coins, the Economy plugin's own balance
// cap: so does one sale. A buy is bounded by the buyer's balance already.
const MAX_TRADE = 1_000_000_000;
/** The refusal for a sale above MAX_TRADE, naming the most shares one trade can move. */
function tooBig(price: number): string {
return `A trade moves at most ${MAX_TRADE.toLocaleString(
'en-US'
)} coins: at ${price} coins a share, that is ${Math.floor(MAX_TRADE / price)} shares at once.`;
}
/** Get current price for a company */
async function getCurrentPrice(companyId: string): Promise<number> {
const history = await mee6.store.get<PriceHistory>(`price_${companyId}`);
if (!history) return COMPANIES.find((c) => c.id === companyId)!.basePrice;
return history.prices[history.prices.length - 1];
}
/** The board as one picture: for each company, its last ten prices as bars. */
async function drawBoard(histories: { company: typeof COMPANIES[number]; prices: number[] }[]): Promise<string> {
const width = 800;
const height = 300;
const panel = width / histories.length;
const layers: any[] = [];
histories.forEach(({ company, prices }, i) => {
const x0 = i * panel + 12;
const min = Math.min(...prices);
const max = Math.max(...prices);
const range = max - min || 1;
const barW = Math.floor((panel - 24) / 10);
const last = prices[prices.length - 1];
const first = prices[0];
const color = last >= first ? '#57F287' : '#ED4245';
layers.push({ type: 'text', text: company.ticker, x: x0, y: 20, size: 22, weight: 'bold', color: '#FFFFFF' });
layers.push({ type: 'text', text: `${last} coins`, x: x0, y: 50, size: 16, color: '#B9BBBE' });
prices.forEach((price, j) => {
const h = 20 + Math.round(((price - min) / range) * 160);
layers.push({ type: 'rect', x: x0 + j * barW, y: 270 - h, width: barW - 3, height: h, color, radius: 2 });
});
});
return await mee6.draw({ width, height, background: '#2C2F33', layers });
}
// Prices move every hour from the moment the creation is deployed; the
// first tick starts every company at its base price.
mee6.schedule.every('price_update', 3600);
mee6.on('scheduled', async (ctx) => {
if (ctx.scheduleKey === 'price_update') {
await initializePrices();
await updatePrices();
}
});
// View market
mee6.command('stocks view', { description: 'View the stock market' }, async (ctx) => {
const fields = [];
const histories: { company: typeof COMPANIES[number]; prices: number[] }[] = [];
for (const company of COMPANIES) {
const history = await mee6.store.get<PriceHistory>(`price_${company.id}`);
histories.push({ company, prices: history?.prices ?? [company.basePrice] });
if (!history) {
fields.push({
name: `${company.ticker} - ${company.name}`,
value: `Price: ${company.basePrice} coins (opens on the next hourly tick)`,
inline: true,
});
continue;
}
const currentPrice = history.prices[history.prices.length - 1];
const prevPrice = history.prices.length > 1 ? history.prices[history.prices.length - 2] : currentPrice;
const change = currentPrice - prevPrice;
const changeSymbol = change > 0 ? '📈' : change < 0 ? '📉' : '➡️';
fields.push({
name: `${company.ticker} - ${company.name}`,
value: `Price: **${currentPrice}** coins ${changeSymbol} ${change >= 0 ? '+' : ''}${change}`,
inline: true,
});
}
const board = await drawBoard(histories);
await ctx.reply({
files: [{ url: board, name: 'stocks.png' }],
embed: {
title: '📊 Stock Market',
description: 'Current prices for all companies',
fields,
color: '#00ff00',
image_url: 'attachment://stocks.png',
footer: { text: 'Prices update every hour' },
},
});
});
// Buy shares
mee6.command(
'stocks buy',
{
description: 'Buy shares of a company',
options: [
{
name: 'company',
type: 'string',
description: 'Which company',
required: true,
choices: COMPANIES.map((c) => ({ name: `${c.ticker} - ${c.name}`, value: c.id })),
},
{ name: 'shares', type: 'integer', description: 'How many shares', required: true },
],
},
async (ctx) => {
const companyId = ctx.option<string>('company');
const shares = ctx.option<number>('shares');
const company = COMPANIES.find((c) => c.id === companyId);
if (!company) return;
if (shares <= 0) {
await ctx.reply('You must buy at least 1 share.');
return;
}
const price = await getCurrentPrice(companyId);
const totalCost = price * shares;
const balance = await mee6.economy.balance(ctx.author.id);
if (balance.coins < totalCost) {
await ctx.reply(`Not enough coins! You need ${totalCost} coins but have ${balance.coins}.`);
return;
}
await mee6.economy.remove(ctx.author.id, totalCost);
const m = mee6.store.member(ctx.author.id);
const portfolio = await m.get<Portfolio>('portfolio', {});
portfolio[companyId] = (portfolio[companyId] || 0) + shares;
await m.set('portfolio', portfolio);
// Track cost basis for profit calculation
const costBasis = await m.get<number>(`cost_${companyId}`, 0);
await m.set(`cost_${companyId}`, costBasis + totalCost);
await ctx.reply(
`✅ Purchased ${shares} shares of **${company.ticker}** at ${price} coins each. Total: ${totalCost} coins.`
);
}
);
// Sell shares
mee6.command(
'stocks sell',
{
description: 'Sell shares of a company',
options: [
{
name: 'company',
type: 'string',
description: 'Which company',
required: true,
choices: COMPANIES.map((c) => ({ name: `${c.ticker} - ${c.name}`, value: c.id })),
},
{ name: 'shares', type: 'integer', description: 'How many shares', required: true },
],
},
async (ctx) => {
const companyId = ctx.option<string>('company');
const shares = ctx.option<number>('shares');
const company = COMPANIES.find((c) => c.id === companyId);
if (!company) return;
if (shares <= 0) {
await ctx.reply('You must sell at least 1 share.');
return;
}
const m = mee6.store.member(ctx.author.id);
const portfolio = await m.get<Portfolio>('portfolio', {});
const owned = portfolio[companyId] || 0;
if (owned < shares) {
await ctx.reply(`You only own ${owned} shares of **${company.ticker}**.`);
return;
}
const price = await getCurrentPrice(companyId);
const totalRevenue = price * shares;
if (totalRevenue > MAX_TRADE) {
await ctx.reply(tooBig(price));
return;
}
await mee6.economy.add(ctx.author.id, totalRevenue);
portfolio[companyId] = owned - shares;
if (portfolio[companyId] === 0) delete portfolio[companyId];
await m.set('portfolio', portfolio);
// Update cost basis proportionally
const costBasis = await m.get<number>(`cost_${companyId}`, 0);
const newCostBasis = costBasis * ((owned - shares) / owned);
if (newCostBasis > 0) {
await m.set(`cost_${companyId}`, newCostBasis);
} else {
await m.delete(`cost_${companyId}`);
}
await ctx.reply(
`✅ Sold ${shares} shares of **${company.ticker}** at ${price} coins each. Total: ${totalRevenue} coins.`
);
}
);
// View portfolio
mee6.command('portfolio', { description: 'View your portfolio and profit/loss' }, async (ctx) => {
const m = mee6.store.member(ctx.author.id);
const portfolio = await m.get<Portfolio>('portfolio', {});
const holdings = Object.keys(portfolio);
if (holdings.length === 0) {
await ctx.reply('You have no shares. Use `/stocks buy` to invest!');
return;
}
const fields = [];
let totalValue = 0;
let totalCost = 0;
for (const companyId of holdings) {
const company = COMPANIES.find((c) => c.id === companyId);
if (!company) continue;
const shares = portfolio[companyId];
const currentPrice = await getCurrentPrice(companyId);
const value = shares * currentPrice;
const costBasis = await m.get<number>(`cost_${companyId}`, 0);
const profit = value - costBasis;
const profitSymbol = profit > 0 ? '📈' : profit < 0 ? '📉' : '➡️';
totalValue += value;
totalCost += costBasis;
fields.push({
name: `${company.ticker} - ${company.name}`,
value: `Shares: ${shares} | Value: ${value} coins | P/L: ${profitSymbol} ${profit >= 0 ? '+' : ''}${profit}`,
inline: false,
});
}
const totalProfit = totalValue - totalCost;
const profitSymbol = totalProfit > 0 ? '📈' : totalProfit < 0 ? '📉' : '➡️';
await ctx.reply({
embed: {
title: `📊 ${ctx.author.displayName}'s Portfolio`,
fields,
color: totalProfit >= 0 ? 0x00ff00 : 0xff0000,
footer: {
text: `Total Value: ${totalValue} coins | Total P/L: ${profitSymbol} ${
totalProfit >= 0 ? '+' : ''
}${totalProfit} coins`,
},
},
});
});