Interface BotContext

interface BotContext {
    cancelClosePosition(): boolean;
    closePosition(type:
        | "none"
        | "all"
        | "half"
        | "quarter"): boolean;
    getAveragePercentPrice(percent: string | number, props?: {
        move?: "up" | "down";
        priceType?: PositionHandlerPriceType;
        shiftMove?: "up" | "down";
        shiftPrice?: number;
        shiftSize?: number;
    }): Decimal;
    getAveragePrice(priceType: PositionHandlerPriceType): Decimal;
    noPositionMinutes(minutes: number): boolean;
    pause(): boolean;
    reset(): boolean;
    resetDCA(): boolean;
    setBaseOrder(value: any, props?: {
        max?: number;
        min?: number;
        step?: number;
        throttle?: number;
    }): boolean;
    setEnterCustomPrice(value: any, props?: {
        max?: number;
        min?: number;
        step?: number;
        throttle?: number;
    }): boolean;
    setEnterType(value: "askPrice" | "customPrice"): boolean;
    setLoss(props: {
        [Name: string]: LimitProps | OROProps | OCOProps;
    }): boolean;
    setMaxPriceDeviation(value: any, props?: {
        max?: number;
        min?: number;
        step?: number;
        throttle?: number;
    }): boolean;
    setMaxUsage(value: any, props?: {
        max?: number;
        min?: number;
        step?: number;
        throttle?: number;
    }): boolean;
    setPriceDeviation(value: any, props?: {
        max?: number;
        min?: number;
        step?: number;
        throttle?: number;
    }): boolean;
    setProfit(props: {
        [Name: string]: LimitProps | OROProps | OCOProps;
    }): boolean;
    setSOStepScale(value: any, props?: {
        max?: number;
        min?: number;
        step?: number;
        throttle?: number;
    }): boolean;
    setSOVolumeScale(value: any, props?: {
        max?: number;
        min?: number;
        step?: number;
        throttle?: number;
    }): boolean;
    setSafetyOrder(value: any, props?: {
        max?: number;
        min?: number;
        step?: number;
        throttle?: number;
    }): boolean;
    start(): boolean;
}

Methods

  • Used to cancel a sell order that closes entire position. Close position is a market order. This action may not trigger fast enough during regular market hours as compared to extended market hours.

    Returns boolean

    tick = (i, bot, utils) => {
    ...
    if(...){
    bot.cancelClosePosition();
    }
    }
  • Used to sell all the shares of a stock at the current market price. This method is useful when the user wants to exit a position quickly and lock in profits or losses.

    Parameters

    • type:
          | "none"
          | "all"
          | "half"
          | "quarter"

      bot action close position

      'all'

    Returns boolean

    tick = (i, bot, utils) => {
    ...
    if(...){
    bot.closePosition();
    }
    }
  • getAveragePercentPrice *

    Parameters

    • percent: string | number
    • Optionalprops: {
          move?: "up" | "down";
          priceType?: PositionHandlerPriceType;
          shiftMove?: "up" | "down";
          shiftPrice?: number;
          shiftSize?: number;
      }
      • Optionalmove?: "up" | "down"

        'up'

      • OptionalpriceType?: PositionHandlerPriceType

        'boughtAverage'

      • OptionalshiftMove?: "up" | "down"

        'up'

      • OptionalshiftPrice?: number
      • OptionalshiftSize?: number

        1

    Returns Decimal

    // example averagePrice=10
    bot.getAveragePercentPrice(1)
    // result 11

    // example averagePrice=10
    bot.getAveragePercentPrice(1, {move: 'down'})
    // result 9

    // example averagePrice=10
    bot.getAveragePercentPrice(1, {move: 'up', shiftPrice: 12, shiftMove: 'up'})
    // result 12

    // example averagePrice=10
    bot.getAveragePercentPrice(1, {move: 'up', shiftPrice: 9, shiftMove: 'up'})
    // result 11
  • Used to monitor the duration of time when no position is open when bot is started. This method is useful when the user wants to apply a time-based strategy for monitoring their bot start trigger.

    Parameters

    • minutes: number

    Returns boolean

    tick = (i, bot, utils) => {
    ...
    if(bot.noPositionMinutes(5)){
    ...
    }
    }

    Reset bot state to wait for new trigger:

    tick = (i, bot, utils) => {
    ...
    if(bot.noPositionMinutes(5)){
    bot.reset();
    }
    }

    Reset bot buy to retry at current price:

    tick = (i, bot, utils) => {
    ...
    if(bot.noPositionMinutes(5)){
    bot.resetDCA();
    }
    }
  • Used to temporarily stop the bot from placing any new orders. This method does not close the existing position or cancel any pending orders. This method is useful when the user wants to pause the bot’s activity for any reason.

    Returns boolean

    tick = (i, bot, utils) => {
    ...
    if(...){
    bot.pause();
    }
    }
  • Used to reset the bot to neutral state. This method does not close an existing open position. This method will not cancel all the pending orders. This method is useful when the user wants to stop trading with the bot, or to reset the bot to neutral state to be ready for new trades. User must manage any leftover open position.

    Returns boolean

    tick = (i, bot, utils) => {
    ...
    if(...){
    bot.reset();
    }
    }
  • Used to restart the bot from the current open position without closing it. This method allows the user to continue adding orders to the existing position based on the bot’s strategy. This method is useful when the user wants to adjust the bot’s settings or parameters without exiting the position.

    Returns boolean

    tick = (i, bot, utils) => {
    ...
    if(...){
    bot.resetDCA();
    }
    }
  • Used to set the initial amount of money to invest in a stock. This method requires a number as a parameter, which indicates how much money in dollars to use for the first order. This method is useful when the user wants to control the risk and reward of their strategy.

    Parameters

    • value: any
    • Optionalprops: {
          max?: number;
          min?: number;
          step?: number;
          throttle?: number;
      }
      • Optionalmax?: number
      • Optionalmin?: number
      • Optionalstep?: number
      • Optionalthrottle?: number

    Returns boolean

    tick = (i, bot, utils) => {
    bot.setBaseOrder(...)
    ...
    }
  • Used to set the custom price for the entry order if using setEnterType custom price. This method requires a number as a parameter, which indicates what price to use for placing the entry order. This method is useful when the user wants to enter a position at a specific price that they think is favorable.

    Parameters

    • value: any
    • Optionalprops: {
          max?: number;
          min?: number;
          step?: number;
          throttle?: number;
      }
      • Optionalmax?: number
      • Optionalmin?: number
      • Optionalstep?: number
      • Optionalthrottle?: number

    Returns boolean

    tick = (i, bot, utils) => {
    bot.setEnterCustomPrice(...)
    ...
    }
  • Used to set the type of entry order to use when opening a position. This method requires a string as a parameter, which can be either “ask” or “custom”. An ask order is executed at the current ask price, which is the lowest price that someone is willing to sell at. A custom order is executed at a specified price that the user chooses. This method is useful when the user wants to choose between speed and accuracy for their entry order.

    Parameters

    • value: "askPrice" | "customPrice"

    Returns boolean

    tick = (i, bot, utils) => {
    bot.setEnterType(...)
    ...
    }
  • Used to set the maximum deviation of the current market price from the last order price to place a new order. This method requires a number as a parameter, which indicates how much deviation in percentage to allow for placing a new order. This method is useful when the user wants to specify max price deviation regardless of actual price deviation set.

    Parameters

    • value: any
    • Optionalprops: {
          max?: number;
          min?: number;
          step?: number;
          throttle?: number;
      }
      • Optionalmax?: number
      • Optionalmin?: number
      • Optionalstep?: number
      • Optionalthrottle?: number

    Returns boolean

    tick = (i, bot, utils) => {
    bot.setMaxPriceDeviation(...)
    ...
    }
  • Used to set the maximum percentage of the budget to use for trading. This method requires a number as a parameter, which indicates how much percentage of the budget to allocate for trading. This method is useful when the user wants to limit their exposure and risk in the market.

    Parameters

    • value: any
    • Optionalprops: {
          max?: number;
          min?: number;
          step?: number;
          throttle?: number;
      }
      • Optionalmax?: number
      • Optionalmin?: number
      • Optionalstep?: number
      • Optionalthrottle?: number

    Returns boolean

    tick = (i, bot, utils) => {
    bot.setMaxUsage(...)
    ...
    }
  • Used to set the deviation of the current market price from the average entry price to place a new order. This method requires a number as a parameter, which indicates how much deviation in percentage to use for placing a new order.

    Parameters

    • value: any
    • Optionalprops: {
          max?: number;
          min?: number;
          step?: number;
          throttle?: number;
      }
      • Optionalmax?: number
      • Optionalmin?: number
      • Optionalstep?: number
      • Optionalthrottle?: number

    Returns boolean

    tick = (i, bot, utils) => {
    bot.setPriceDeviation(...)
    ...
    }
  • Used to set the scale factor for increasing the distance between each safety order. This method requires a number as a parameter, which indicates how much to multiply the distance between each safety order by. This method is useful when the user wants to avoid placing safety orders too close or too far from each other.

    Parameters

    • value: any
    • Optionalprops: {
          max?: number;
          min?: number;
          step?: number;
          throttle?: number;
      }
      • Optionalmax?: number
      • Optionalmin?: number
      • Optionalstep?: number
      • Optionalthrottle?: number

    Returns boolean

    tick = (i, bot, utils) => {
    bot.setSOStepScale(...)
    ...
    }
  • Used to set the scale factor for sizing the volume of each safety order. This method requires a number as a parameter, which indicates how much to multiply the volume of each safety order by. This method is useful when the user wants to increase their exposure and potential profit as the market price moves further away from their direction.

    Parameters

    • value: any
    • Optionalprops: {
          max?: number;
          min?: number;
          step?: number;
          throttle?: number;
      }
      • Optionalmax?: number
      • Optionalmin?: number
      • Optionalstep?: number
      • Optionalthrottle?: number

    Returns boolean

    tick = (i, bot, utils) => {
    bot.setSOVolumeScale(...)
    ...
    }
  • Used to set the number of additional orders to place after the base order. This method requires a number as a parameter, which indicates the safety orders position quantity to use for averaging down the entry price. This method is useful when the user wants to reduce the risk of losing money when the market price goes against their direction.

    Parameters

    • value: any
    • Optionalprops: {
          max?: number;
          min?: number;
          step?: number;
          throttle?: number;
      }
      • Optionalmax?: number
      • Optionalmin?: number
      • Optionalstep?: number
      • Optionalthrottle?: number

    Returns boolean

    tick = (i, bot, utils) => {
    bot.setSafetyOrder(...)
    ...
    }
  • Used to activate the bot and begin executing orders based on the bot’s strategy. This method is useful when the user wants to start trading with the bot or resume from bot paused state.

    Returns boolean

    tick = (i, bot, utils) => {
    ...
    if(...){
    bot.start();
    }
    }