# placeOrder()

Places an order according to the specified directives.

  • Interface
class MidaTradingAccount {
    placeOrder (directives: MidaOrderDirectives): Promise<MidaOrder>;
}

# Market orders

Market orders are executed as soon as possible at the current market conditions.

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

const myOrder = await myAccount.placeOrder({
    symbol: "BTCUSDT",
    direction: MidaOrderDirection.BUY,
    volume: 1,
});
  • Example 2
import { MidaOrderDirection, MidaOrderTimeInForce, } from "@reiryoku/mida";

const myOrder = await myAccount.placeOrder({
    symbol: "#AAPL",
    direction: MidaOrderDirection.SELL,
    timeInForce: MidaOrderTimeInForce.FILL_OR_KILL,
    volume: 1,
});
  • Example 3
import { MidaOrderDirection, decimal, } from "@reiryoku/mida";

const myOrder = await myAccount.placeOrder({
    symbol: "SATS",
    direction: MidaOrderDirection.BUY,
    volume: decimal("0.00000000000000001"),
});

# Limit orders

Limit orders are executed at different conditions depending on the order direction. Buy limit orders are executed when the ask price is equal or less than the limit price, sell limit orders are executed when the bid price is equal or greater than the limit price.

  • Example






 


import { MidaOrderDirection, } from "@reiryoku/mida";

const myOrder = await myAccount.placeOrder({
    symbol: "XAUUSD",
    direction: MidaOrderDirection.SELL,
    volume: 1,
    limit: 2000,
});

# Stop orders

Stop orders are executed at different conditions depending on the order direction. Buy stop orders are executed when the ask price is equal or greater than the stop price, sell stop orders are executed when the bid price is equal or less than the stop price.

  • Example






 


import { MidaOrderDirection, } from "@reiryoku/mida";

const myOrder = await myAccount.placeOrder({
    symbol: "XAUUSD",
    direction: MidaOrderDirection.SELL,
    volume: 1,
    stop: 2000,
});

# Time in force

Time in force can be passed in the directives.

  • Example











 
 


import {
    MidaOrderDirection,
    MidaOrderTimeInForce,
    date,
} from "@reiryoku/mida";

const myOrder = await myAccount.placeOrder({
    symbol: "XAUUSD",
    direction: MidaOrderDirection.SELL,
    volume: 1,
    limit: 2000,
    timeInForce: MidaOrderTimeInForce.GOOD_TILL_DATE,
    expirationDate: date().addMinutes(5), // Expire in 5 minutes
});

# Impact existing positions

The position id can be passed in the directives to make the order affect an existing position.

  • Example



 




import { MidaOrderDirection, } from "@reiryoku/mida";

const myOrder = await myAccount.placeOrder({
    positionId: "12345",
    direction: MidaOrderDirection.BUY,
    volume: 1,
});

# Resolvers

By default the Promise returned by placeOrder() resolves when the order enters in one of the following states: rejected, pending, expired or executed.

The resolverEvents directive allows changing this behaviour by indicating an array of order events that will resolve the Promise. Passing an empty array will resolve the Promise immediately, this means that in most cases the returned order will still be in requested state.