# MidaTradingSystem()
Trading systems, trading bots or expert advisors are represented by the MidaTradingSystem
class.
The first step to create a trading system is extending the MidaTradingSystem
class.
- Example 1
import { MidaTradingSystem, } from "@reiryoku/mida";
export class SuperTradingSystem extends MidaTradingSystem {
async configure () {
// Called once per instance before the first startup
// can be used as async constructor
}
async onStart () {
// Called when the trading system starts being operative
}
async onStop () {
// Called when the trading system stops being operative
}
}
TIP
A trading system has an integrated market watcher, the watched()
method
is used to configure the market watcher before the first startup of the trading system
- Example 2
import { MidaTradingSystem, MidaTimeframe, } from "@reiryoku/mida";
export class SuperTradingSystem extends MidaTradingSystem {
watched () {
return {
"BTCUSD": {
watchTicks: true,
watchPeriods: true,
timeframes: [ MidaTimeframe.H1, MidaTimeframe.D1, ],
},
};
}
async configure () {
// Called once per instance before the first startup
// can be used as async constructor
}
async onTick (tick) {
const { bid, ask, date, } = tick;
}
async onPeriodClose (period) {
const [ open, high, low, close, ] = period.ohlc;
switch (period.timeframe) {
case MidaTimeframe.H1: {
// Closed H1 candlestick
break;
}
case MidaTimeframe.D1: {
// Closed D1 candlestick
break;
}
}
}
}