Trading & Positions¶
140 functions across 11 categories.
Categories¶
- Easy Insurances (14 commands)
- Easy Safeties (19 commands)
- Order Handling (8 commands)
- Order Information (8 commands)
- Position Information (14 commands)
- Position Prices (11 commands)
- Signal Helpers (24 commands)
- Trade Actions (Managed) (5 commands)
- Trade Actions (Unmanaged) (8 commands)
- Trade Bot (4 commands)
- Trade Market Information (25 commands)
Easy Insurances¶
AbsolutePriceChange¶
Compares the average entry price to current price, absolute value-based.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
amount |
number |
No | Minimum absolute price change before the insurance agrees. |
targetPrice |
number |
No | The target price of the trade. Default is the current buy or sell price. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: boolean
Returns true if the minimum price change percentage is reached.
DisableOnLosses¶
Blocks new orders if total gain is negative after X trades .
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
tradeCount |
number |
Yes | The trade count, after which the profits start to matter. |
acceptedLoss |
number |
No | The accepted loss percentage, 0 by default. |
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: boolean
Returns true if completed trades less than [tradeCount] or when gains are positive, otherwise false.
NeverEnterWithALoss¶
Blocks enter trade when targetPrice is above the last sell order. Only works on spot and when there is no position open.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
acceptedLoss |
number |
No | The accepted loss in percentage. Default is 0. This also affects user-defined targetPrice. |
targetPrice |
number |
No | The target price of the trade. Can be used when placing orders beforehand in unmanaged trading. |
Returns: boolean
Returns true if the trade is allowed.
NeverExitWithLoss¶
Compares the average enter price to the targetPrice or current price.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
acceptedLoss |
number |
No | The accepted loss in percentage. Default is 0. This also affects user-defined targetPrice. |
targetPrice |
number |
No | The target price of the trade. Can be used when placing orders beforehand in unmanaged trading. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: boolean
Returns true if the trade is allowed.
OrderOncePerBar¶
Only allows a order to occur once per bar. Signals produced during a ordered bar are blocked.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
interval |
number |
No | Interval of the bar in minutes. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: boolean
Returns true when new bar opens or no orders occurred during a bar.
OvercomeDoubleFeeCosts¶
Calculates the target profit and makes sure the fee costs are double-covered.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
targetPrice |
number |
No | The target price of the trade. Default is the current buy or sell price. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: boolean
Returns true if the trade profit is enough to cover double the fees.
OvercomeFeeCosts¶
Calculates the target profit and makes sure the fee costs are covered.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
targetPrice |
number |
No | The target price of the trade. Default is the current buy or sell price. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: boolean
Returns true if the trade profit is enough to cover the fees.
PercentagePriceChange¶
Compares the average enter price to current price, percentage-based.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
percentage |
number |
No | Minimum percentage change before the insurance agrees. |
targetPrice |
number |
No | The target price of the trade. Default is the current buy or sell price. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: boolean
Returns true if the minimum price change percentage is reached.
StopLossCooldown¶
Blocks any signal until a certain number of minutes have passed since the last exit trade executed by a safety.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
minutes |
number |
Yes | Number of minutes to wait after the last order. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: boolean
Returns true when the last trade is a certain number of minutes ago.
TradeOncePerBar¶
Only allows a trade to occur once per bar. Signals produced during a traded bar are blocked.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
interval |
number |
No | Interval of the bar in minutes. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: boolean
Returns true when new bar opens or no trade occurred during a bar.
TradeOnlySideways¶
Checks the current market condition for sideways movement.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
threshold |
number |
No | Sideways movement threshold. |
interval |
number |
No | The ticks interval. |
fullCandles |
boolean |
No | If true, the last closed candles will be returned. |
market |
string |
No | The market of the tick. Default is the selected main market. |
Returns: boolean
Returns true if the trade is allowed.
TradeOnlyTrending¶
Checks the current market condition for a trend.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
threshold |
number |
No | Trend strength threshold. |
interval |
number |
No | The ticks interval. |
fullCandles |
boolean |
No | If true, the last closed candles will be returned. |
market |
string |
No | The market of the tick. Default is the selected main market. |
Returns: boolean
Returns true if the trade is allowed.
WaitAfterOrder¶
Blocks any signal until a certain number of minutes have passed since the last placed order. This includes orders executed in an update cycle
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
timeout |
number |
Yes | Number of minutes to wait after the last order. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: boolean
Returns true when the last placed order is a certain number of minutes ago.
WaitAfterTrade¶
Blocks any signal until a certain number of minutes have passed since the last trade.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
timeout |
number |
Yes | Number of minutes to wait after the last trade. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: boolean
Returns true when the last trade is a certain number of minutes ago.
Easy Safeties¶
ChandelierStopLoss¶
Calculates the chandelier exit long/short price and compares it with the current price.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
depth |
number |
No | Depth length. Default is 20. |
multiplier |
number |
No | ATR multiplier. Default is 3. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
direction |
enum |
No | The direction of the position. PositionLong or PositionShort. By default both. |
Returns: boolean
Returns true if the stop loss price have been breached.
DeactivateAfterEnterOrder¶
Deactivates the bot after an enter order has been completed.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionCount |
number |
No | Number of position allowed before the check is preformed. |
Returns: boolean
Returns true when the bot has been deactivated.
DeactivateAfterExitOrder¶
Deactivates the bot after an exit order has been completed.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionCount |
number |
No | Number of position allowed before the check is preformed. |
Returns: boolean
Returns true when the bot has been deactivated.
DeactivateAfterXActiveMinutes¶
Deactivates the bot when the is active for a certain time.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
minutes |
number |
Yes | Number of positions allowed before the bot is deactivated. |
Returns: boolean
Returns true when the bot has been deactivated.
DeactivateAfterXIdleMinutes¶
Deactivates the bot if the last completed order is a number of minutes in the past. Timeout starts after the first completed order.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
minutes |
number |
Yes | Number of positions allowed before the bot is deactivated. |
Returns: boolean
Returns true when the bot has been deactivated.
DeactivateAfterXOrders¶
Deactivates the bot after a number of orders has been completed.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
count |
number |
No | Number of orders allowed before the bot is deactivated. |
Returns: boolean
Returns true when the bot has been deactivated.
DeactivateAfterXPositions¶
Deactivates the bot after a number of positions has been completed.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
count |
number |
No | Number of positions allowed before the bot is deactivated. |
Returns: boolean
Returns true when the bot has been deactivated.
DeactivateOnLoss¶
Deactivates the bot when there is no open position and the ROI based losses have reached a certain level.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
maxLoss |
number |
Yes | Maximum allowed loss based on the ROI. |
Returns: boolean
Returns true when the bot has been deactivated.
DeactivateOnProfit¶
Deactivates the bot when there is no open position and the ROI based profits have reached a certain level.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
minProfit |
number |
Yes | Minimum profit based on the ROI. |
Returns: boolean
Returns true when the bot has been deactivated.
DynamicStopLoss¶
Calculates the dynamic stop loss price and compares it with the current exit price.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
percentage |
number |
Yes | Price pump percentage. |
depth |
number |
No | Read depth. Default is 30 ticks. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
direction |
enum |
No | The direction of the position. PositionLong or PositionShort. By default both. |
Returns: boolean
Returns true is the stop loss price has been breached.
DynamicTakeProfit¶
Calculates the dynamic take profit price and compares it with the current exit price.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
percentage |
number |
Yes | Price pump percentage. |
depth |
number |
No | Read depth. Default is 30 ticks. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
direction |
enum |
No | The direction of the position. PositionLong or PositionShort. By default both. |
Returns: boolean
Returns true is the take profit price has been breached.
GrowingTrailingStopLoss¶
Keeps track of the highest/lowest recorded price and adjust the stop loss accordingly. The higher the price change the more the trailing distances grows.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
percentage |
number |
Yes | Trailing stop loss percentage. |
growPercentage |
number |
Yes | The grow percentage. 0.035 for example. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
direction |
enum |
No | The direction of the position. PositionLong or PositionShort. By default both. |
Returns: boolean
Returns true if the stop loss has been hit.
ShrinkingTrailingStopLoss¶
Keeps track of the highest/lowest recorded price and adjust the stop loss accordingly. The higher the price change the more the trailing distances shrinks.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
percentage |
number |
Yes | Trailing stop loss percentage. |
shrinkPercentage |
number |
Yes | This percentage will be added to the stop every time the stop adjust. The percentage will raise exponentially on every adjustment. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
direction |
enum |
No | The direction of the position. PositionLong or PositionShort. By default both. |
Returns: boolean
Returns true if the stop loss has been hit.
StopLoss¶
Calculates the current percentage change from the average enter price and compares it with the stop loss value.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
percentage |
number |
Yes | Stop loss percentage. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
direction |
enum |
No | The direction of the position. PositionLong or PositionShort. By default both. |
Returns: boolean
Returns true if the stop loss has been hit.
StopLossROI¶
Calculates the defined position's current ROI percentage and gives a signal if the set loss is reached.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
percentage |
number |
Yes | Stop loss ROI percentage. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
direction |
enum |
No | The direction of the position. PositionLong or PositionShort. By default both. |
Returns: boolean
Returns true if the stop loss has been hit.
TakeProfit¶
Calculates the current percentage change from the average enter price and compares it with the take profit value.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
percentage |
number |
Yes | Take profit percentage. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
direction |
enum |
No | The direction of the position. PositionLong or PositionShort. By default both. |
Returns: boolean
Returns true if the take profit has been reached.
TakeProfitROI¶
Calculates the defined position's current ROI percentage and gives a signal if the set profit is reached.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
percentage |
number |
Yes | Take profit ROI percentage. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
direction |
enum |
No | The direction of the position. PositionLong or PositionShort. By default both. |
Returns: boolean
Returns true if the take profit has been reached.
TrailingArmStopLoss¶
Keeps track of the highest/lowest recorded price and adjust the stop loss accordingly when the arm% has been reached.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
percentage |
number |
Yes | Trailing stop loss percentage. |
arm |
number |
Yes | The Arm percentage. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
direction |
enum |
No | The direction of the position. PositionLong or PositionShort. By default both. |
Returns: boolean
Returns true if the stop loss has been hit.
TrailingStopLoss¶
Keeps track of the highest/lowest recorded price and adjust the stop loss accordingly.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
percentage |
number |
Yes | Trailing stop loss percentage. |
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
direction |
enum |
No | The direction of the position. PositionLong or PositionShort. By default both. |
Returns: boolean
Returns true if the stop loss has been hit.
Order Handling¶
CancelAllOrders¶
Cancels all open orders.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: void
CancelOrder¶
Sends out a cancel order for the given order identifier.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
orderId |
string |
Yes | Unique order identifier provided by the PlaceOrder commands. |
Returns: void
IsAnyOrderFinished¶
Checks if there are any open orders completed/cancelled.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: boolean
Returns true if there are any open orders completed/cancelled.
IsAnyOrderOpen¶
Checks if there are any open orders.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: boolean
Returns true if there are any open orders.
IsBuyOrder¶
Checks if the given order is a buy order.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
orderId |
string |
Yes | Unique order identifier provided by the PlaceOrder commands. |
Returns: boolean
Returns true if the given order is on buy side.
IsOrderFilled¶
Checks if the given order is filled.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
orderId |
string |
Yes | Unique order identifier provided by the PlaceOrder commands. |
Returns: boolean
Returns true if the given order is filled.
IsOrderOpen¶
Checks if the given order is still open.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
orderId |
string |
Yes | Unique order identifier provided by the PlaceOrder commands. |
Returns: boolean
Returns true if the given order is still open.
IsSellOrder¶
Checks if the given order is a sell order.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
orderId |
string |
Yes | Unique order identifier provided by the PlaceOrder commands. |
Returns: boolean
Returns true if the given order is on sell side.
Order Information¶
GetAllFilledOrders¶
A collection of (partially) filled orders executed by the bot. Maximum size is 50 orders.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. When set only orders related to that position are returned. |
Returns: dynamic
Returns a list of OrderContainer() objects. Sorted descending on close timestamp.
GetAllOpenOrders¶
A collection of open orders executed by the bot.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. When set only orders related to that position are returned. |
Returns: dynamic
Returns a list of OrderContainer() objects.
GetFailedOrderMessage¶
The reason for the order failure.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
orderId |
string |
Yes | Unique order identifier provided by the PlaceOrder commands. |
Returns: string
Returns a string with the reason for the order failure.
GetOrderCancelledAmount¶
Calculates the cancelled amount if the order is completed/cancelled.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
orderId |
string |
Yes | Unique order identifier provided by the PlaceOrder commands. |
Returns: number
Returns the cancelled amount if the order is completed/cancelled.
GetOrderFilledAmount¶
Calculates the amount filled for a specific order.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
orderId |
string |
Yes | Unique order identifier provided by the PlaceOrder commands. |
afterFees |
boolean |
No | If true, the fee cost are subtracted from the total amount if they are paid in the base currency. |
Returns: number
Returns the amount filled for a specific order.
GetOrderOpenTime¶
Calculates how long an order is or has been open in minutes.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
orderId |
string |
Yes | Unique order identifier provided by the PlaceOrder commands. |
inSeconds |
boolean |
No | If set on true, the timespan will be in seconds. |
Returns: number
Returns the time the order is or has been open for in minutes.
GetOrderProfit¶
Calculates the realized profits of the order.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
orderId |
string |
Yes | Unique order identifier provided by the PlaceOrder commands. |
Returns: number
Returns gross profits of the order.
OrderContainer¶
Gets all the information from an specific order.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
orderId |
string |
Yes | Unique order identifier provided by the PlaceOrder commands. |
Returns: dynamic
Returns an array with order information.
Position Information¶
AdjustVPosition¶
Adjusts a virtual bot position by processing a simulated order using the defined specifications. Works similarly to PlaceExitLongOrder/PlaceExitShortOrder, but will NOT create a real order; only simulated!
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
price |
number |
Yes | The close price of the position. |
amount |
number |
Yes | The amount to adjust: negative value reduces, positive value adds. |
positionId |
string |
No | Unique position identifier. |
Returns: void
CloseVPosition¶
Closes a virtual bot position entirely by processing a simulated order using the defined specifications. Works similarly to DoExitPosition and PlaceExitPositionOrder, but will NOT create a real order; only simulated! Use this to "clean up" bot positions if required.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
price |
number |
Yes | The enter price of the position. |
positionId |
string |
No | Unique position identifier. |
Returns: void
CreatePosition¶
Creates a bot position by processing a simulated order using the defined specifications. By doing this, profit/loss and position details can be used by the script. Use the returned position ID with PositionContainer() to extract position data.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
direction |
enum |
Yes | The direction of the position. |
price |
number |
Yes | The enter price of the position. |
amount |
number |
Yes | The size of the position. |
market |
string |
No | The market of the position. |
leverage |
number |
No | The leverage of the position. -1 for default. |
positionId |
string |
No | Unique position identifier. |
Returns: string
Returns the position ID.
GetAllOpenPositions¶
Gets all open positions and returns them as PositionContainers.
Returns: dynamic
Returns an array of PositionContainers.
GetPositionAmount¶
Gets the total amount open in a specific position.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: number
Returns the total amount open in a specific position.
GetPositionDirection¶
Gets the direction of a specific position.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: enum
Returns PositionLong, PositionShort or NoPosition.
GetPositionEnterPrice¶
Gets the average enter price of an open position.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
includeClosed |
boolean |
No | True for total position amount (default), false for only open amount. |
Returns: number
Returns the average enter price.
GetPositionMarket¶
Gets the market of an open position.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: string
Returns the account, market & leverage as a single string.
GetPositionProfit¶
Gets the total realized plus unrealized profit of a specific position.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
targetPrice |
number |
No | Optional target price. Default is the best bid/ask. |
Returns: number
Returns the total realized plus unrealized profit of a specific position. On spot/margin the result will be in the quote currency. For leverage its in the underlying currency.
GetPositionROI¶
Calculates the ROI based on used margin and unrealized + realized profits.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
targetPrice |
number |
No | Optional target price. Default is the best bid/ask. |
Returns: number
Returns the ROI as a percentage.
IsPositionClosed¶
Checks whether or not a position is closed.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: boolean
Returns true if position is closed, otherwise false.
LongAmount¶
Gets the total amount open in a long position.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: number
Returns the total amount open in a long position.
PositionContainer¶
Gets all the information from the open bot position.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
includeClosed |
boolean |
No | True for total position amount (default), false for only open amount. Affects enterPrice value in returned object. |
Returns: dynamic
Returns an array with position information.
ShortAmount¶
Gets the total amount open in a short position.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: number
Returns the total amount open in a short position.
Position Prices¶
AverageEnterPrice¶
Gets the average enter price.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
includeClosed |
boolean |
No | True for total position amount (default), false for only open amount. |
Returns: number
Returns the average enter price.
AverageExitPrice¶
Gets the average exit price.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: number
Returns the average exit price.
LastExitLongPrice¶
Gets the last used exit long price.
Returns: number
Returns the last used exit long price.
LastExitPositionPrice¶
Gets the last used exit short or long price.
Returns: number
Returns the last used exit short or long price.
LastExitShortPrice¶
Gets the last used exit short price.
Returns: number
Returns the last used exit short price.
LastLongPrice¶
Gets the last enter long price.
Returns: number
Returns the last enter long price.
LastLongProfit¶
Gets the profit of the last long exit or sell trade.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: number
Returns the profit.
LastLongROI¶
Gets the last long position ROI.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: number
Returns the last long position ROI.
LastShortPrice¶
Gets the last enter short price.
Returns: number
Returns the last enter short price.
LastShortProfit¶
Gets the profit of the last short exit or buy trade.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: number
Returns the profit.
LastShortROI¶
Gets the last short position ROI.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
Returns: number
Returns the last short position ROI.
Signal Helpers¶
BoolToSignal¶
Converts 4 boolean values to a signal.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
isLong |
boolean |
No | When true, SignalLong will be returned. |
isShort |
boolean |
No | When true, SignalShort will be returned. |
isExit |
boolean |
No | When true, SignalExitPosition will be returned. |
isNone |
boolean |
No | When true, SignalNone will be returned. |
Returns: enum
The signal as a result of the boolean values.
ConvertSignal¶
Aliases: MapSignal
Converts the signal if its matches the defined one.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signal |
enum |
Yes | The original signal. |
signalToCovert |
enum |
Yes | The signal we want to convert. |
convertedSignal |
enum |
Yes | The signal we want to convert too. |
Returns: enum
Returns the original or converted signal depending on the input.
DelaySignal¶
Saves and delays a signal by a number of minutes.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signal |
enum |
Yes | The original signal. |
minutes |
number |
Yes | The number of minutes of the delay. |
Returns: enum
Returns the saved signal from a number of minutes back or SignalNone when it doesn't have a delayed signal yet.
GetAboveBelowSignal¶
Returns a continuous signal when values are above/below of each other.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
fast |
number |
Yes | The 'faster' value. |
slow |
number |
Yes | The 'slower' value. |
Returns: enum
Returns SignalLong when fast is above slow, SignalShort when fast is below slow and SignalNone will occur if values are exactly the same.
GetBuySellLevelSignal¶
Determines the signal from a result with a buy and sell level.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
value |
number |
Yes | The value to compare. |
buyLevel |
number |
Yes | Below this value, a DoLong() is executed. |
sellLevel |
number |
Yes | Above this value, a DoShort() is executed. |
Returns: enum
Returns SignalLong when the result is below the buy level, SignalShort when the result is above the sell level and SignalNone when the result between the buy and sell level.
GetConsensusSignal¶
Counts the number of signals. When the majority agrees it will return the signal.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signals[] |
EnumParams |
Yes | Indicator signals collection. Takes a variable number of arguments. |
Returns: enum
Returns SignalLong, SignalShort, SignalExitPosition or SignalNone when there is a consensus or SignalNone when there is not.
GetCrossOverUnderSignal¶
Determines the signal from a result with a crossover or -under level.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
fast |
number|table |
Yes | The 'faster' value. |
slow |
number|table |
Yes | The 'slower' value. |
Returns: enum
Returns SignalLong when the a crossover occurs, SignalShort when a crossunder occurs and SignalNone when non one those happened.
GetRemoteSignal¶
Gets the remote signal which is published by SaveRemoteSignal()
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
id |
string |
Yes | The unique identifier of the signal. |
Returns: enum
Returns a trade signal enumeration. For example SignalLong(), SignalShort(), SignalExitPosition(), SignalNone() or SignalError().
GetSuperSignal¶
Returns a continuous trade signal with defined signal type and values.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
indicatorValue |
HaasNumberCollection |
Yes | The 'faster' or indicator value. |
signalValue |
HaasNumberCollection |
Yes | The 'slower' or signal value. |
signalType |
enum |
Yes | The signal type which defines how the inputs are interpreted. |
centerPosition |
number |
No | The center position for 'Zero Cross' signal types. 0 for indicators that oscillate below and above zero, 50 for indicators like RSI, MFI and STOCH. |
buyLevel |
number |
No | The buy level for 'Threshold' signal types. Used for indicators like RSI, MFI and STOCH. |
sellLevel |
number |
No | The sell level for 'Threshold' signal types. Used for indicators like RSI, MFI and STOCH. |
Returns: enum
Returns a signal based on defined 'signalType' (see InputSignalTypes()).
GetThresholdSignal¶
Determines the signal based on a result and a threshold.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
value |
number |
Yes | The value to compare. |
threshold |
number |
Yes | Below this value, a SignalLong is returned. If its above a SignalShort. |
swing |
number |
No | Minimum swing below or above the threshold before a signal is returned. |
Returns: enum
Returns SignalLong when the result is below the threshold and SignalShort when the result is above the threshold.
GetUnanimousSignal¶
Validates if all signals are the same.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signals[] |
EnumParams |
Yes | Indicator signals collection. Takes a variable number of arguments. |
Returns: enum
Returns SignalLong, SignalShort or SignalNone when there is unanimous decision and SignalNone when there is not.
GetWebHookSignal¶
Gets the latest incoming webhook signal by ID. Triggers immediate script execution when a webhook arrives, bypassing the normal minute tick interval — use this for high-performance signal-based trading.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
id |
string |
Yes | The webhook signal ID to listen for. Must match the key used in the incoming PUSH_SIGNAL webhook request. |
Returns: dynamic
Returns the latest signal payload stored by the incoming webhook, or nil if no signal has been received.
GetWeightedConsensusSignal¶
Calculates and determines the weighted consensus signal.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
longWeight |
number |
Yes | The required sum of the long signals weight before the signal is valid. |
shortWeight |
number |
Yes | The required sum of the short signals weight before the signal is valid. |
exitWeight |
number |
Yes | The required sum of the exit signals weight before the signal is valid. |
signals[] |
EnumParams |
Yes | Indicator signals collection. Takes a variable number of arguments. |
Returns: enum
Returns SignalLong, SignalShort, SignalExitPosition or SignalNone when there is a consensus or SignalNone when there is not.
HindSightSignal¶
Uses hindsight to tell if its the best moment to long or short
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
period |
number |
Yes | Hindsight view period length. |
Returns: enum
Returns a trading signal
IgnoreSignalIf¶
Marks the signal to be ignored when it matches a certain signal.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signal |
enum |
Yes | The original signal. |
signalToIgnore |
enum |
Yes | The signal to ignore. SignalLong, SignalShort or SignalExitPosition. |
Returns: enum
Returns the original signal.
PositionToBool¶
Converts a position value to 3 boolean values.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
position |
enum |
Yes | Bot position enum. PositionLong, PositionShort or NoPosition. |
Returns: dynamic
Three boolean values based on the position input.
ReverseSignal¶
Reverses a signal from long to short or short to long. SignalNone will be ignored and stay the same.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signal |
enum |
Yes | The original signal. |
Returns: enum
Returns the reversed signal.
SaveRemoteSignal¶
This command can save and distribute a trading signal over the HaasCloud. This can be used in combination with trade signal enumeration. For example SignalLong(), SignalShort(), SignalExitPosition() or SignalNone().
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
id |
string |
Yes | The unique identifier of the signal. |
secret |
string |
Yes | The secret key on which to save the signal. |
signal |
enum |
Yes | The signal enum to save. |
Returns: void
SignalMapper¶
Maps a signal value to their defined specifications.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signal |
enum |
Yes | The original signal. |
reverse |
boolean |
No | If true, the signals are revered. |
mapLongTo |
enum |
No | The mapped long signal. |
mapShortTo |
enum |
No | The mapped short signal. |
mapExitTo |
enum |
No | The mapped exit signal. |
mapNoneTo |
enum |
No | The mapped none signal. |
Returns: enum
The mapped signal.
SignalProperties¶
Sets properties such as weight or ignore in the signal input.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signal |
enum |
Yes | The original signal. |
useLong |
boolean |
No | When true, this signal is used for long decisions. |
useShort |
boolean |
No | When true, this signal is used for short decisions. |
useExit |
boolean |
No | When true, this signal is used for exit decisions. |
weight |
number |
No | The weight of the signal. Minimum weight of 1 required. |
delay |
number |
No | Number of minutes the signal will be delayed. |
Returns: enum
Returns the signal with the new specifications.
SignalToBool¶
Converts a signal value to 4 boolean values.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signal |
enum |
Yes | The original signal. |
Returns: dynamic
Four boolean values based on the signal input.
SignalToLog¶
Logs the given signals.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signals |
EnumParams |
Yes | The signals to log. |
Returns: void
SignalWeight¶
Add a weight to the signal. Can be used in combination with GetWeightedConsensusSignal().
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signal |
enum |
Yes | The original signal. |
weight |
number |
Yes | The weight of the signal. Minimum weight of 1 required. |
Returns: enum
Returns the original signal with a weight mark.
UseSignalIf¶
Marks the signal to be used when its matches a certain signal.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signal |
enum |
Yes | The original signal. |
signalToUse |
enum |
Yes | The signal to ignore. SignalLong, SignalShort or SignalExitPosition. |
Returns: enum
Returns the original signal.
Trade Actions (Managed)¶
DoExitPosition¶
Sends out a sell signal on spot or an exit positions signal on margin & leverage.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
note |
string |
No | A note for the order. Visible in the open orders and history. |
count |
number |
No |
Returns: void
DoFlipPosition¶
Executes a DoLong() when the current position is short and an DoShort() the position is long.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
note |
string |
No | A note for the order. Visible in the open orders and history. |
Returns: void
DoLong¶
Aliases: DoBuy
Generates a buy signal on spot or a long signal on margin & leverage.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
note |
string |
No | A note for the order. Visible in the open orders and history. |
count |
number |
No |
Returns: void
DoShort¶
Aliases: DoSell
Generates a sell signal on spot or a short signal on margin & leverage.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
note |
string |
No | A note for the order. Visible in the open orders and history. |
count |
number |
No |
Returns: void
DoSignal¶
Processes a signal enum. Triggers a DoLong() when the signal equals SignalLong, a DoShort() when the signal equals SignalShort, a DoExitPosition() when the signal equals SignalExitPosition and does nothing when the signal is SignalNone.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signal |
enum |
Yes | The signal to process. |
note |
string |
No | A note for the order. Visible in the open orders and history. |
Returns: void
Trade Actions (Unmanaged)¶
PlaceBuyOrder¶
PlaceBuyOrder(price, amount, [market], [type], [note], [positionId], [timeout], [triggerPrice], [reduceOnly], [hiddenOrder])
Places a (limit) buy order for the given amount and price. Returns the order identifier (text).
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
price |
number |
Yes | The price on which to execute the order. If the order is a market order, this field will be ignored. |
amount |
number |
Yes | The amount to execute. |
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
type |
enum |
No | The type of order. Default is limit. |
note |
string |
No | A note for the order. Visible in the open orders and history. |
positionId |
string |
No | Optional unique internal identifier that can be used to maintain multiple separate positions. |
timeout |
number |
No | The order timeout in seconds. By default the timeout is 600 seconds / 10 minutes. Using a negative value will disable the timeout. |
triggerPrice |
number |
No | Trigger price, used for conditional orders. This parameter must only be set when using native order types that are supported by the exchange. |
reduceOnly |
boolean |
No | Ensures that the executed order does not flip the opened position. |
hiddenOrder |
boolean |
No | The hidden order option ensures an order does not appear in the order book. |
Returns: string
Unique order identifier.
PlaceCancelledOrder¶
Executes the remaining amount of a canceled order.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
orderId |
string |
Yes | Unique order identifier. Returned by the PlaceOrder commands. |
price |
number |
No | The price on which to execute. Be defaults the best ask or bid price is used. |
Returns: string
Returns an new order identifier. Empty if no order is executed.
PlaceExitLongOrder¶
PlaceExitLongOrder(price, amount, [market], [type], [note], [positionId], [timeout], [triggerPrice], [reduceOnly], [hiddenOrder])
Places a (limit) exit long order for the given amount and price. Returns the order identifier (text).
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
price |
number |
Yes | The price on which to execute the order. If the order is a market order, this field will be ignored. |
amount |
number |
Yes | The amount to execute. |
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
type |
enum |
No | The type of order. Default is limit. |
note |
string |
No | A note for the order. Visible in the open orders and history. |
positionId |
string |
No | Optional unique internal identifier that can be used to maintain multiple separate positions. |
timeout |
number |
No | The order timeout in seconds. By default the timeout is 600 seconds / 10 minutes. Using a negative value will disable the timeout. |
triggerPrice |
number |
No | Trigger price, used for conditional orders. This parameter must only be set when using native order types that are supported by the exchange. |
reduceOnly |
boolean |
No | Ensures that the executed order does not flip the opened position. |
hiddenOrder |
boolean |
No | The hidden order option ensures an order does not appear in the order book. |
Returns: string
Unique order identifier.
PlaceExitPositionOrder¶
Places exit orders for a specific bot position.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
positionId |
string |
No | Optional unique identifier. Required when the bot is trading multiple position at once. |
price |
number |
No | The price on which to execute. Be defaults the best ask or bid price is used. |
type |
enum |
No | Order type used for the order. |
note |
string |
No | A note for the order. Visible in the open orders and history. |
timeout |
number |
No | The order timeout in seconds. By default the timeout is 600 seconds / 10 minutes except for NoTimeOutOrderType. |
Returns: string
Returns an order identifier.
PlaceExitShortOrder¶
PlaceExitShortOrder(price, amount, [market], [type], [note], [positionId], [timeout], [triggerPrice], [reduceOnly], [hiddenOrder])
Places a (limit) exit short order for the given amount and price. Returns the order identifier (text).
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
price |
number |
Yes | The price on which to execute the order. If the order is a market order, this field will be ignored. |
amount |
number |
Yes | The amount to execute. |
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
type |
enum |
No | The type of order. Default is limit. |
note |
string |
No | A note for the order. Visible in the open orders and history. |
positionId |
string |
No | Optional unique internal identifier that can be used to maintain multiple separate positions. |
timeout |
number |
No | The order timeout in seconds. By default the timeout is 600 seconds / 10 minutes. Using a negative value will disable the timeout. |
triggerPrice |
number |
No | Trigger price, used for conditional orders. This parameter must only be set when using native order types that are supported by the exchange. |
reduceOnly |
boolean |
No | Ensures that the executed order does not flip the opened position. |
hiddenOrder |
boolean |
No | The hidden order option ensures an order does not appear in the order book. |
Returns: string
Unique order identifier.
PlaceGoLongOrder¶
PlaceGoLongOrder(price, amount, [market], [type], [note], [positionId], [timeout], [triggerPrice], [reduceOnly], [hiddenOrder])
Places a (limit) go long order for the given amount and price. Returns the order identifier (text).
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
price |
number |
Yes | The price on which to execute the order. If the order is a market order, this field will be ignored. |
amount |
number |
Yes | The amount to execute. |
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
type |
enum |
No | The type of order. Default is limit. |
note |
string |
No | A note for the order. Visible in the open orders and history. |
positionId |
string |
No | Optional unique internal identifier that can be used to maintain multiple separate positions. |
timeout |
number |
No | The order timeout in seconds. By default the timeout is 600 seconds / 10 minutes. Using a negative value will disable the timeout. |
triggerPrice |
number |
No | Trigger price, used for conditional orders. This parameter must only be set when using native order types that are supported by the exchange. |
reduceOnly |
boolean |
No | Ensures that the executed order does not flip the opened position. |
hiddenOrder |
boolean |
No | The hidden order option ensures an order does not appear in the order book. |
Returns: string
Unique order identifier.
PlaceGoShortOrder¶
PlaceGoShortOrder(price, amount, [market], [type], [note], [positionId], [timeout], [triggerPrice], [reduceOnly], [hiddenOrder])
Places a (limit) go short order for the given amount and price. Returns the order identifier (text).
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
price |
number |
Yes | The price on which to execute the order. If the order is a market order, this field will be ignored. |
amount |
number |
Yes | The amount to execute. |
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
type |
enum |
No | The type of order. Default is limit. |
note |
string |
No | A note for the order. Visible in the open orders and history. |
positionId |
string |
No | Optional unique internal identifier that can be used to maintain multiple separate positions. |
timeout |
number |
No | The order timeout in seconds. By default the timeout is 600 seconds / 10 minutes. Using a negative value will disable the timeout. |
triggerPrice |
number |
No | Trigger price, used for conditional orders. This parameter must only be set when using native order types that are supported by the exchange. |
reduceOnly |
boolean |
No | Ensures that the executed order does not flip the opened position. |
hiddenOrder |
boolean |
No | The hidden order option ensures an order does not appear in the order book. |
Returns: string
Unique order identifier.
PlaceSellOrder¶
PlaceSellOrder(price, amount, [market], [type], [note], [positionId], [timeout], [triggerPrice], [reduceOnly], [hiddenOrder])
Places a (limit) sell order for the given amount and price. Returns the order identifier (text).
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
price |
number |
Yes | The price on which to execute the order. If the order is a market order, this field will be ignored. |
amount |
number |
Yes | The amount to execute. |
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
type |
enum |
No | The type of order. Default is limit. |
note |
string |
No | A note for the order. Visible in the open orders and history. |
positionId |
string |
No | Optional unique internal identifier that can be used to maintain multiple separate positions. |
timeout |
number |
No | The order timeout in seconds. By default the timeout is 600 seconds / 10 minutes. Using a negative value will disable the timeout. |
triggerPrice |
number |
No | Trigger price, used for conditional orders. This parameter must only be set when using native order types that are supported by the exchange. |
reduceOnly |
boolean |
No | Ensures that the executed order does not flip the opened position. |
hiddenOrder |
boolean |
No | The hidden order option ensures an order does not appear in the order book. |
Returns: string
Unique order identifier.
Trade Bot¶
IndicatorContainer¶
Merges multiple signals into a single list and determines the unanimous and consensus signal.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signals[] |
EnumParams |
No | Indicator signals. Takes a variable number of arguments. |
Returns: dynamic
Returns a list with on index 1 the array with signals, on index 2 the unanimous and on index 3 the consensus signal.
InsuranceContainer¶
Validates if all the signals agree.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signals[] |
...boolean |
No | Safety signals collection. Takes a variable number of arguments. |
Returns: boolean
Returns true if all the signals in the collection are true.
SafetyContainer¶
Checks a collection for active safety signals.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
signals[] |
...boolean |
No | Safety signals collection. Takes a variable number of arguments. |
Returns: boolean
Returns true if any of the signals is active.
TradeBotContainer¶
Checks the safety, indicator & insurance signal. If a safety is active, DoExitPosition() will be executed. When there are no safeties active, the indicator signal will be executed if the insurances agree.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
safetySignal |
boolean |
No | Safety container result. |
indicatorSignal |
enum |
No | Indicator container result. |
insuranceSignal |
boolean |
No | Insurance container result. |
Returns: void
Trade Market Information¶
AmountDecimals¶
Returns a number of how many decimals is allowed for order amounts.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
amount |
number |
No |
Returns: number
Returns the allowed decimal count.
AmountLabel¶
Aliases: AmountCurrency
Gets the amount label. For reflection, in case the market is Bitstamp BTC/USDit will return 'BTC'. When we are on BitMEX XBT/USD (XBTUSD), it will return 'contract(s)'.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: string
Returns the amount label as string.
AmountStep¶
Returns the minimum allowed trade amount step for market.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: number
Returns the trade amount step size.
BaseCurrency¶
Returns the base currency of the market. For reflection, in case we are on Bitstamp BTC/USD it will return 'BTC'.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: string
Returns the base currency as string.
ContractName¶
Gets the contract name of the market.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: string
Returns the contract name of the market.
ContractType¶
Gets the contract type of the market (Vanilla, Inverse, or Quanto). Returns nil for spot/margin markets without contract details.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: dynamic
Returns VanillaContract, InverseContract, QuantoContract, or nil.
ContractValue¶
Gets the value of a single contract, defined in their denomination.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: number
Returns the value of a single contract, defined in their denomination.
GetAccountMarkets¶
An array of markets affiliated with a particular account.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
accountId |
string |
No | The guid returned by AccountGuid(), InputAccount or InputAccountMarket for example. |
Returns: dynamic
Returns an array with all the markets as a string.
GetExchangeMarkets¶
An array of markets affiliated with a particular exchange.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
exchangeCode |
string |
Yes | The exchange code affiliated with the exchange. |
Returns: dynamic
Returns an array with all the markets as a string.
IsTradeAmountEnough¶
Gets whether or not the trade amount is high enough for exchange limits.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
Yes | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
price |
number |
Yes | The price on which to check the trade amount. |
amount |
number |
Yes | The amount to check. |
logWarning |
boolean |
No | If true, a warning is logged. |
Returns: boolean
Returns whether or not the trade amount is high enough for exchange limits.
IsValidMarket¶
Checks if the input is a valid market.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
Yes | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: boolean
Returns true if the market is valid.
MakersFee¶
Gets makers fee of the market.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: number
Returns makers fee of the market.
MarketType¶
Gets the market type enumeration of the market.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: enum
Returns SpotTrading, MarginTrading or LeverageTrading.
MinimumTradeAmount¶
Calculates the minimum trade amount on a certain price while keeping exchange specifications in consideration.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
price |
number |
No | The price on which to calculate the trade amount. By default the close price is used. |
Returns: number
Returns the minimum trade amount taking the decimal count, minimum amount and volume into account.
ParseTradeAmount¶
Parses the trade amount to exchange specifications.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
Yes | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
price |
number |
Yes | The price on which to parse the trade amount. |
amount |
number |
Yes | The amount to parse. |
Returns: number
Returns the trade amount adjusted for exchange specifications.
ParseTradePrice¶
Parses the trade price to exchange specifications.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
Yes | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
price |
number |
Yes | The price on which to check the trade amount. |
Returns: number
Returns the trade price adjusted for exchange specifications.
PriceDecimals¶
Aliases: QuoteDecimals
Returns a number of how many decimals is allowed for order prices.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
price |
number |
No | Specific price value. This can have an effect on the number of decimals. |
Returns: number
Returns the allowed decimal count.
PriceStep¶
Aliases: QuoteStep
Returns the minimum allowed price step for market.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: number
Returns the price step size.
ProfitLabel¶
Aliases: ProfitCurrency
Returns the profit label. For reflection, in case the market is Bitstamp BTC/USD it will return 'USD'. When we are on BitMEX XBT/USD (XBTUSD), it will return 'XBT'.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: string
Returns the profit label as string.
QuoteCurrency¶
Returns the quote currency of the market. For reflection, in case we are on Bitstamp BTC/USD it will return 'USD'.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: string
Returns the quote currency as string.
SetFee¶
Saves a custom fee percentage which is used in back tests and returned by Fee().
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
percentage |
number |
Yes | Fee percentage to store. |
market |
string |
No | The guid returned by AccountGuid(), InputAccount or InputAccountMarket for example. |
Returns: void
TakersFee¶
Gets takers fee of the market.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: number
Returns takers fee of the market.
TradeMarketContainer¶
Retrieves all the information on the trade market.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: dynamic
Returns the market information on an array.
UnderlyingAsset¶
Returns the underlying assets of the market. For reflection, in case we are on Bitstamp BTC/USD it will return 'BTC'. When we are on BitMEX XBT/USD (XBTUSD), it will return 'XBT'.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
No | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
Returns: string
Returns the underlying assets as string.
UsedMargin¶
Calculates the used margin for a specific position.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
market |
string |
Yes | The market returned by PriceMarket(), InputAccountMarket() or InputMarket() for example. |
price |
number |
Yes | Position price. |
amount |
number |
Yes | Position amount. |
leverage |
number |
Yes | Leverage ratio. Use 0 for cross-margin. |
Returns: number
Returns the amount in the underlying currency value.
Auto-generated from HaasScript source code.