Framework error codes
The following section describes the code values of an Sway.Result object – error codes in the framework. Almost all the error codes relate to trading requests.
All the values described in this section are in the Sway.ErrorCodes enumeration, for example Sway.ErrorCodes.OKAY.
8.1 Success/no-failure values
There are three values which are treated by Sway.Result as isOkay=true and isError=false:
Sway.ErrorCodes.
Description
OKAY
No error; success
SUCCESS
Synonym for OKAY; same numeric value (zero)
CANCELLED
Action cancelled or dismissed by the user
NO_ACTION_REQUIRED
No action. For example, a trading request such as FLATTEN when there are no open orders or trades on the account.
All the remaining values represent error conditions, and the Sway.Result will report isOkay=false and isError=true.
8.2 Not-yet-implemented errors
The following errors are not currently issued by the framework under any circumstances. But in future they may be issued if e.g. the implementation of some functionality is specific to each broker back-end platform, and Sway Charts Pro has only completed the integration with some platforms:
Sway.ErrorCodes.
Description
NOTYETIMPLMENTED
Functionality has not yet been implemented.
TR_NOTYETIMPLEMENTED
More specifically, trading functionality which has not yet been implemented
8.3 Failed internal validation of trading actions
The following error codes represent failed internal validation of trading actions – e.g. no trading volume specified – before trying to pass them to the broker's back-end system.
Sway.ErrorCodes.
Description
TR_INVALIDJOBDEFINITION
Invalid request definition for a trading job (generally invalid, rather than a problem such as TR_NOVOLUME)
TR_BADINSTRUMENT
Unrecognised or missing instrumentId
TR_BELOWMINIMUMVOLUME
Specified volume is below the minimum for the market
TR_CANTUSEBREAKEVENONPENDING
Attempt to set break-even exit on a pending order rather than an open trade
TR_TRADESLWRONGSIDEOFBID
Stop-loss on an open buy trade is the wrong side of the current (bid) price
TR_TRADESLWRONGSIDEOFASK
Stop-loss on an open sell trade is the wrong side of the current (ask) price
TR_TRADETPWRONGSIDEOFBID
Take-profit on an open buy trade is the wrong side of the current (bid) price
TR_TRADETPWRONGSIDEOFASK
Take-profit on an open sell trade is the wrong side of the current (ask) price
TR_ORDERSLWRONGSIDEOFBUYENTRY
Stop-loss on a pending buy order is the wrong side of the entry price for the order
TR_ORDERSLWRONGSIDEOFSELLENTRY
Stop-loss on a pending sell order is the wrong side of the entry price for the order
TR_ORDERTPWRONGSIDEOFBUYENTRY
Take-profit on a pending buy order is the wrong side of the entry price for the order
TR_ORDERTPWRONGSIDEOFSELLENTRY
Take-profit on a pending sell order is the wrong side of the entry price for the order
TR_ACCOUNTREADONLY
Access to the trading account is read-only and trading is not permitted (Account.accountReadOnly = true)
TR_UNEXPECTEDTRADINGACTION
Unexpected trading action, such as trying to close an order ID which identifies a credit record on the account rather than an order or trade
TR_INTERNALERROR
Unexpected internal trading error
TR_NOVOLUME
No volume specified on trading request
TR_NOENTRYPRICE
No entry price specified for a new pending order
TR_NEEDSLWITHRISKVOLUME
Risk-based trading volume, such as {cashRisk: x}, requires a stop-loss
TR_CANTHAVERISKVOLUMEANDSL
Can't set both the volume and stop-loss to cash/risk based values; one of them must be an absolute value rather than a cash-based value such as {equityPercent: 0.5}
TR_PARTIALCLOSENOEFFECT
Requested partial close will have effect. For example, a percentage-based partial close where the resulting volume is less than the minimum trading increment for the market.
TR_PARTIALCLOSEISFULLCLOSE
Requested partial close will execute a full close. (For example: volume is 10K, minimum trading increment is 1K; a request for a 95% close gets rounded up to 10K)
TR_PARTIALCLOSENOTMULTIPLE
Requested volume for a partial close is not a multiple of the minimum trading increment on the market (e.g. closing 5K on a market where the minimum volume is 10K)
TR_AMBIGUOUSENTRYOFFSET
Can't use price offsets for the entry where the tradingAction is BUY_PENDING or SELL_PENDING
TR_NOCANDLEDATAFORCOMMAND
Unable to get the candle data required for a trading action
TR_RRRWITHNOSTOPLOSS
Can't use an rrr value for the take-profit unless a stop-loss is specified.
8.4 Trading requests blocked by user settings/preferences
The Sway Charts Pro platform lets the user set options such as "don't allow trades and orders without a stop-loss" or "don't allow trades or orders which risk more than x% of equity" (based on the order's volume and stop-loss).
The following error codes represent breaches of the user's rules:
Sway.ErrorCodes.
Description
TR_TRADINGGLOBALLYDISABLED
User has disabled all trading in the platform's settings
TR_SETTINGSREQUIRESL
User's settings require that all orders and trades have a stop-loss
TR_SLTOOWIDEFORMAXRISK
Volume and stop-loss imply a cash risk which is beyond the user's specified maximum
TR_MINRISKTOOLARGE
Special case of the above: even the minimum trading volume on the market would, with the specified stop-loss, imply a cash risk which is beyond the user's specified maximum
TR_WIDGETTYPECANTTRADE
Your widget (category) has not been given permission to place trades
8.5 Rejection by trading validators
There are two error codes relating to trading validators:
Sway.ErrorCodes.
Description
TR_VALIDATORREJECTION
Trading validator rejected the request ({status: "block"})
TR_VALIDATORTIMEOUT
Time-out while collecting a response from active trading validators
8.6 Trading requests rejected by the broker platform
The following error codes describe scenarios where a trading request passed internal validation by the framework; was sent to the broker; but the broker rejected the request (or failed in some other way).
There are some error codes whose meaning overlaps, or which are very near duplicates (such as TR_MARKETMOVED and TR_REQUOTE). These reflect different classes of rejection in different back-end broker platforms.
Sway.ErrorCodes.
Description
TR_NOCONNECTION
No current connection to the back-end broker platform
TR_CLIENTSIDETIMEOUT
Time-out (client-side, implemented by the framework) while waiting for a response from the back-end broker platform
TR_BROKERERROR
General, uncategorised error reported by the back-end broker platform
TR_GENERALREJECTION
General, uncategorised rejection reported by the back-end broker platform
TR_ACCOUNTSUSPENDED
Trading account is reported as suspended
TR_ACCOUNTCLOSED
Trading account is reported as closed
TR_NOFUNDS
Too little margin to place the trade
TR_MARKETCLOSED
Market is currently closed
TR_TOOMANYPENDINGORDERS
Too many open pending orders
TR_TOOMANYPOSITIONS
Too many open positions
TR_TOOMUCHVOLUME
Too much open volume
TR_LONGTRADESONLY
Only long trades are permitted on this market
TR_SHORTTRADESONLY
Only short trades are permitted on this market
TR_CLOSETRADESONLY
The market is in close-only mode. New orders are not accepted.
TR_MARKETSUSPENDED
Trading on this market has been suspended by the broker
TR_VOLUMETOOSMALL
Requested trading volume is too small
TR_VOLUMETOOLARGE
Requested trading volume is too large
TR_VOLUMEINVALID
Requested trading volume is reported as not valid
TR_VOLUMEREJECTED
General rejection of the requested trading volume
TR_MANDATORYSTOP
Broker requires that the order has a stop-loss
TR_ALEADYCLOSED
Request to close an order or trade which is already closed
TR_ORDERLOCKED
Order/trade is currently locked by the broker and cannot be modified or closed
TR_ORDERMISSING
Request to modify an order or trade which does not exist
TR_TOOMANYREQUESTS
Broker rejected the request because the framework is making too many requests
TR_INVALIDEXPIRY
Invalid expiry option/value on an order
TR_HEDGINGNOTALLOWED
Order would create a hedged trade, and is not permitted by the account
TR_MUSTUSEFIFO
Orders must be processed (usually: specifically, closed) in FIFO order on a non-hedging account
TR_TOOCLOSETOMODIFY
Back-end system does not allow modification of the order because its entry/exit is too close to the current price
TR_PRICEINDICATIVE
Market price is indicative, and cannot be traded against
TR_INSTRUCTIONREJECTIONWITHCODE
Platform-specific order rejection
TR_REJECTIONWITHCODE
Platform-specific order rejection
TR_NOPRICEFORJOB
Unable to obtain a price for executing the order
TR_TRIGGERTOOCLOSETOMARKET
Price (typically, entry price on a pending order) is too close to the current market price
TR_AUTOTRADINGDISABLEDBYBROKER
MT4/5-specific: the order has been placed via an EA, and automated trading is disabled by the broker
TR_MT4ERROR130
MT4-specific: error #130, which can mean either that the entry price on a pending order is too close to the market price, or that the s/l or t/p on a trade is too close to the current market price, or that the s/l or t/p on a pending order is too close to the requested entry price
TR_NOTPENDING
Attempt to delete an ID which is not a pending order
TR_MARKETORDERSNOTALLOWED
At-market orders are not allowed on this market
TR_LIMITORDERSNOTALLOWED
Limit orders are not allowed on this market
TR_STOPORDERSNOTALLOWED
Stop orders are not allowed on this market
TR_STOPLIMITORDERSNOTALLOWED
Stop-limit orders are not allowed on this market
TR_SLNOTALLOWED
Stop-losses are not allowed on this market
TR_TPNOTALLOWED
Take-profits are not allowed on this market
TR_ACCOUNTNOTRADINGRIGHTS
Your account does not have trading rights. (Generally implies that the account is not allowed to trade, rather than being logged in with a read-only password.)
8.7 Other (non-trading) errors
There is a small number of further error codes which do not relate to trading activity:
Sway.ErrorCodes.
Description
TR_BADCANDLEREQUEST
Invalid request for candle data
TR_MAILERROR
Problem with the mail system. Either no connection to the mail server, or an invalid send-mail request
Last updated