Firetron’s InputSpreadOrder

1 34 Views No Comments 2 weeks ago
  • Creates a group of inputs for Firetron’s SpreadOrder.
    Does not create an input for the orderParams parameter.

    Custom Command Dependencies:
    None

    Test Code:

    if not IsAnyOrderOpen() then
    
      local currentPrice = CurrentPrice()[1]
    
      -- Test Long Spread
    
      Log('==================================================')
      Log('Testing Long Spread, CurrentPrice: '..currentPrice)
      Log('==================================================')
    
      local input = CC_InputSpreadOrder('SpreadOrder')
    
      local p = {
        amount      = input.amount,
        amountType  = input.amountType,
        count       = input.count,
        direction   = input.direction,
        orderParams = {
          market = PriceMarket(),
          type   = NoTimeOutOrderType,
          note   = 'Long Spread',
        },
        price       = currentPrice,
        spread      = input.spread,
        spreadType  = input.spreadType,
      }
    
      local longOrders = CC_SpreadOrder(p)
    
      for i = 1, #longOrders do
    
        Log('Long Order ID: '..longOrders[i])
    
      end
    
      -- Test Short Spread
    
      Log('==================================================')
      Log('Testing Short Spread, CurrentPrice: '..currentPrice)
      Log('==================================================')
    
      p.direction   = PositionShort
      p.orderParams = {
        market = PriceMarket(),
        type   = NoTimeOutOrderType,
        note   = 'Short Spread',
      }
    
      local shortOrders = CC_SpreadOrder(p)
    
      for i = 1, #shortOrders do
    
        Log('Short Order ID: '..shortOrders[i])
    
      end
    
    end
    
    HaasScript Code
    --  ============================================================================
    --    Firetron's InputSpreadOrder
    --
    --    Creates a group of inputs for Firetron's SpreadOrder.
    --    Does not create an input for the orderParams parameter.
    --
    --    Custom Command Dependencies:
    --    None
    --
    --    Discord: @FiretronP75
    --  ============================================================================
    
    --  ========================================================
    --    Variables
    --  ========================================================
    
    --  ------------------------------------
    --    Definition
    --  ------------------------------------
    
    local description
    local inputSuggestions
    local label
    local output
    local outputSuggestions
    local tooltip
    
    --  ------------------------------------
    --    Enumeration
    --  ------------------------------------
    
    local AmountType = {
      per   = 'per',
      total = 'total',
    }
    
    local SpreadType = {
      fib     = 'fib',
      fixed   = 'fixed',
      percent = 'percent',
    }
    
    --  ------------------------------------
    --    Parameter
    --  ------------------------------------
    
    local pAmount
    local pAmountType
    local pCount
    local pDirection
    local pGroup
    local pPrice
    local pSpread
    local pSpreadType
    
    --  ========================================================
    --    Command Definition
    --  ========================================================
    
    description = 'Creates a group of inputs for Firetron\'s SpreadOrder. Does not create an input for the orderParams parameter.'
    DefineCommand('InputSpreadOrder', description)
    
    --  ========================================================
    --    Parameter Definition
    --  ========================================================
    
    description      = 'The group of the input fields.'
    inputSuggestions = 'Text'
    pGroup           = DefineParameter(StringType, 'group', description, true, 'SpreadOrder', inputSuggestions)
    
    --  ========================================================
    --    Input Definitions
    --  ========================================================
    
    label   = 'Amount'
    tooltip = 'How much to order. May be total amount or amount per order.'
    pAmount = Input(label, 1, tooltip, pGroup)
    
    label       = 'AmountType'
    tooltip     = '"total" if you specified a total amount, "per" if you specified an amount per order.'
    pAmountType = InputOptions(label, AmountType.per, AmountType, tooltip, pGroup)
    
    label   = 'Count'
    tooltip = 'How many orders to place.'
    pCount  = Input(label, 1, tooltip, pGroup)
    
    label      = 'Direction'
    tooltip    = 'PositionLong will spread long orders below the price, PositionShort will spread short orders above the price.'
    pDirection = InputConstant(label, PositionLong, tooltip, pGroup)
    
    label   = 'Price'
    tooltip = 'Price to spread out orders from. No order will be placed at this price. The first order will be placed at the spread distance away from this price.'
    pPrice  = Input(label, 1, tooltip, pGroup)
    
    label   = 'Spread'
    tooltip = 'How far to space orders apart. May be a percent, fibonacci, or fixed amount.'
    pSpread = Input(label, 1, tooltip, pGroup)
    
    label       = 'SpreadType'
    tooltip     = '"fib" if you specified a fibonacci spread, "fixed" if you specified a fixed spread, "percent" if you specified a percent spread.'
    pSpreadType = InputOptions(label, SpreadType.fixed, SpreadType, tooltip, pGroup)
    
    --  ========================================================
    --    Output Definitions
    --  ========================================================
    
    output = {
      amount      = pAmount,
      amountType  = pAmountType,
      count       = pCount,
      direction   = pDirection,
      price       = pPrice,
      spread      = pSpread,
      spreadType  = pSpreadType,
    }
    
    description       = 'ListDynamic with named elements.'
    outputSuggestions = 'CC_SpreadOrder'
    DefineOutput(ListDynamicType, output, description, outputSuggestions)
    
    description = 'How much to order. May be total amount or amount per order.'
    DefineOutputIndex( 1, NumberType, 'amount', description)
    
    description = '"total" if you specified a total amount, "per" if you specified an amount per order.'
    DefineOutputIndex( 2, StringType, 'amountType', description)
    
    description = 'How many orders to place.'
    DefineOutputIndex( 3, NumberType, 'count', description)
    
    description = 'PositionLong will spread long orders below the price, PositionShort will spread short orders above the price.'
    DefineOutputIndex( 4, EnumType, 'direction', description)
    
    description = 'Price to spread out orders from. No order will be placed at this price. The first order will be placed at the spread distance away from this price.'
    DefineOutputIndex( 5, NumberType, 'price', description)
    
    description = 'How far to space orders apart. May be a percent, fibonacci, or fixed amount.'
    DefineOutputIndex( 6, NumberType, 'spread', description)
    
    description = '"fib" if you specified a fibonacci spread, "fixed" if you specified a fixed spread, "percent" if you specified a percent spread.'
    DefineOutputIndex( 7, StringType, 'spreadType', description)
Login or Register to Comment

Unlock your crypto trading potential

Create a free account and enjoy everything we have to offer.

Join for Free