Firetron’s InputAmountSpread

1 107 Views No Comments 1 month ago
  • Creates a group of inputs for Firetron’s GetAmountSpread.

    Custom Command Dependencies:
    None

    Test code:

    if not Load('done', false) then
    
      local p = {listDynamic = CC_InputAmountSpread('Amount Spread')}
    
      local spreadAmounts = CC_GetAmountSpread(p)
    
      for i = 1, #spreadAmounts do
    
        Log('Spread Amount: '..spreadAmounts[i])
    
      end
    
      Save('done', true)
    
    end
    • This topic was modified 1 month ago by Firetron. Reason: Updated test script to use new parameter: listDynamic
    • This topic was modified 1 month ago by Firetron. Reason: Removed unused vars
    • This topic was modified 1 month ago by Firetron. Reason: Added "mult" option
    • This topic was modified 1 month ago by Firetron. Reason: Added "exp" option
    • This topic was modified 3 weeks, 3 days ago by Firetron. Reason: Added offset input
    • This topic was modified 2 weeks, 4 days ago by Firetron. Reason: Cleaned up test script
    • This topic was modified 2 weeks, 4 days ago by Firetron. Reason: Added parameter: total
    HaasScript Code
    --  ============================================================================
    --    Firetron's InputAmountSpread
    --
    --    Creates a group of inputs for Firetron's GetAmountSpread.
    --
    --    Custom Command Dependencies:
    --    None
    --
    --    Discord: @FiretronP75
    --  ============================================================================
    
    --  ========================================================
    --    Variables
    --  ========================================================
    
    --  ------------------------------------
    --    Definition
    --  ------------------------------------
    
    local defaultValue
    local description
    local index
    local inputSuggestions
    local isRequired
    local label
    local name
    local options
    local output
    local outputSuggestions
    local tooltip
    local type
    
    --  ------------------------------------
    --    Enumeration
    --  ------------------------------------
    
    local SpreadType = {
      exp   = 'exp',
      fib   = 'fib',
      mult  = 'mult',
      per   = 'per',
      total = 'total',
    }
    
    --  ------------------------------------
    --    Parameter
    --  ------------------------------------
    
    local pCount
    local pGroup
    local pOffset
    local pSpreadFactor
    local pSpreadType
    local pTotal
    
    --  ========================================================
    --    Command Definition
    --  ========================================================
    
    name        = 'InputAmountSpread'
    description = 'Creates a group of inputs for Firetron\'s GetAmountSpread.'
    DefineCommand(name, description)
    
    --  ========================================================
    --    Parameter Definition
    --  ========================================================
    
    type             = StringType
    name             = 'group'
    description      = 'The group of the input fields.'
    isRequired       = false
    defaultValue     = 'Amount Spread'
    inputSuggestions = 'Text'
    pGroup           = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
    
    --  ========================================================
    --    Input Definitions
    --  ========================================================
    
    label        = 'Count'
    defaultValue = 1
    tooltip      = 'How many amounts are in the spread.'
    pCount       = Input(label, defaultValue, tooltip, pGroup)
    
    label         = 'Offset'
    defaultValue  = 0
    tooltip       = 'How many amounts to skip over at the start of the spread.'
    pOffset       = Input(label, defaultValue, tooltip, pGroup)
    
    label         = 'Spread Factor'
    defaultValue  = 1
    tooltip       = 'How much to order. May be total amount or amount per order or fibonacci amount per order or multiplied amount per order or exponential ammount per order.'
    pSpreadFactor = Input(label, defaultValue, tooltip, pGroup)
    
    label        = 'Spread Type'
    defaultValue = SpreadType.per
    options      = SpreadType
    tooltip      = '"total" if you specified a total amount, "per" if you specified an amount per order, "fib" if you specified a fibonacci amount per order, "mult" if you specified an amount to be multiplied by the order index, "exp" if you specified an amount to be exponentially multiplied by the order index.'
    pSpreadType  = InputOptions(label, defaultValue, options, tooltip, pGroup)
    
    label        = 'Total'
    defaultValue = 0
    tooltip      = 'Total amount to divide up. Set to 0 to disable. If enabled, each value in the amount spread will be converted to a rationed amount of the total. When the spreadType is "total" this is redundant.'
    pTotal       = Input(label, defaultValue, tooltip, pGroup)
    
    --  ========================================================
    --    Output Definitions
    --  ========================================================
    
    output = {
      count        = pCount,
      offset       = pOffset,
      spreadFactor = pSpreadFactor,
      spreadType   = pSpreadType,
      total        = pTotal,
    }
    
    type              = ListDynamicType
    description       = 'ListDynamic with named elements.'
    outputSuggestions = 'CC_GetAmountSpread'
    DefineOutput(type, output, description, outputSuggestions)
    
    index       = 1
    type        = NumberType
    name        = 'count'
    description = 'How many amounts are in the spread.'
    DefineOutputIndex(index, type, name, description, outputSuggestions)
    
    index       = 2
    type        = NumberType
    name        = 'offset'
    description = 'How many amounts to skip over at the start of the spread.'
    DefineOutputIndex(index, type, name, description, outputSuggestions)
    
    index       = 3
    type        = NumberType
    name        = 'spreadFactor'
    description = 'How much to order. May be total amount or amount per order or fibonacci amount per order or multiplied amount per order or exponential ammount per order.'
    DefineOutputIndex(index, type, name, description, outputSuggestions)
    
    index       = 4
    type        = StringType
    name        = 'spreadType'
    description = '"total" if you specified a total amount, "per" if you specified an amount per order, "fib" if you specified a fibonacci amount per order, "mult" if you specified an amount to be multiplied by the order index, "exp" if you specified an amount to be exponentially multiplied by the order index.'
    DefineOutputIndex(index, type, name, description, outputSuggestions)
    
    index       = 5
    type        = NumberType
    name        = 'total'
    description = 'Total amount to divide up. Set to 0 to disable. If enabled, each value in the amount spread will be converted to a rationed amount of the total. When the spreadType is "total" this is redundant.'
    DefineOutputIndex(index, type, name, description, outputSuggestions)
Login or Register to Comment

Unlock your crypto trading potential

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

Join for Free