Firetron’s InputOrderOptions with reduceOnly hiddenOrder

stable
By Kobalt in Other Published July 2022 👁 1,047 views 💬 0 comments

Description

updated Firetron’s InputOrderOptions https://www.haasscripts.com/t/firetrons-inputorderoptions/ to include 9. reduceOnly - Boolean - (Optional) Ensures that the executed order does not flip the opened position. 10. hiddenOrder - Boolean - (Optional) The hidden order option ensures an order does not appear in the order book. Test script: if not Load('done', false) then -- Test Long Order Log('==================================================') Log('Testing Long Order: ') Log('==================================================') local longOptions = CC_InputOrderOptionsV4('Long Order') Log(longOptions.price) Log(longOptions.amount) Log(longOptions.market) Log(longOptions.type) Log(longOptions.note) Log(longOptions.positionId) Log(longOptions.timeout) Log(longOptions.triggerPrice) Log(longOptions.reduceOnly) Log(longOptions.hiddenOrder) local longParams = { market = longOptions.market, type = longOptions.type, note = longOptions.note, positionId = longOptions.positionId, timeout = longOptions.timeout, triggerPrice = longOptions.triggerPrice, reduceOnly = longOptions.reduceOnly, hiddenOrder = longOptions.hiddenOrder } PlaceGoLongOrder(longOptions.price, longOptions.amount, longParams) -- Test Short Order Log('==================================================') Log('Testing Short Order') Log('==================================================') local shortOptions = CC_InputOrderOptionsV4('Short Order') Log(shortOptions.price) Log(shortOptions.amount) Log(shortOptions.market) Log(shortOptions.type) Log(shortOptions.note) Log(shortOptions.positionId) Log(shortOptions.timeout) Log(shortOptions.triggerPrice) Log(shortOptions.reduceOnly) Log(shortOptions.hiddenOrder) local shortParams = { market = shortOptions.market, type = shortOptions.type, note = shortOptions.note, positionId = shortOptions.positionId, timeout = shortOptions.timeout, triggerPrice = shortOptions.triggerPrice, reduceOnly = shortOptions.reduceOnly, hiddenOrder = shortOptions.hiddenOrder } PlaceGoShortOrder(shortOptions.price, shortOptions.amount, shortParams) Save('done', true) end
HaasScript
--  ============================================================================
--    Firetron's InputOrderOptions
--
--    Creates a group of inputs for order options.
--
--    Custom Command Dependencies:
--    None
--
--    Discord: @FiretronP75
--  ============================================================================
 
--  ========================================================
--    Variables
--  ========================================================
 
--  ------------------------------------
--    Definition
--  ------------------------------------
 
local defaultValue
local description
local index
local inputSuggestions
local isRequired
local label
local name
local output
local outputSuggestions
local tooltip
local type
 
--  ------------------------------------
--    Parameter
--  ------------------------------------
 
local pAmount = TradeAmount()
local pGroup
local pIsAmountShown
local pIsMarketShown
local pIsNoteShown
local pIsPositionIdShown
local pIsPriceShown
local pIsTimeoutShown
local pIsTriggerPriceShown
local pIsReduceOnlyShown
local pIsHiddenOrderShown
local pIsTypeShown
local pMarket = PriceMarket()
local pNote = ''
local pPositionId = ''
local pPrice = -1
local pTimeout = 600
local pTriggerPrice = -1
local pReduceOnly = -1
local pHiddenOrder = -1
local pType = LimitOrderType
 
--  ========================================================
--    Command Definition
--  ========================================================
 
description = 'Creates a group of inputs for order options.'
DefineCommand('InputOrderOptionsV4', description)
 
--  ========================================================
--    Parameter Definition
--  ========================================================
 
type             = StringType
name             = 'group'
description      = 'The group of the input fields.'
isRequired       = false
defaultValue     = 'Order Options'
inputSuggestions = 'Text'
pGroup           = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
 
type             = BooleanType
name             = 'isPriceShown'
description      = 'Shows the input.'
isRequired       = false
defaultValue     = true
inputSuggestions = 'Boolean'
pIsPriceShown    = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
 
type             = BooleanType
name             = 'isAmountShown'
description      = 'Shows the input.'
isRequired       = false
defaultValue     = true
inputSuggestions = 'Boolean'
pIsAmountShown   = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
 
type             = BooleanType
name             = 'isMarketShown'
description      = 'Shows the input.'
isRequired       = false
defaultValue     = true
inputSuggestions = 'Boolean'
pIsMarketShown   = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
 
type             = BooleanType
name             = 'isTypeShown'
description      = 'Shows the input.'
isRequired       = false
defaultValue     = true
inputSuggestions = 'Boolean'
pIsTypeShown     = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
 
type             = BooleanType
name             = 'isNoteShown'
description      = 'Shows the input.'
isRequired       = false
defaultValue     = true
inputSuggestions = 'Boolean'
pIsNoteShown     = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
 
type               = BooleanType
name               = 'isPositionIdShown'
description        = 'Shows the input.'
isRequired         = false
defaultValue       = true
inputSuggestions   = 'Boolean'
pIsPositionIdShown = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
 
type             = BooleanType
name             = 'isTimeoutShown'
description      = 'Shows the input.'
isRequired       = false
defaultValue     = true
inputSuggestions = 'Boolean'
pIsTimeoutShown  = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
 
type                 = BooleanType
name                 = 'isTriggerPriceShown'
description          = 'Shows the input.'
isRequired           = false
defaultValue         = true
inputSuggestions     = 'Boolean'
pIsTriggerPriceShown = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)

type                 = BooleanType
name                 = 'isReduceOnlyShown'
description          = 'Shows the input.'
isRequired           = false
defaultValue         = true
inputSuggestions     = 'Boolean'
pIsReduceOnlyShown   = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)

type                 = BooleanType
name                 = 'isHiddenOrderShown'
description          = 'Shows the input.'
isRequired           = false
defaultValue         = true
inputSuggestions     = 'Boolean'
pIsHiddenOrderShown  = DefineParameter(type, name, description, isRequired, defaultValue, inputSuggestions)
 
--  ========================================================
--    Input Definitions
--  ========================================================
 
if pIsPriceShown then
  label        = '       Price'
  defaultValue = -1
  tooltip      = 'The price on which to execute the order. If the order is a market order, this field will be ignored.'
  pPrice       = Input(label, defaultValue, tooltip, pGroup)
end
 
if pIsAmountShown then
  label        = '      Amount'
  defaultValue = TradeAmount()
  tooltip      = 'The amount to execute.'
  pAmount      = Input(label, defaultValue, tooltip, pGroup)
end
 
if pIsMarketShown then
  label   = '     Market'
  tooltip = 'The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example.'
  pMarket = InputAccountMarket(label, tooltip, pGroup)
end
 
if pIsTypeShown then
  label        = '    Type'
  defaultValue = LimitOrderType
  tooltip      = 'The type of order. Default is limit.'
  pType        = InputOrderType(label, defaultValue, tooltip, pGroup)
end
 
if pIsNoteShown then
  label        = '   Note'
  defaultValue = ''
  tooltip      = 'A note for the order. Visible in the open orders and history.'
  pNote        = Input(label, defaultValue, tooltip, pGroup)
end
 
if pIsPositionIdShown then
  label        = '  Position ID'
  defaultValue = ''
  tooltip      = 'Optional unique internal identifier that can be used to maintain multiple separate positions.'
  pPositionId  = Input(label, defaultValue, tooltip, pGroup)
end
 
if pIsTimeoutShown then
  label        = ' Timeout'
  defaultValue = 600
  tooltip      = 'The order timeout in seconds. By default the timeout is 600 seconds / 10 minutes.'
  pTimeout     = Input(label, defaultValue, tooltip, pGroup)
end
 
if pIsTriggerPriceShown then
  label         = ' Trigger Price'
  defaultValue  = -1
  tooltip       = 'Trigger price, used for conditional orders. This parameter must only be set when using native order types that are supported by the exchange.'
  pTriggerPrice = Input(label, defaultValue, tooltip, pGroup)
end

if pIsReduceOnlyShown then
  label         = '  Reduce Only'
  defaultValue  = false
  tooltip       = 'Reduce Only, Ensures that the executed order does not flip the opened position. PlaceGoLongOrder to close Short, PlaceGoShortOrder to close Long on Spot works with PlaceSellOrder, PlaceBuyOrder. if enabled either side will only close the other.'
  pReduceOnly = Input(label, defaultValue, tooltip, pGroup)
end

if pIsHiddenOrderShown then
  label         = '  Hidden Order'
  defaultValue  = false
  tooltip       = 'The hidden order option ensures an order does not appear in the order book.'
  pHiddenOrder = Input(label, defaultValue, tooltip, pGroup)
end
--  ========================================================
--    Output Definitions
--  ========================================================
 
output = {
  price        = pPrice,
  amount       = pAmount,
  market       = pMarket,
  type         = pType,
  note         = pNote,
  positionId   = pPositionId,
  timeout      = pTimeout,
  triggerPrice = pTriggerPrice,
  reduceOnly   = pReduceOnly,
  hiddenOrder  = pHiddenOrder,
}
 
type              = ListDynamicType
description       = 'ListDynamic with named elements.'
outputSuggestions = 'Trade'
DefineOutput(type, output, description, outputSuggestions)
 
index       = 1
type        = NumberType
name        = 'price'
description = 'The price on which to execute the order. If the order is a market order, this field will be ignored.'
DefineOutputIndex(index, type, name, description)
 
index       = 2
type        = NumberType
name        = 'amount'
description = 'The amount to execute.'
DefineOutputIndex(index, type, name, description)
 
index       = 3
type        = StringType
name        = 'market'
description = 'The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example.'
DefineOutputIndex(index, type, name, description)
 
index       = 4
type        = EnumType
name        = 'type'
description = 'The type of order.'
DefineOutputIndex(index, type, name, description)
 
index       = 5
type        = StringType
name        = 'note'
description = 'A note for the order. Visible in the open orders and history.'
DefineOutputIndex(index, type, name, description)
 
index       = 6
type        = StringType
name        = 'positionId'
description = 'Optional unique internal identifier that can be used to maintain multiple separate positions.'
DefineOutputIndex(index, type, name, description)
 
index       = 7
type        = NumberType
name        = 'timeout'
description = 'The order timeout in seconds.'
DefineOutputIndex(index, type, name, description)
 
index       = 8
type        = NumberType
name        = 'triggerPrice'
description = 'Trigger price, used for conditional orders.'
DefineOutputIndex(index, type, name, description)

index       = 9
type        = BooleanType
name        = 'reduceOnly'
description = 'Reduce Only, Ensures that the executed order does not flip the opened position. '
DefineOutputIndex(index, type, name, description)

index       = 10
type        = BooleanType
name        = 'hiddenOrder'
description = 'The hidden order option ensures an order does not appear in the order book.'
DefineOutputIndex(index, type, name, description)

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!