[pshaiCmd] PlaceAnyOrder
stableDescription
A handy custom command to (maybe) make it a little easier to place orders in VE.
HaasScript
DefineCommand('PlaceAnyOrder', 'Places any type of order based on inputs and market settings')
local isBuy = DefineParameter(BooleanType, 'isBuy', '', true, true, 'True, False, IsTrue, IsFalse')
local isExit = DefineParameter(BooleanType, 'isExit', '', true, false, 'True, False, IsTrue, IsFalse')
local price = DefineParameter(NumberType, 'price', 'Order price', false, 0, 'Price Data, ParseTradePrice, SessionGet')
local amount = DefineParameter(NumberType, 'amount', 'Order amount', false, TradeAmount(), 'TradeAmount, MinimumTradeAmount, ParseTradeAmount, SessionGet')
local market = DefineParameter(StringType, 'market', 'Market', false, '', 'PriceMarket, InputMarket, InputAccountMarket, SessionGet')
local type = DefineParameter(EnumType, 'orderType', 'Order type', false, LimitOrderType, 'InputOrderType, Enumerations Order Types, SessionGet')
local note = DefineParameter(StringType, 'note', 'Note', false, '', 'Text, SessionGet')
local positionId = DefineParameter(StringType, 'positionId', 'Position ID', false, '', 'SessionGet')
local timeout = DefineParameter(NumberType, 'timeout', 'Timeout in seconds', false, 0, 'Number, SessionGet')
local triggerPrice = DefineParameter(NumberType, 'triggerPrice', 'Trigger price for native order types, such as stop and take-profit', false, 0, 'Price Data, ParseTradePrice, SSessionGet')
local isSpot = MarketType(market) == SpotTrading
local cmd
if isSpot then
if (isBuy and not isExit) or (not isBuy and isExit) then
cmd = PlaceBuyOrder
elseif (isBuy and isExit) or (not (isBuy and isExit)) then
cmd = PlaceSellOrder
end
else
if isBuy and not isExit then
cmd = PlaceGoLongOrder
elseif isBuy and isExit then
cmd = PlaceExitLongOrder
elseif not (isBuy and isExit) then
cmd = PlaceGoShortOrder
elseif not isBuy and isExit then
cmd = PlaceExitShortOrder
end
end
if price == 0 then
if (isBuy and not isExit) or (not isBuy and isExit) then
price = CurrentPrice(market).bid
elseif (isBuy and isExit) or (not (isBuy and isExit)) then
price = CurrentPrice(market).ask
end
end
if triggerPrice <= 0 and
(type == StopLimitOrderType
or type == StopMarketOrderType
or type == TakeProfitLimitOrderType
or type == TakeProfitMarketOrderType)
then
LogError('Trigger price not set for ' .. type)
end
local oid = cmd(
price,
amount,
{
market = market,
type = type,
note = note,
positionId = positionId,
timeout = timeout,
triggerPrice = triggerPrice
})
DefineOutput(StringType, oid, 'Order ID')
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!