# Symbol states
A trading system may operate on one or more symbols, symbol states are a way
to define a local state for every symbol used in a trading system.
A symbol state generator is a method producing the state of a symbol,
symbol state generators are defined with the dollar sign $
followed by the symbol name.
- Example 1
import { MidaTradingSystem, } from "@reiryoku/mida";
export class SuperTradingSystem extends MidaTradingSystem {
$BTCUSD () {
// BTCUSD state
}
}
- Example 2
import { MidaTradingSystem, } from "@reiryoku/mida";
export class SuperTradingSystem extends MidaTradingSystem {
$BTCUSD () {
const onTick = async (tick) => {
info(`Bitcoin price is ${tick.bid} USD`);
};
return {
onTick,
};
}
}
# Shared state
Part of a symbol state can be shared with the global trading system state and/or with other symbols.
- Example
import { info, MidaTradingSystem, } from "@reiryoku/mida";
export class SuperTradingSystem extends MidaTradingSystem {
$BTCUSD () {
const shared = { bid: undefined, };
const onTick = async (tick) => {
shared.bid = tick.bid;
};
return {
shared,
onTick,
};
}
async onUpdate () {
const btcUsdBid = this.shared.$BTCUSD.bid;
info(`Bitcoin price is ${btcUsdBid} USD`);
}
}