# Customizers

Customizers can be used to shape the behaviour of trading engines and accounts.

# Commission customizer

Commissions can be added through a commission customizer, a custom function that given the order and the details of the upcoming trade, returns a commission for the respective trade.

  • Example
import { decimal, } from "@reiryoku/mida";

// Used to set a fixed commission of 1 USD to all trades
engine.setCommissionCustomizer(() => [ "USD", decimal(1), ]);

// Used to set a commission relative to the traded volume
engine.setCommissionCustomizer((order, upcomingTrade) => {
    return [
        upcomingTrade.executedVolume.multiply(1), // Commission = 1 USD per lot

# Latency customizer

Latency and slippage can be simulated through a latency customizer, a custom function called when a trading account places an order.

  • Example 1
// Set a latency of 1 second when placing an order, this means that 1 second of ticks
// will be elapsed before actually placing the order
myAccount.setLatencyCustomizer(() => 1);
  • Example 2
import { generateInRandomFloat, } from "@reiryoku/mida";

// Set a random latency bewteen 0.1 and 2 seconds when placing an order
myAccount.setLatencyCustomizer(() => generateInRandomFloat(0.1, 2));