1.24.1
This site is a full specification with examples of what you can do with Tradable Core, but if you haven't had a look at it yet, we recommend reading the Getting Started guide first.
NOTE! The oauth flow doesn't work properly in this documentation site for the codepen examples, for the best experience please see the examples on Codepen.io, you can do that clicking on the "Edit on Codepen" linkBoolean
tradingEnabled
:
Indicates if the user is authenticated
Object
selectedAccount
:
The current user's active trading account. When "onEmbedReady" is called and "tradingEnabled" is true, it is already available and the instruments are initialized for it.
Array
<Object
> accounts
:
List of accounts for the user, it is automatically initialized when trading is enabled.
Object
lastSnapshot
:
Last received account snapshot (may be null).
Array
<Object
> availableInstruments
:
List of instruments cached in memory for the selected account. If the full instrument list is available for the selected account, all of them. Otherwise, instruments are gradually cached for the requested prices. All instruments related to to the open positions and pending orders are cached since the beginning.
.addInstrumentIdToUpdates(updateClientId, instrumentId)
Subscribe for the given instrument Id's prices on the account snaphot updates (onAccountUpdated)
Subscribe for the given instrument Id's prices on the account snaphot updates (onAccountUpdated)
String
updateClientId
:
Id for the element that is requesting the prices, only when no ids are subscribed to an instrument will the instrument be removed from the updates
String
instrumentId
:
Instrument Id for the prices
tradable.addInstrumentIdToUpdates("yourCustomId", "401155666");
// Now the snapshot retrieved by the "accountUpdated" event
// will include prices for the specified instrument
.addOrModifyProtections(positionId, takeProfit, stopLoss, resolve, reject)
Adds or modifies stoploss AND takeprofit on a position (on the selectedAccount)
Adds or modifies stoploss AND takeprofit on a position (on the selectedAccount)
String
positionId
:
Id of position to close
number
takeProfit
:
Take Profit price (Set to null if not wanted)
number
stopLoss
:
Stop Loss price (Set to null if not wanted)
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.addOrModifyProtectionsForAccount(accountId, positionId, takeProfit, stopLoss, resolve, reject)
Adds or modifies stoploss AND takeprofit on a position (on a specific account)
Adds or modifies stoploss AND takeprofit on a position (on a specific account)
String
accountId
:
The unique id for the account the request goes to
String
positionId
:
Id of position to close
number
takeProfit
:
Take Profit price (Set to null if not wanted)
number
stopLoss
:
Stop Loss price (Set to null if not wanted)
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.addOrModifyStopLoss(positionId, newPrice, resolve, reject)
Adds or modifies the stop loss order on a position. (on the selectedAccount)
Adds or modifies the stop loss order on a position. (on the selectedAccount)
String
positionId
:
Id of position to close
String
newPrice
:
The new trigger price
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.addOrModifyStopLossForAccount(accountId, positionId, newPrice, resolve, reject)
Adds or modifies the stop loss order on a position. (on a specific account)
Adds or modifies the stop loss order on a position. (on a specific account)
String
accountId
:
The unique id for the account the request goes to
String
positionId
:
Id of position to close
String
newPrice
:
The new trigger price
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.addOrModifyTakeProfit(positionId, newPrice, resolve, reject)
Adds or modifies the take profit order on a position. (on the selectedAccount)
Adds or modifies the take profit order on a position. (on the selectedAccount)
String
positionId
:
Id of position to close
String
newPrice
:
The new trigger price
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.addOrModifyTakeProfitForAccount(accountId, positionId, newPrice, resolve, reject)
Adds or modifies the take profit order on a position. (on a specific account)
Adds or modifies the take profit order on a position. (on a specific account)
String
accountId
:
The unique id for the account the request goes to
String
positionId
:
Id of position to close
String
newPrice
:
The new trigger price
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.authenticate(brokerId)
Start oauth flow within the page
Start oauth flow within the page
number
brokerId
:
(optional) If the authentication flow needs to be opened for a certain broker, this is the id (v1/brokers)
.authenticateWithCredentials(brokerId, login, password, externalId, resolve, reject)
Gets a token granting access to the account(s) associated with the given login and enables trading
Gets a token granting access to the account(s) associated with the given login and enables trading
number
brokerId
:
The id of the broker that the account is at
String
login
:
The login for the account
String
password
:
The password for the account
String
externalId
:
Allows the caller to provide an id for the user, so it is possible to link the user identity in the caller's system with the Tradable account.
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.authenticateWithWindow(brokerId)
number
brokerId
:
(optional) If the authentication flow needs to be opened for a certain broker, this is the id (v1/brokers)
.calculateExpectedProfitOrLoss(positionSize, pipDistance, pipValue)
Calculates the resulting equity profit or loss for a position/order if a take profit or stop loss at a Pips/Points distance is hit
Calculates the resulting equity profit or loss for a position/order if a take profit or stop loss at a Pips/Points distance is hit
number
positionSize
:
The position size, for a Long/Buy position: positive, for a Short/Sell position: negative
number
pipDistance
:
Distance in pips/points. It can be calculated using the method 'tradable.calculatePipDistance'
number
pipValue
:
The current value of one pip for one unit of this instrument converted to the account currency, it is part of the Price object
number
:
The expected profit or loss in account currency
// The pipValue for EURUSD is 0.0001 in a USD account, so if a take profit at 25 pips is hit
// for a 10000 EURUSD Long (BUY) position the result should be 25
var position = {side: 'BUY', openPrice: 1.13250, amount: 10000}; // Fake position
var amount = (position.side === "BUY") ? position.amount : (position.amount*-1);
var pipDistance = tradable.calculatePipDistance("EURUSD", position.openPrice, 1.13500);
var expectedProfit = tradable.calculateExpectedProfitOrLoss(amount, pipDistance, 0.0001);
// If the take profit is closing a Short (SELL) order instead, the amount should be negative
var order = {side: 'SELL', price: 1.13750, amount: 10000}; // Fake order
var amount = (order.side === "BUY") ? order.amount : (order.amount*-1);
var pipDistance = tradable.calculatePipDistance("EURUSD", order.price, 1.13500);
var expectedProfit = tradable.calculateExpectedProfitOrLoss(amount, pipDistance, 0.0001);
.calculatePipDistance(instrumentId, priceFrom, priceTo)
Calculates the distance in Pips/Points between prices.
Calculates the distance in Pips/Points between prices.
String
instrumentId
:
The instrument id to calculate the distance
number
priceFrom
:
Price to calculate the distance from (opening price, 'openPrice' for a position or price for an 'order')
number
priceTo
:
Price to calculate the distance to (closing price or protection price)
number
:
The pip/point distance (can return a negative value if from > to)
// In the following example the distance result should be 31
var pipDistance = tradable.calculatePipDistance("EURUSD", 1.13571, 1.13881);
.calculatePipSize(instrumentId)
Calculates the pip size for an instrument
Calculates the pip size for an instrument
The instrument id to calculate the pip size
number
// In the following example the pip size would be 0.0001
var pipSize = tradable.calculatePipDistance("EURUSD");
.calculatePositionSizeForRiskAmount(instrumentId, riskAmount, stopLossInPips, pipValue, equity)
Calculates a position size for an instrument out of a given amount willing to risk.
Calculates a position size for an instrument out of a given amount willing to risk.
String
instrumentId
:
The instrument id to calculate the position size
number
riskAmount
:
Amount of equity (money in account currency) willing to risk
number
stopLossInPips
:
Stop loss value in pips/points. It can be calculated using the method 'tradable.calculatePipDistance'
number
pipValue
:
The current value of one pip for one unit of this instrument converted to the account currency, it is part of the Price object
number
equity
:
(optional) The account equity, if not sent it will be taken from the selected account's last received snapshot
number
:
Calculated position size
// Calculate the position size for risking 10k of the account's equity with a 25 pips stop loss
var positionSize = tradable.calculatePositionSizeForRiskAmount("EURUSD", 10000, 25, pipValue);
.calculatePositionSizeForRiskPercentage(instrumentId, riskPercentage, stopLossInPips, pipValue, equity)
Calculates a position size for an instrument out of a given equity percentage willing to risk.
Calculates a position size for an instrument out of a given equity percentage willing to risk.
String
instrumentId
:
The instrument id to calculate the position size
number
riskPercentage
:
Percentage of account equity willing to risk
number
stopLossInPips
:
Stop loss value in pips/points. It can be calculated using the method 'tradable.calculatePipDistance'
number
pipValue
:
The current value of one pip for one unit of this instrument converted to the account currency, it is part of the Price object
number
equity
:
(optional) The account equity, if not sent it will be taken from the selected account's last received snapshot
number
:
Calculated position size
// Calculate the position size for risking 10% of the account's equity with a 25 pips stop loss
var positionSize = tradable.calculatePositionSize("EURUSD", 10, 25, pipValue);
.cancelOrder(orderId, resolve, reject)
Cancels the order with the given id on the selectedAccount
Cancels the order with the given id on the selectedAccount
String
orderId
:
Id of order to cancel
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.cancelOrderForAccount(accountId, orderId, resolve, reject)
Cancels the order with the given id on a specific account
Cancels the order with the given id on a specific account
String
accountId
:
The unique id for the account the request goes to
String
orderId
:
Id of order to cancel
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.cancelProtections(positionId, resolve, reject)
Cancel stoploss and takeprofit protections on a position (on the selectedAccount)
Cancel stoploss and takeprofit protections on a position (on the selectedAccount)
String
positionId
:
Id of position to close
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.cancelProtectionsForAccount(accountId, positionId, resolve, reject)
Cancel stoploss and takeprofit protections on a position (on a specific account)
Cancel stoploss and takeprofit protections on a position (on a specific account)
String
accountId
:
The unique id for the account the request goes to
String
positionId
:
Id of position to close
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.cancelStopLoss(positionId, resolve, reject)
Cancel the stop loss order on a position. (on the selectedAccount)
Cancel the stop loss order on a position. (on the selectedAccount)
String
positionId
:
Id of position to close
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.cancelStopLossForAccount(accountId, positionId, resolve, reject)
Cancel the stop loss order on a position. (on a specific account)
Cancel the stop loss order on a position. (on a specific account)
String
accountId
:
The unique id for the account the request goes to
String
positionId
:
Id of position to close
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.cancelStopLossOnOrder(orderId, resolve, reject)
Cancel a Stop Loss protection attached to a MARKET, LIMIT or STOP order on the selected account
Cancel a Stop Loss protection attached to a MARKET, LIMIT or STOP order on the selected account
String
orderId
:
Id of order to which the Stop Loss is attached
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{}
.cancelStopLossOnOrderForAccount(accountId, orderId, resolve, reject)
Cancel a Stop Loss protection attached to a MARKET, LIMIT or STOP order on a specific account
Cancel a Stop Loss protection attached to a MARKET, LIMIT or STOP order on a specific account
String
accountId
:
The unique id for the account the request goes to
String
orderId
:
Id of order to which the Stop Loss is attached
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{}
.cancelTakeProfit(positionId, resolve, reject)
Cancel the take profit order on a position. (on the selectedAccount)
Cancel the take profit order on a position. (on the selectedAccount)
String
positionId
:
Id of position to close
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.cancelTakeProfitForAccount(accountId, positionId, resolve, reject)
Cancel the take profit order on a position. (on a specific account)
Cancel the take profit order on a position. (on a specific account)
String
accountId
:
The unique id for the account the request goes to
String
positionId
:
Id of position to close
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.cancelTakeProfitOnOrder(orderId, resolve, reject)
Cancel a Take Profit protection attached to a MARKET, LIMIT or STOP order on the selected account
Cancel a Take Profit protection attached to a MARKET, LIMIT or STOP order on the selected account
String
orderId
:
Id of order to which the Take Profit is attached
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{}
.cancelTakeProfitOnOrderForAccount(accountId, orderId, resolve, reject)
Cancel a Take Profit protection attached to a MARKET, LIMIT or STOP order on a specific account
Cancel a Take Profit protection attached to a MARKET, LIMIT or STOP order on a specific account
String
accountId
:
The unique id for the account the request goes to
String
orderId
:
Id of order to which the Take Profit is attached
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{}
.closeAllPositions(resolve, reject)
Closes all positions on the selectedAccount
Closes all positions on the selectedAccount
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.closeAllPositionsForAccount(accountId, resolve, reject)
Closes all positions on a specific account
Closes all positions on a specific account
String
accountId
:
The unique id for the account the request goes to
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.closePosition(positionId, resolve, reject)
Closes the position (on the selectedAccount) with the given id
Closes the position (on the selectedAccount) with the given id
String
positionId
:
Id of position to close
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.closePositionForAccount(accountId, positionId, resolve, reject)
Closes the position (on a specific account) with the given id
Closes the position (on a specific account) with the given id
String
accountId
:
The unique id for the account the request goes to
String
positionId
:
Id of position to close
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.createForexDemoAccount(resolve, reject)
Creates a Forex demo account, gets an authentication token granting access to that account and enables trading for it
Creates a Forex demo account, gets an authentication token granting access to that account and enables trading for it
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.createStocksDemoAccount(resolve, reject)
Creates a Stock demo account, gets an authentication token granting access to that account and enables trading for it
Creates a Stock demo account, gets an authentication token granting access to that account and enables trading for it
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.enableWithAccessToken(accessToken, endpoint, expiresIn)
Enables trading for the account corresponding to the given access token
Enables trading for the account corresponding to the given access token
.getAccountById(accountId)
Returns the account object for the given account uniqueId
Returns the account object for the given account uniqueId
String
accountId
:
Account uniqueId
Object
:
Account object for the given account uniqueId or undefined if not found
This is an example object returned by this method:
{ "uniqueId": "c3ae8ff5d44f9c8833b0af6c02194cab50758ddg", "displayName": "My Brokerage Account", "brokerName": "Some company", "brokerId": 1, "brokerageAccountId": "Some id", "brokerLogos": { "small": "https://www.example.com/broker/small.png", "onLight": "https://www.example.com/broker/onLight.png", "onDark": "https://www.example.com/broker/onDark.png", "svg": "https://www.example.com/broker/image.svg", "svgSolid": "https://www.example.com/broker/imageSolid.svg" }, "endpointURL": "https://router-eu-west-1-prod.tradable.com/", "externalBackofficeReport": "https://www.example.com/brokerBackendReporting", "currency": "USD", "currencySign": "$", "isLiveAccount": false, "trackConfiguration": "MULTI", "stopLossSupported": true, "takeProfitSupported": true, "protectionEntryTypes": { "entryTypes": [ "ABSOLUTE" ] }, "marketOrdersSupport": { "takeProfit": true, "stopLoss": true }, "limitOrdersSupport": { "takeProfit": true, "stopLoss": true }, "stopOrdersSupport": { "takeProfit": true, "stopLoss": true }, "instrumentRetrieval": "FULL_INSTRUMENT_LIST" }
.getAccounts(resolve, reject)
Initializes the tradable.accountsMap and the tradable.accounts list
Initializes the tradable.accountsMap and the tradable.accounts list
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "accounts": { "uniqueId": "c3ae8ff5d44f9c8833b0af6c02194cab50758ddg", "displayName": "My Brokerage Account", "brokerName": "Some company", "brokerId": 1, "brokerageAccountId": "Some id", "brokerLogos": { "small": "https://www.example.com/broker/small.png", "onLight": "https://www.example.com/broker/onLight.png", "onDark": "https://www.example.com/broker/onDark.png", "svg": "https://www.example.com/broker/image.svg", "svgSolid": "https://www.example.com/broker/imageSolid.svg" }, "endpointURL": "https://router-eu-west-1-prod.tradable.com/", "externalBackofficeReport": "https://www.example.com/brokerBackendReporting", "currency": "USD", "currencySign": "$", "isLiveAccount": false, "trackConfiguration": "MULTI", "stopLossSupported": true, "takeProfitSupported": true, "protectionEntryTypes": { "entryTypes": [ "ABSOLUTE" ] }, "marketOrdersSupport": { "takeProfit": true, "stopLoss": true }, "limitOrdersSupport": { "takeProfit": true, "stopLoss": true }, "stopOrdersSupport": { "takeProfit": true, "stopLoss": true }, "instrumentRetrieval": "FULL_INSTRUMENT_LIST" } }
.getAppInfo(resolve, reject)
Provides app information
Provides app information
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "brokers": { "brokerLogos": { "small": "https://www.example.com/broker/small.png", "onLight": "https://www.example.com/broker/onLight.png", "onDark": "https://www.example.com/broker/onDark.png", "svg": "https://www.example.com/broker/image.svg", "svgSolid": "https://www.example.com/broker/imageSolid.svg" }, "brokerId": -2, "brokerName": "Forex Demo Account", "isLive": false, "linkedBrokerId": -1 }, "iconURL": "http://www.example.com/myLogo.png", "name": "My Tradable App" }
.getBrokers(resolve, reject)
Provides account id and tokens granting access to the requested account
Provides account id and tokens granting access to the requested account
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
[ { "brokerLogos": { "small": "https://www.example.com/broker/small.png", "onLight": "https://www.example.com/broker/onLight.png", "onDark": "https://www.example.com/broker/onDark.png", "svg": "https://www.example.com/broker/image.svg", "svgSolid": "https://www.example.com/broker/imageSolid.svg" }, "brokerId": -2, "brokerName": "Forex Demo Account", "isLive": false, "linkedBrokerId": -1 } ]
.getCandles(instrumentId, from, to, aggregation, resolve, reject)
Provides candles for the selectedAccount, given instrument Id, aggregation and range (from-to)
Provides candles for the selectedAccount, given instrument Id, aggregation and range (from-to)
String
instrumentId
:
The instrument id for the candles
number
from
:
The start of the candle range. In milliseconds since epoch
number
to
:
The end of the candle range. In milliseconds since epoch
number
aggregation
:
The aggregation interval in minutes. Allowed values: 1,5,15,30,60,1440,21600,40320
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
// Day Candles for last week:
var id = "someInsturmentId";
var fromDate = new Date();
fromDate.setDate(fromDate.getDate() - 7);
var dayRes = 60 * 24;
tradable.getCandles(id, fromDate.getTime(), Date.now(), dayRes).then(function(data){
console.log("Received candles: " + JSON.stringify(data, null, 2));
}, function(jqXHR){
console.error("Error requesting candles: " + jqXHR.responseJSON.message);
});
This is an example object returned by the callback from this method:
{
"candles": {
"timestamp": 1433908800000,
"open": 1.10023,
"close": 1.100054,
"high": 1.100101,
"low": 1.100001,
"volume": 160
},
"indicators": {}
}
.getCandlesForAccount(accountId, instrumentId, from, to, aggregation, resolve, reject)
Provides candles for a specific account, the given instrument Id, aggregation and range (from-to)
Provides candles for a specific account, the given instrument Id, aggregation and range (from-to)
String
accountId
:
The unique id for the account the request goes to
String
instrumentId
:
The instrument id for the candles
number
from
:
The start of the candle range. In milliseconds since epoch
number
to
:
The end of the candle range. In milliseconds since epoch
number
aggregation
:
The aggregation interval in minutes. Allowed values: 1,5,15,30,60,1440,21600,40320
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
// Hourly Candles for last 2 days:
var actId = tradable.selectedAccount.uniqueId;
var id = "someInsturmentId";
var fromDate = new Date();
fromDate.setDate(fromDate.getDate() - 2);
var hourRes = 60;
tradable.getCandlesForAccount(actId, id, fromDate.getTime(), Date.now(), hourRes).then(function(data){
console.log("Received candles: " + JSON.stringify(data, null, 2));
}, function(jqXHR){
console.error("Error requesting candles: " + jqXHR.responseJSON.message);
});
This is an example object returned by the callback from this method:
{
"candles": {
"timestamp": 1433908800000,
"open": 1.10023,
"close": 1.100054,
"high": 1.100101,
"low": 1.100001,
"volume": 160
},
"indicators": {}
}
.getInstrumentFromBrokerageAccountSymbol(brokerageAccountSymbol)
Returns the correspondent instrument obj to the brokerageAccountSymbol if it's in the current account. Beware! getInstrumentFromBrokerageAccountSymbol is a convenience synchronous method that retrieves the instrument from cache. In accounts in which the FULL_INSTRUMENT_LIST is not supported, you need to subscribe the instrument id to prices, have it in the account snapshot or request it through POST 'getInstrumentsFromIds' for it to be cached.
Returns the correspondent instrument obj to the brokerageAccountSymbol if it's in the current account. Beware! getInstrumentFromBrokerageAccountSymbol is a convenience synchronous method that retrieves the instrument from cache. In accounts in which the FULL_INSTRUMENT_LIST is not supported, you need to subscribe the instrument id to prices, have it in the account snapshot or request it through POST 'getInstrumentsFromIds' for it to be cached.
String
brokerageAccountSymbol
:
Instrument Brokerage Account Symbol
Object
:
Correspondent instrument obj to the Brokerage Account Symbol or null if not found
This is an example object returned by this method:
{ "instrumentId": "abc123", "brokerageAccountSymbol": "EUR/USD", "displayName": "EUR/USD", "exchangeID": null, "maxAmount": 50000000, "maxShortAmount": 5000000, "orderSizeIncrements": { "orderSizeIncrementBands": [ { "lowerBound": 1, "increment": 1, "decimals": 0 }, { "lowerBound": 100, "increment": 100, "decimals": 0 } ] }, "pipPrecision": 4, "priceIncrements": { "priceIncrementBands": [ { "lowerBound": 0, "increment": 0.05, "decimals": 2 }, { "lowerBound": 10, "increment": 0.1, "decimals": 1 }, { "lowerBound": 500, "increment": 0.25, "decimals": 2 }, { "lowerBound": 1000, "increment": 0.5, "decimals": 1 }, { "lowerBound": 2500, "increment": 1, "decimals": 0 } ] }, "quoteCurrency": "USD", "shortDescription": "", "symbol": "EURUSD", "type": "FOREX" }
.getInstrumentFromId(instrumentId)
Returns the correspondent instrument obj to the instrumentId if it's in the current account. Beware! getInstrumentFromId is a convenience synchronous method that retrieves the instrument from cache. In accounts in which the FULL_INSTRUMENT_LIST is not supported, you need to subscribe the instrument id to prices, have it in the account snapshot or request it through POST 'getInstrumentsFromIds' for it to be cached.
Returns the correspondent instrument obj to the instrumentId if it's in the current account. Beware! getInstrumentFromId is a convenience synchronous method that retrieves the instrument from cache. In accounts in which the FULL_INSTRUMENT_LIST is not supported, you need to subscribe the instrument id to prices, have it in the account snapshot or request it through POST 'getInstrumentsFromIds' for it to be cached.
String
instrumentId
:
Instrument id
Object
:
Correspondent instrument obj to the id or null if not found
This is an example object returned by this method:
{ "instrumentId": "abc123", "brokerageAccountSymbol": "EUR/USD", "displayName": "EUR/USD", "exchangeID": null, "maxAmount": 50000000, "maxShortAmount": 5000000, "orderSizeIncrements": { "orderSizeIncrementBands": [ { "lowerBound": 1, "increment": 1, "decimals": 0 }, { "lowerBound": 100, "increment": 100, "decimals": 0 } ] }, "pipPrecision": 4, "priceIncrements": { "priceIncrementBands": [ { "lowerBound": 0, "increment": 0.05, "decimals": 2 }, { "lowerBound": 10, "increment": 0.1, "decimals": 1 }, { "lowerBound": 500, "increment": 0.25, "decimals": 2 }, { "lowerBound": 1000, "increment": 0.5, "decimals": 1 }, { "lowerBound": 2500, "increment": 1, "decimals": 0 } ] }, "quoteCurrency": "USD", "shortDescription": "", "symbol": "EURUSD", "type": "FOREX" }
.getInstrumentFromSymbol(symbol)
Returns the correspondent instrument obj to the symbol if it's in the current account. Beware! getInstrumentFromSymbol is a convenience synchronous method that retrieves the instrument from cache. In accounts in which the FULL_INSTRUMENT_LIST is not supported, you need to subscribe the instrument id to prices, have it in the account snapshot or request it through POST 'getInstrumentsFromIds' for it to be cached.
Returns the correspondent instrument obj to the symbol if it's in the current account. Beware! getInstrumentFromSymbol is a convenience synchronous method that retrieves the instrument from cache. In accounts in which the FULL_INSTRUMENT_LIST is not supported, you need to subscribe the instrument id to prices, have it in the account snapshot or request it through POST 'getInstrumentsFromIds' for it to be cached.
String
symbol
:
Instrument symbol
Object
:
Correspondent instrument obj to the symbol or null if not found
This is an example object returned by this method:
{ "instrumentId": "abc123", "brokerageAccountSymbol": "EUR/USD", "displayName": "EUR/USD", "exchangeID": null, "maxAmount": 50000000, "maxShortAmount": 5000000, "orderSizeIncrements": { "orderSizeIncrementBands": [ { "lowerBound": 1, "increment": 1, "decimals": 0 }, { "lowerBound": 100, "increment": 100, "decimals": 0 } ] }, "pipPrecision": 4, "priceIncrements": { "priceIncrementBands": [ { "lowerBound": 0, "increment": 0.05, "decimals": 2 }, { "lowerBound": 10, "increment": 0.1, "decimals": 1 }, { "lowerBound": 500, "increment": 0.25, "decimals": 2 }, { "lowerBound": 1000, "increment": 0.5, "decimals": 1 }, { "lowerBound": 2500, "increment": 1, "decimals": 0 } ] }, "quoteCurrency": "USD", "shortDescription": "", "symbol": "EURUSD", "type": "FOREX" }
.getInstrumentsFromIds(instrumentIds, resolve, reject)
Get the instrument information for a set of instrument Ids for the selectedAccount
Get the instrument information for a set of instrument Ids for the selectedAccount
Array
instrumentIds
:
Array of instrument Ids for the wanted instruments
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
tradable.getInstrumentsFromIds(["xyz456"]).then(function(instruments) {
console.log(JSON.stringify(instruments, null, 2));
}, function(jqXHR) {
console.error("Error trying to retrieve instruments: " + jqXHR.responseJSON.message);
});
This is an example object returned by the callback from this method:
{
"instruments": [
{
"minAmount": 1000,
"instrumentId": "xyz456",
"displayName": "EUR/JPY",
"maxShortAmount": 5000001,
"shortDescription": "",
"type": "CFD",
"quoteCurrency": "JPY",
"exchangeID": null,
"multipleOfMinAmount": true,
"brokerageAccountSymbol": "EUR/JPY",
"pipPrecision": 2,
"decimals": 3,
"maxAmount": 50000000
}
],
"sequenceId": 647594837
}
.getInstrumentsFromIdsForAccount(accountId, instrumentIds, resolve, reject)
Get the instrument information for a set of instrument Ids for for a specific accountId
Get the instrument information for a set of instrument Ids for for a specific accountId
String
accountId
:
The unique id for the account the request goes to
Array
instrumentIds
:
Array of instrument Ids for the wanted instruments
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
var accountId = tradable.selectedAccount.uniqueId;
tradable.getInstrumentsFromIdsForAccount(accountId, ["xyz456"]).then(function(instruments) {
console.log(JSON.stringify(instruments, null, 2));
}, function(jqXHR) {
console.error("Error trying to retrieve instruments: " + jqXHR.responseJSON.message);
});
This is an example object returned by the callback from this method:
{
"instruments": [
{
"minAmount": 1000,
"instrumentId": "xyz456",
"displayName": "EUR/JPY",
"maxShortAmount": 5000001,
"shortDescription": "",
"type": "CFD",
"quoteCurrency": "JPY",
"exchangeID": null,
"multipleOfMinAmount": true,
"brokerageAccountSymbol": "EUR/JPY",
"pipPrecision": 2,
"decimals": 3,
"maxAmount": 50000000
}
],
"sequenceId": 647594837
}
.getLastDailyClose(instrumentIds, resolve, reject)
A list of close prices for the previous day for certain symbols (on a specific account)
A list of close prices for the previous day for certain symbols (on a specific account)
Array
instrumentIds
:
Array of instrument Ids for the wanted daily close prices
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.getMetrics(resolve, reject)
The users balance and other account metrics for the selectedAccount
The users balance and other account metrics for the selectedAccount
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "availableForTrading": 10900, "balance": 10000, "closedProfit": 0, "equity": 11000, "marginUsed": 100, "openProfit": 1000 }
.getMetricsForAccount(accountId, resolve, reject)
The users balance and other account metrics for a specific accountId
The users balance and other account metrics for a specific accountId
String
accountId
:
The unique id for the account the request goes to
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "availableForTrading": 10900, "balance": 10000, "closedProfit": 0, "equity": 11000, "marginUsed": 100, "openProfit": 1000 }
.getOpenPositions(resolve, reject)
Returns a list of all the open positions on the selectedAccount
Returns a list of all the open positions on the selectedAccount
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
[ { "id": "yh-14-e", "instrumentId": "abc123", "side": "BUY", "amount": 10000, "openPrice": 0.9, "lastPrice": 1, "openProfit": 1000, "closedProfit": null, "openNotionalProfit": 1000, "closedNotionalProfit": null, "rolloverFees": null, "otherFees": null, "creationTime": 1461149630, "lastModified": 1461149630, "stoploss": null, "takeprofit": null, "sequenceId": 647594837 } ]
.getOpenPositionsForAccount(accountId, resolve, reject)
Returns a list of all the open positions on a specific account
Returns a list of all the open positions on a specific account
String
accountId
:
The unique id for the account the request goes to
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
[ { "id": "yh-14-e", "instrumentId": "abc123", "side": "BUY", "amount": 10000, "openPrice": 0.9, "lastPrice": 1, "openProfit": 1000, "closedProfit": null, "openNotionalProfit": 1000, "closedNotionalProfit": null, "rolloverFees": null, "otherFees": null, "creationTime": 1461149630, "lastModified": 1461149630, "stoploss": null, "takeprofit": null, "sequenceId": 647594837 } ]
.getOrderById(orderId, resolve, reject)
Returns an order for the provided id and the selectedAccount, without the up-to-date price
Returns an order for the provided id and the selectedAccount, without the up-to-date price
String
orderId
:
Id of order
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "id": "oteF-6eh4", "instrumentId": "abc123", "side": "BUY", "type": "MARKET", "amount": 10000, "status": "PENDING", "price": 0, "lastPrice": 1, "creationDate": 1461149630, "affectedPositions": {}, "stopLoss": null, "takeProfit": null, "executionPrice": null, "sequenceId": 647594837 }
.getOrderByIdForAccount(accountId, orderId, resolve, reject)
Returns an order for the provided id and a specific account, without the up-to-date price
Returns an order for the provided id and a specific account, without the up-to-date price
String
accountId
:
The unique id for the account the request goes to
String
orderId
:
Id of order
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "id": "oteF-6eh4", "instrumentId": "abc123", "side": "BUY", "type": "MARKET", "amount": 10000, "status": "PENDING", "price": 0, "lastPrice": 1, "creationDate": 1461149630, "affectedPositions": {}, "stopLoss": null, "takeProfit": null, "executionPrice": null, "sequenceId": 647594837 }
.getOrders(resolve, reject)
Returns a list of all the orders divided in pending, recentlyCancelled and recentlyExecuted for the selectedAccount
Returns a list of all the orders divided in pending, recentlyCancelled and recentlyExecuted for the selectedAccount
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "pending": { "id": "1234", "instrumentId": "abc123", "symbol": "EURUSD", "side": "BUY", "type": "MARKET", "amount": 10000, "status": "PENDING", "price": 0, "lastPrice": 1, "creationDate": 1498484641547, "affectedPositions": [], "stopLossDistance": null, "takeProfitDistance": null, "stopLoss": null, "takeProfit": null, "executionPrice": null }, "recentlyCancelled": { "id": "1236", "instrumentId": "abc123", "symbol": "EURUSD", "side": "BUY", "type": "STOP", "amount": 10000, "status": "CANCELLED", "price": 1.1, "lastPrice": 1, "creationDate": 1498484641552, "affectedPositions": [], "stopLossDistance": null, "takeProfitDistance": null, "stopLoss": null, "takeProfit": null, "executionPrice": null }, "recentlyExecuted": { "id": "1235", "instrumentId": "abc123", "symbol": "EURUSD", "side": "BUY", "type": "LIMIT", "amount": 10000, "status": "EXECUTED", "price": 0.9, "lastPrice": 1, "creationDate": 1498484641552, "affectedPositions": [ "1235" ], "stopLossDistance": null, "takeProfitDistance": null, "stopLoss": null, "takeProfit": null, "executionPrice": 0.9 }, "sequenceId": 647594837 }
.getOrdersForAccount(accountId, resolve, reject)
Returns a list of all the orders divided in pending, recentlyCancelled and recentlyExecuted for a specific accountId
Returns a list of all the orders divided in pending, recentlyCancelled and recentlyExecuted for a specific accountId
String
accountId
:
The unique id for the account the request goes to
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "pending": { "id": "1234", "instrumentId": "abc123", "symbol": "EURUSD", "side": "BUY", "type": "MARKET", "amount": 10000, "status": "PENDING", "price": 0, "lastPrice": 1, "creationDate": 1498484641547, "affectedPositions": [], "stopLossDistance": null, "takeProfitDistance": null, "stopLoss": null, "takeProfit": null, "executionPrice": null }, "recentlyCancelled": { "id": "1236", "instrumentId": "abc123", "symbol": "EURUSD", "side": "BUY", "type": "STOP", "amount": 10000, "status": "CANCELLED", "price": 1.1, "lastPrice": 1, "creationDate": 1498484641552, "affectedPositions": [], "stopLossDistance": null, "takeProfitDistance": null, "stopLoss": null, "takeProfit": null, "executionPrice": null }, "recentlyExecuted": { "id": "1235", "instrumentId": "abc123", "symbol": "EURUSD", "side": "BUY", "type": "LIMIT", "amount": 10000, "status": "EXECUTED", "price": 0.9, "lastPrice": 1, "creationDate": 1498484641552, "affectedPositions": [ "1235" ], "stopLossDistance": null, "takeProfitDistance": null, "stopLoss": null, "takeProfit": null, "executionPrice": 0.9 }, "sequenceId": 647594837 }
.getPendingOrders(resolve, reject)
Returns a list of all the pending orders the selectedAccount - This will typically be limit orders but in a market without liquidity it can also contain market orders
Returns a list of all the pending orders the selectedAccount - This will typically be limit orders but in a market without liquidity it can also contain market orders
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
[ { "id": "oteF-6eh4", "instrumentId": "abc123", "side": "BUY", "type": "MARKET", "amount": 10000, "status": "PENDING", "price": 0, "lastPrice": 1, "creationDate": 1461149630, "affectedPositions": {}, "stopLoss": null, "takeProfit": null, "executionPrice": null, "sequenceId": 647594837 } ]
.getPendingOrdersForAccount(accountId, resolve, reject)
Returns a list of all the pending orders for a specific account - This will typically be limit orders but in a market without liquidity it can also contain market orders
Returns a list of all the pending orders for a specific account - This will typically be limit orders but in a market without liquidity it can also contain market orders
String
accountId
:
The unique id for the account the request goes to
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
[ { "id": "oteF-6eh4", "instrumentId": "abc123", "side": "BUY", "type": "MARKET", "amount": 10000, "status": "PENDING", "price": 0, "lastPrice": 1, "creationDate": 1461149630, "affectedPositions": {}, "stopLoss": null, "takeProfit": null, "executionPrice": null, "sequenceId": 647594837 } ]
.getPositionById(positionId, resolve, reject)
Returns a position for the provided id, without the up-to-date price and metrics on the selectedAccount
Returns a position for the provided id, without the up-to-date price and metrics on the selectedAccount
String
positionId
:
Id of position to retrieve
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "id": "yh-14-e", "instrumentId": "abc123", "side": "BUY", "amount": 10000, "openPrice": 0.9, "lastPrice": 1, "openProfit": 1000, "closedProfit": null, "openNotionalProfit": 1000, "closedNotionalProfit": null, "rolloverFees": null, "otherFees": null, "creationTime": 1461149630, "lastModified": 1461149630, "stoploss": null, "takeprofit": null, "sequenceId": 647594837 }
.getPositionByIdForAccount(accountId, positionId, resolve, reject)
Returns a position for the provided id, without the up-to-date price and metrics on a specific account
Returns a position for the provided id, without the up-to-date price and metrics on a specific account
String
accountId
:
The unique id for the account the request goes to
String
positionId
:
Id of position to retrieve
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "id": "yh-14-e", "instrumentId": "abc123", "side": "BUY", "amount": 10000, "openPrice": 0.9, "lastPrice": 1, "openProfit": 1000, "closedProfit": null, "openNotionalProfit": 1000, "closedNotionalProfit": null, "rolloverFees": null, "otherFees": null, "creationTime": 1461149630, "lastModified": 1461149630, "stoploss": null, "takeprofit": null, "sequenceId": 647594837 }
.getPositions(resolve, reject)
Returns a list of all the positions on the selectedAccount. Will return open and recently closed positions
Returns a list of all the positions on the selectedAccount. Will return open and recently closed positions
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "open": { "id": "1235", "instrumentId": "abc123", "side": "BUY", "amount": 10000, "openPrice": 0.9, "lastPrice": 1, "openProfit": 1000, "closedProfit": null, "openNotionalProfit": 1000, "closedNotionalProfit": null, "rolloverFees": null, "otherFees": null, "creationTime": 1498484641598, "lastModified": 1498484641598, "stoploss": null, "takeprofit": null }, "recentlyClosed": { "id": "1236", "instrumentId": "abc123", "side": null, "amount": 0, "openPrice": 0, "lastPrice": 1, "openProfit": 0, "closedProfit": null, "openNotionalProfit": null, "closedNotionalProfit": -10, "rolloverFees": null, "otherFees": null, "creationTime": 1498484641598, "lastModified": 1498484641598, "stoploss": null, "takeprofit": null }, "sequenceId": 647594837 }
.getPositionsForAccount(accountId, resolve, reject)
Returns a list of all the positions on a specific account. Will return open and recently closed positions
Returns a list of all the positions on a specific account. Will return open and recently closed positions
String
accountId
:
The unique id for the account the request goes to
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "open": { "id": "1235", "instrumentId": "abc123", "side": "BUY", "amount": 10000, "openPrice": 0.9, "lastPrice": 1, "openProfit": 1000, "closedProfit": null, "openNotionalProfit": 1000, "closedNotionalProfit": null, "rolloverFees": null, "otherFees": null, "creationTime": 1498484641598, "lastModified": 1498484641598, "stoploss": null, "takeprofit": null }, "recentlyClosed": { "id": "1236", "instrumentId": "abc123", "side": null, "amount": 0, "openPrice": 0, "lastPrice": 1, "openProfit": 0, "closedProfit": null, "openNotionalProfit": null, "closedNotionalProfit": -10, "rolloverFees": null, "otherFees": null, "creationTime": 1498484641598, "lastModified": 1498484641598, "stoploss": null, "takeprofit": null }, "sequenceId": 647594837 }
.getPrices(instrumentIds, resolve, reject)
A list of prices for certain instrument Ids (on the selectedAccount)
A list of prices for certain instrument Ids (on the selectedAccount)
Array
instrumentIds
:
Array of instrument Ids for the wanted prices
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
[ { "instrumentId": "abc123", "bid": 0.99231, "ask": 0.99251, "spread": 2, "pipValue": 0.0001, "margin": { "marginBands": { "lowerBound": 0, "marginFactor": 0.001234 } } } ]
.getPricesForAccount(accountId, instrumentIds, resolve, reject)
A list of prices for certain instrument Ids (on a specific account)
A list of prices for certain instrument Ids (on a specific account)
String
accountId
:
The unique id for the account the request goes to
Array
instrumentIds
:
Array of instrument Ids for the wanted prices
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
[ { "instrumentId": "abc123", "bid": 0.99231, "ask": 0.99251, "spread": 2, "pipValue": 0.0001, "margin": { "marginBands": { "lowerBound": 0, "marginFactor": 0.001234 } } } ]
.getRemainingTokenMillis
Returns the remaining milliseconds for the token to expire
Returns the remaining milliseconds for the token to expire
number
:
remainingMillis Remaining milliseconds for the token to expire
.getSnapshot(instrumentIds, resolve, reject)
Provides the account snapshot for the selectedAccount - a full snapshot of all orders, positions, account metrics and prices for the instrument Ids given as input
Provides the account snapshot for the selectedAccount - a full snapshot of all orders, positions, account metrics and prices for the instrument Ids given as input
Array
instrumentIds
:
Array of instrument Ids for the wanted prices
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "metrics": { "availableForTrading": 10900, "balance": 10000, "closedProfit": 0, "equity": 11000, "marginUsed": 100, "openProfit": 1000 }, "orders": { "pending": { "id": "1234", "instrumentId": "abc123", "symbol": "EURUSD", "side": "BUY", "type": "MARKET", "amount": 10000, "status": "PENDING", "price": 0, "lastPrice": 1, "creationDate": 1498484641583, "affectedPositions": [], "stopLossDistance": null, "takeProfitDistance": null, "stopLoss": null, "takeProfit": null, "executionPrice": null }, "recentlyCancelled": { "id": "1236", "instrumentId": "abc123", "symbol": "EURUSD", "side": "BUY", "type": "STOP", "amount": 10000, "status": "CANCELLED", "price": 1.1, "lastPrice": 1, "creationDate": 1498484641583, "affectedPositions": [], "stopLossDistance": null, "takeProfitDistance": null, "stopLoss": null, "takeProfit": null, "executionPrice": null }, "recentlyExecuted": { "id": "1235", "instrumentId": "abc123", "symbol": "EURUSD", "side": "BUY", "type": "LIMIT", "amount": 10000, "status": "EXECUTED", "price": 0.9, "lastPrice": 1, "creationDate": 1498484641590, "affectedPositions": [ "1235" ], "stopLossDistance": null, "takeProfitDistance": null, "stopLoss": null, "takeProfit": null, "executionPrice": 0.9 }, "sequenceId": 647594837 }, "positions": { "open": { "id": "1235", "instrumentId": "abc123", "side": "BUY", "amount": 10000, "openPrice": 0.9, "lastPrice": 1, "openProfit": 1000, "closedProfit": null, "openNotionalProfit": 1000, "closedNotionalProfit": null, "rolloverFees": null, "otherFees": null, "creationTime": 1498484641591, "lastModified": 1498484641591, "stoploss": null, "takeprofit": null }, "recentlyClosed": { "id": "1236", "instrumentId": "abc123", "side": null, "amount": 0, "openPrice": 0, "lastPrice": 1, "openProfit": 0, "closedProfit": null, "openNotionalProfit": null, "closedNotionalProfit": -10, "rolloverFees": null, "otherFees": null, "creationTime": 1498484641591, "lastModified": 1498484641591, "stoploss": null, "takeprofit": null }, "sequenceId": 647594837 }, "prices": { "instrumentId": "abc123", "bid": 0.99231, "ask": 0.99251, "spread": 2, "pipValue": 0.0001, "margin": { "marginBands": { "lowerBound": 0, "marginFactor": 0.001234 } } }, "sequenceId": 647594837 }
.getSnapshotForAccount(accountId, instrumentIds, resolve, reject)
Provides the account snapshot for a specific account - a full snapshot of all orders, positions, account metrics and prices for the instrument Ids given as input
Provides the account snapshot for a specific account - a full snapshot of all orders, positions, account metrics and prices for the instrument Ids given as input
String
accountId
:
The unique id for the account the request goes to
Array
instrumentIds
:
Array of instrument Ids for the wanted prices
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "metrics": { "availableForTrading": 10900, "balance": 10000, "closedProfit": 0, "equity": 11000, "marginUsed": 100, "openProfit": 1000 }, "orders": { "pending": { "id": "1234", "instrumentId": "abc123", "symbol": "EURUSD", "side": "BUY", "type": "MARKET", "amount": 10000, "status": "PENDING", "price": 0, "lastPrice": 1, "creationDate": 1498484641583, "affectedPositions": [], "stopLossDistance": null, "takeProfitDistance": null, "stopLoss": null, "takeProfit": null, "executionPrice": null }, "recentlyCancelled": { "id": "1236", "instrumentId": "abc123", "symbol": "EURUSD", "side": "BUY", "type": "STOP", "amount": 10000, "status": "CANCELLED", "price": 1.1, "lastPrice": 1, "creationDate": 1498484641583, "affectedPositions": [], "stopLossDistance": null, "takeProfitDistance": null, "stopLoss": null, "takeProfit": null, "executionPrice": null }, "recentlyExecuted": { "id": "1235", "instrumentId": "abc123", "symbol": "EURUSD", "side": "BUY", "type": "LIMIT", "amount": 10000, "status": "EXECUTED", "price": 0.9, "lastPrice": 1, "creationDate": 1498484641590, "affectedPositions": [ "1235" ], "stopLossDistance": null, "takeProfitDistance": null, "stopLoss": null, "takeProfit": null, "executionPrice": 0.9 }, "sequenceId": 647594837 }, "positions": { "open": { "id": "1235", "instrumentId": "abc123", "side": "BUY", "amount": 10000, "openPrice": 0.9, "lastPrice": 1, "openProfit": 1000, "closedProfit": null, "openNotionalProfit": 1000, "closedNotionalProfit": null, "rolloverFees": null, "otherFees": null, "creationTime": 1498484641591, "lastModified": 1498484641591, "stoploss": null, "takeprofit": null }, "recentlyClosed": { "id": "1236", "instrumentId": "abc123", "side": null, "amount": 0, "openPrice": 0, "lastPrice": 1, "openProfit": 0, "closedProfit": null, "openNotionalProfit": null, "closedNotionalProfit": -10, "rolloverFees": null, "otherFees": null, "creationTime": 1498484641591, "lastModified": 1498484641591, "stoploss": null, "takeprofit": null }, "sequenceId": 647594837 }, "prices": { "instrumentId": "abc123", "bid": 0.99231, "ask": 0.99251, "spread": 2, "pipValue": 0.0001, "margin": { "marginBands": { "lowerBound": 0, "marginFactor": 0.001234 } } }, "sequenceId": 647594837 }
.getUser(resolve, reject)
Provides information about the end-user
Provides information about the end-user
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "userId": "d3ae8ff5d55f9c8833b0af6c02194cab50758ddf", "userName": "Alex Smith", "userThumbnail": "https://www.example.com/userThumb", "userPicture": "https://www.example.com/userPic" }
.initializeWithToken(access_token, end_point, expires_in, resolve, reject)
This method will initialize tradable core with the minimum required in order to be able to use the API calls that do not require a selected account. Beware! If you use this method instead of 'enableWithAccessToken', there will not be a selectedAccount and the instruments will not be cached. The on/off listeners will not work either. I.e. you will only be able to use methods that require an 'accountId'
This method will initialize tradable core with the minimum required in order to be able to use the API calls that do not require a selected account. Beware! If you use this method instead of 'enableWithAccessToken', there will not be a selectedAccount and the instruments will not be cached. The on/off listeners will not work either. I.e. you will only be able to use methods that require an 'accountId'
String
access_token
:
The authentication token granting access to the account
String
end_point
:
The endpoint to send API requests to
String
expires_in
:
The expiry date (in seconds) of the access token.
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.modifyOrderPrice(orderId, newPrice, resolve, reject)
Modifies the price for the order identified with the given id on the selectedAccount
Modifies the price for the order identified with the given id on the selectedAccount
String
orderId
:
Id of order to modify
String
newPrice
:
The new trigger price
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.modifyOrderPriceForAccount(accountId, orderId, newPrice, resolve, reject)
Modifies the price for the order identified with the given id on a specific account
Modifies the price for the order identified with the given id on a specific account
String
accountId
:
The unique id for the account the request goes to
String
orderId
:
Id of order to modify
String
newPrice
:
The new trigger price
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.modifyProtectedOrder(order, price, takeProfitPrice, stopLossPrice, currentBidOrAskPrice, resolve, reject)
Modify a MARKET, LIMIT or STOP order with Take Profit and/or Stop Loss protections on the selected account. Some accounts require an absolute price for the take profit and others require a price distance (See 'account.protectionEntryTypes'). This method will send the required entry type and value, i.e. it will calculate the distance from the price and send it if the account only supports the 'DISTANCE' entry type or just send the desired take profit or stop loss prices if the 'ABSOLUTE' entry type is supported
Modify a MARKET, LIMIT or STOP order with Take Profit and/or Stop Loss protections on the selected account. Some accounts require an absolute price for the take profit and others require a price distance (See 'account.protectionEntryTypes'). This method will send the required entry type and value, i.e. it will calculate the distance from the price and send it if the account only supports the 'DISTANCE' entry type or just send the desired take profit or stop loss prices if the 'ABSOLUTE' entry type is supported
Object
order
:
Order object to be modified
number
price
:
The new trigger price (Current order price or undefined if no modification required)
number
takeProfitPrice
:
Take profit trigger price (null to delete take profit | current take profit price or undefined if no modification required)
number
stopLossPrice
:
Stop loss trigger price (null to delete stop loss | current stop loss price or undefined if no modification required)
number
currentBidOrAskPrice
:
For 'BUY' MARKET orders the ask price for the instrument, for 'SELL' MARKET orders the bid price. It is only required for MARKET orders, for LIMIT and STOP orders pass 0.
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{}
.modifyProtectedOrderForAccount(accountId, order, newPrice, takeProfitPrice, stopLossPrice, currentBidOrAskPrice, resolve, reject)
Modify a MARKET, LIMIT or STOP order with Take Profit and/or Stop Loss protections on a specific account. Some accounts require an absolute price for the take profit and others require a price distance (See 'account.protectionEntryTypes'). This method will send the required entry type and value, i.e. it will calculate the distance from the price and send it if the account only supports the 'DISTANCE' entry type or just send the desired take profit or stop loss prices if the 'ABSOLUTE' entry type is supported
Modify a MARKET, LIMIT or STOP order with Take Profit and/or Stop Loss protections on a specific account. Some accounts require an absolute price for the take profit and others require a price distance (See 'account.protectionEntryTypes'). This method will send the required entry type and value, i.e. it will calculate the distance from the price and send it if the account only supports the 'DISTANCE' entry type or just send the desired take profit or stop loss prices if the 'ABSOLUTE' entry type is supported
String
accountId
:
The unique id for the account the request goes to
Object
order
:
Order object to be modified
number
newPrice
:
The new trigger price (Current order price or undefined if no modification required)
number
takeProfitPrice
:
Take profit trigger price (null to delete take profit | current take profit price or undefined if no modification required)
number
stopLossPrice
:
Stop loss trigger price (null to delete stop loss | current stop loss price or undefined if no modification required)
number
currentBidOrAskPrice
:
For 'BUY' MARKET orders the ask price for the instrument, for 'SELL' MARKET orders the bid price. It is only required for MARKET orders, for LIMIT and STOP orders pass 0.
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{}
.off(namespace, eventName)
Turn off an specific event listener with a namespace
Turn off an specific event listener with a namespace
String
namespace
:
The unique name that identifies your listener
String
eventName
:
(optional) The event's name, if not specified all events for the given namespace will be turned off
tradable.off("yourCustomNamespace", "accountUpdated");
.on(namespace, eventName, callback)
Add an event listener with an specific name that can be turned off calling 'off'.
Add an event listener with an specific name that can be turned off calling 'off'.
String
namespace
:
A unique name that will identify your listener and that you will have to use to turn the listener off
String
eventName
:
The available events are "embedStarting", "embedReady", "accountUpdated", "accountSwitch", "twoFactorAuthentication", "tokenExpired", "tokenWillExpire", "reLoginRequired", "error"
Function
callback
:
Event listener callback function
// Read more: https://github.com/tradable/tradable-core#additional-events
tradable.on("yourCustomNamespace", "accountUpdated", function(snapshot) {
console.log("Notified with every snapshot..");
});
.onAccountSwitch(callback)
Gets notified every time the selectedAccount is changed (through the setSelectedAccount method)
Gets notified every time the selectedAccount is changed (through the setSelectedAccount method)
Function
callback
:
Callback function to be notified
.onAccountUpdated(callback)
Gets notified with a new account snapshot every certain time (700 millis by default)
Gets notified with a new account snapshot every certain time (700 millis by default)
Function
callback
:
Callback function to be notified
.onEmbedReady(callback)
Main library state notifier, called every time the state of tradingEnabled changes
Main library state notifier, called every time the state of tradingEnabled changes
Function
callback
:
Callback function to be notified
.onError(callback)
Gets called when a general error occurs, for example an account initialization error due to a password change
Gets called when a general error occurs, for example an account initialization error due to a password change
Function
callback
:
Callback function to be notified
.onTokenExpired(callback)
Gets called back when the token expires
Gets called back when the token expires
Function
callback
:
Callback function to be notified
.onTokenWillExpire(callback)
Gets called back every 5 minutes when the remaining token time is less than 30 minutes
Gets called back every 5 minutes when the remaining token time is less than 30 minutes
Function
callback
:
Callback function to be notified
.placeLimitOrder(amount, price, side, instrumentId, resolve, reject)
Place a LIMIT order on the selectedAccount
Place a LIMIT order on the selectedAccount
number
amount
:
The order amount
number
price
:
The trigger price for the order
String
side
:
The order side ('BUY' or 'SELL')
String
instrumentId
:
The instrument id for the order
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "id": "oteF-6eh4", "instrumentId": "abc123", "side": "BUY", "type": "MARKET", "amount": 10000, "status": "PENDING", "price": 0, "lastPrice": 1, "creationDate": 1461149630, "affectedPositions": {}, "stopLoss": null, "takeProfit": null, "executionPrice": null, "sequenceId": 647594837 }
.placeLimitOrderForAccount(accountId, amount, price, side, instrumentId, resolve, reject)
Place a LIMIT order on a specific account
Place a LIMIT order on a specific account
String
accountId
:
The unique id for the account the request goes to
number
amount
:
The order amount
number
price
:
The trigger price for the order.
String
side
:
The order side ('BUY' or 'SELL')
String
instrumentId
:
The instrument id for the order
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "id": "oteF-6eh4", "instrumentId": "abc123", "side": "BUY", "type": "MARKET", "amount": 10000, "status": "PENDING", "price": 0, "lastPrice": 1, "creationDate": 1461149630, "affectedPositions": {}, "stopLoss": null, "takeProfit": null, "executionPrice": null, "sequenceId": 647594837 }
.placeMarketOrder(amount, side, instrumentId, resolve, reject)
Place a MARKET order on the selectedAccount
Place a MARKET order on the selectedAccount
number
amount
:
The order amount
String
side
:
The order side ('BUY' or 'SELL')
String
instrumentId
:
The instrument id for the order
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
tradable.placeMarketOrder(10000, "BUY", "abc123").then(function(order) {
console.log(JSON.stringify(order, null, 2));
}, function(jqXHR) {
console.error("Trade rejected: " + jqXHR.responseJSON.message);
});
This is an example object returned by the callback from this method:
{
"id": "oteF-6eh4",
"instrumentId": "abc123",
"side": "BUY",
"type": "MARKET",
"amount": 10000,
"status": "PENDING",
"price": 0,
"lastPrice": 1,
"creationDate": 1461149630,
"affectedPositions": {},
"stopLoss": null,
"takeProfit": null,
"executionPrice": null,
"sequenceId": 647594837
}
.placeMarketOrderForAccount(accountId, amount, side, instrumentId, resolve, reject)
Place a MARKET order on a specific account
Place a MARKET order on a specific account
String
accountId
:
The unique id for the account the request goes to
number
amount
:
The order amount
String
side
:
The order side ('BUY' or 'SELL')
String
instrumentId
:
The instrument id for the order
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
var accountId = tradable.selectedAccount.uniqueId;
tradable.placeMarketOrderForAccount(accountId, 10000, "BUY", "abc123").then(function(order) {
console.log(JSON.stringify(order, null, 2));
}, function(jqXHR) {
console.error("Trade rejected: " + jqXHR.responseJSON.message);
});
This is an example object returned by the callback from this method:
{
"id": "oteF-6eh4",
"instrumentId": "abc123",
"side": "BUY",
"type": "MARKET",
"amount": 10000,
"status": "PENDING",
"price": 0,
"lastPrice": 1,
"creationDate": 1461149630,
"affectedPositions": {},
"stopLoss": null,
"takeProfit": null,
"executionPrice": null,
"sequenceId": 647594837
}
.placeProtectedOrder(amount, price, side, instrumentId, type, takeProfitPrice, stopLossPrice, currentBidOrAskPrice, resolve, reject)
Place a MARKET, LIMIT or STOP order with Take Profit and/or Stop Loss protections on the selected account. Some accounts require an absolute price for the take profit and others require a price distance (See 'account.protectionEntryTypes'). This method will send the required entry type and value, i.e. it will calculate the distance from the price and send it if the account only supports the 'DISTANCE' entry type or just send the desired take profit or stop loss prices if the 'ABSOLUTE' entry type is supported
Place a MARKET, LIMIT or STOP order with Take Profit and/or Stop Loss protections on the selected account. Some accounts require an absolute price for the take profit and others require a price distance (See 'account.protectionEntryTypes'). This method will send the required entry type and value, i.e. it will calculate the distance from the price and send it if the account only supports the 'DISTANCE' entry type or just send the desired take profit or stop loss prices if the 'ABSOLUTE' entry type is supported
number
amount
:
The order amount
number
price
:
The trigger price for the order (0 if MARKET order)
String
side
:
The order side ('BUY' or 'SELL')
String
instrumentId
:
The instrument id for the order
String
type
:
Order type ('MARKET','LIMIT' or 'STOP')
number
takeProfitPrice
:
Take profit trigger price (null if not desired)
number
stopLossPrice
:
Stop loss trigger price (null if not desired)
number
currentBidOrAskPrice
:
For 'BUY' MARKET orders the ask price for the instrument, for 'SELL' MARKET orders the bid price. It is only required for MARKET orders with protections, for LIMIT and STOP orders pass 0.
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "id": "oteF-6eh4", "instrumentId": "abc123", "side": "BUY", "type": "MARKET", "amount": 10000, "status": "PENDING", "price": 0, "lastPrice": 1, "creationDate": 1461149630, "affectedPositions": {}, "stopLoss": null, "takeProfit": null, "executionPrice": null, "sequenceId": 647594837 }
.placeProtectedOrderForAccount(accountId, amount, price, side, instrumentId, type, takeProfitPrice, stopLossPrice, currentBidOrAskPrice, resolve, reject)
Place a MARKET, LIMIT or STOP order with Take Profit and/or Stop Loss protections on a specific account. Some accounts require an absolute price for the take profit and others require a price distance (See 'account.protectionEntryTypes'). This method will send the required entry type and value, i.e. it will calculate the distance from the price and send it if the account only supports the 'DISTANCE' entry type or just send the desired take profit or stop loss prices if the 'ABSOLUTE' entry type is supported
Place a MARKET, LIMIT or STOP order with Take Profit and/or Stop Loss protections on a specific account. Some accounts require an absolute price for the take profit and others require a price distance (See 'account.protectionEntryTypes'). This method will send the required entry type and value, i.e. it will calculate the distance from the price and send it if the account only supports the 'DISTANCE' entry type or just send the desired take profit or stop loss prices if the 'ABSOLUTE' entry type is supported
String
accountId
:
The unique id for the account the request goes to
number
amount
:
The order amount
number
price
:
The trigger price for the order (0 if MARKET order)
String
side
:
The order side ('BUY' or 'SELL')
String
instrumentId
:
The instrument id for the order
String
type
:
Order type ('MARKET','LIMIT' or 'STOP')
number
takeProfitPrice
:
Take profit trigger price (null if not desired)
number
stopLossPrice
:
Stop loss trigger price (null if not desired)
number
currentBidOrAskPrice
:
For 'BUY' MARKET orders the ask price for the instrument, for 'SELL' MARKET orders the bid price. It is only required for MARKET orders with protections, for LIMIT and STOP orders pass 0.
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "id": "oteF-6eh4", "instrumentId": "abc123", "side": "BUY", "type": "MARKET", "amount": 10000, "status": "PENDING", "price": 0, "lastPrice": 1, "creationDate": 1461149630, "affectedPositions": {}, "stopLoss": null, "takeProfit": null, "executionPrice": null, "sequenceId": 647594837 }
.placeStopOrder(amount, price, side, instrumentId, resolve, reject)
Place a STOP order on the selectedAccount
Place a STOP order on the selectedAccount
number
amount
:
The order amount
number
price
:
The trigger price for the order
String
side
:
The order side ('BUY' or 'SELL')
String
instrumentId
:
The instrument id for the order
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "id": "oteF-6eh4", "instrumentId": "abc123", "side": "BUY", "type": "MARKET", "amount": 10000, "status": "PENDING", "price": 0, "lastPrice": 1, "creationDate": 1461149630, "affectedPositions": {}, "stopLoss": null, "takeProfit": null, "executionPrice": null, "sequenceId": 647594837 }
.placeStopOrderForAccount(accountId, amount, price, side, instrumentId, resolve, reject)
Place a STOP order on a specific account
Place a STOP order on a specific account
String
accountId
:
The unique id for the account the request goes to
number
amount
:
The order amount
number
price
:
The trigger price for the order.
String
side
:
The order side ('BUY' or 'SELL')
String
instrumentId
:
The instrument id for the order
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
This is an example object returned by the callback from this method:
{ "id": "oteF-6eh4", "instrumentId": "abc123", "side": "BUY", "type": "MARKET", "amount": 10000, "status": "PENDING", "price": 0, "lastPrice": 1, "creationDate": 1461149630, "affectedPositions": {}, "stopLoss": null, "takeProfit": null, "executionPrice": null, "sequenceId": 647594837 }
.reducePositionToAmount(positionId, newAmount, resolve, reject)
Reduces the position (on the selectedAccount) size, by setting a new quantity
Reduces the position (on the selectedAccount) size, by setting a new quantity
String
positionId
:
Id of position to reduce
String
newAmount
:
the new amount
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.reducePositionToAmountForAccount(accountId, positionId, newAmount, resolve, reject)
Reduces the position (on a specific account) size, by setting a new quantity
Reduces the position (on a specific account) size, by setting a new quantity
String
accountId
:
The unique id for the account the request goes to
String
positionId
:
Id of position to reduce
String
newAmount
:
the new amount
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.refreshAuthentication(refreshTokenValue, appSecret, resolve, reject)
Refreshes the authentication that was granted when the refresh token was issued
Refreshes the authentication that was granted when the refresh token was issued
String
refreshTokenValue
:
The value of the refresh token.
String
appSecret
:
The client secret of the app that is requesting the refresh
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.reLogin(resolve, reject)
Sometimes when the user connects an account from multiple clients at a time, a re-login might be required to continue trading. To solve this issue, you need to listen to the "reLoginRequired" event and call "reLogin()" for the selected account once the user is ready to re-enable trading.
Sometimes when the user connects an account from multiple clients at a time, a re-login might be required to continue trading. To solve this issue, you need to listen to the "reLoginRequired" event and call "reLogin()" for the selected account once the user is ready to re-enable trading.
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.reLoginForAccount(accountId, resolve, reject)
Sometimes when the user connects an account from multiple clients at a time, a re-login might be required to continue trading. To solve this issue, you need to listen to the "reLoginRequired" event and call "reLoginForAccount(accountId)" once the user is ready to re-enable trading.
Sometimes when the user connects an account from multiple clients at a time, a re-login might be required to continue trading. To solve this issue, you need to listen to the "reLoginRequired" event and call "reLoginForAccount(accountId)" once the user is ready to re-enable trading.
String
accountId
:
Account Id that needs to be re-logged in
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
.removeInstrumentIdFromUpdates(updateClientId, instrumentIdToRemove)
Unsubscribe for the given instrument Id's prices on the account snaphot updates (onAccountUpdated)
Unsubscribe for the given instrument Id's prices on the account snaphot updates (onAccountUpdated)
String
updateClientId
:
Id for the element that is requesting the prices, only when no ids are subscribed to an instrument will the instrument be removed from the updates
String
instrumentIdToRemove
:
Instrument Id to remove from the prices
tradable.removeInstrumentIdFromUpdates("yourCustomId", "401155666");
.roundAmount(instrumentId, amount)
Rounds an amount for a certain instrument using the correspondent decimals
Rounds an amount for a certain instrument using the correspondent decimals
number
:
Rounded amount or null if the provided instrument is not found/invalid number
// In the following example the returned rounded amount should be 10000
var roundedAmount = tradable.roundAmount("EURUSD", 10000.1149);
.roundAmountWithIncrement(instrumentId, amount)
Rounds an amount for a certain instrument using the correspondent decimals AND increment
Rounds an amount for a certain instrument using the correspondent decimals AND increment
number
:
Rounded amount or null if the provided instrument is not found/invalid number
// In the following example the returned rounded amount should be 10000 considering that the increment is 1
var roundedAmount = tradable.roundAmount("EURUSD", 10000.1149);
.roundPrice(instrumentId, price)
Rounds a price for a certain instrument using the correspondent decimals
Rounds a price for a certain instrument using the correspondent decimals
number
:
Rounded price or null if the provided instrument is not found/invalid number
// In the following example the returned rounded price should be 1.11492
var roundedPrice = tradable.roundPrice("EURUSD", 1.114919999999998);
.roundPriceWithIncrement(instrumentId, price)
Rounds a price for a certain instrument using the correspondent decimals AND increment
Rounds a price for a certain instrument using the correspondent decimals AND increment
number
:
Rounded price or null if the provided instrument is not found/invalid number
// In the following example the returned rounded price should be 511.25 considering that the increment for it is 0.25
var roundedPrice = tradable.roundPriceWithIncrement("80813968", 511.22222);
.searchInstruments(query, resolve, reject)
Search for instruments with a specific String for the selectedAccount.
Search for instruments with a specific String for the selectedAccount.
String
query
:
The query used in an instrument search
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
tradable.searchInstruments("EURUS").then(function(instrumentResults) {
console.log(JSON.stringify(instrumentResults, null, 2));
}, function(jqXHR) {
console.error("Error trying to find instruments: " + jqXHR.responseJSON.message);
});
This is an example object returned by the callback from this method:
[
{
"instrumentId": "1",
"symbol": "EURUSD",
"brokerageAccountSymbol": "EUR/USD",
"displayName": "EUR/USD",
"shortDescription": "",
"type": null
}
]
.searchInstrumentsForAccount(accountId, query, resolve, reject)
Search for instruments with a specific String for a specific accountId.
Search for instruments with a specific String for a specific accountId.
String
accountId
:
The unique id for the account the request goes to
String
query
:
The query used in an instrument search
Function
resolve
:
(optional) Success callback for the API call, errors don't get called through this callback
Function
reject
:
(optional) Error callback for the API call
Object
:
If resolve/reject are not specified it returns a Promise for chaining, otherwise it calls the resolve/reject handlers
var accountId = tradable.selectedAccount.uniqueId;
tradable.searchInstrumentsForAccount(accountId, "EURUS").then(function(instrumentResults) {
console.log(JSON.stringify(instrumentResults, null, 2));
}, function(jqXHR) {
console.error("Error trying to find instruments: " + jqXHR.responseJSON.message);
});
This is an example object returned by the callback from this method:
[
{
"instrumentId": "1",
"symbol": "EURUSD",
"brokerageAccountSymbol": "EUR/USD",
"displayName": "EUR/USD",
"shortDescription": "",
"type": null
}
]
.setAccountUpdateFrequencyMillis(accUpdateMillis)
Customize the frequency for account snapshot updates (onAccountUpdated)
Customize the frequency for account snapshot updates (onAccountUpdated)
number
accUpdateMillis
:
Frequency in milliseconds
.setExternalId(externalId)
Saves an external id for user mapping purposes. It is required to set the external id before authentication for tradable to properly map it with all the user entries.
Saves an external id for user mapping purposes. It is required to set the external id before authentication for tradable to properly map it with all the user entries.
String
externalId
:
User id in external system
.setSelectedAccount(accountId, resolve, reject)
Sets the account unique id that will be used for account related API calls
Sets the account unique id that will be used for account related API calls
.showApprovalPage
Redirect to the Tradable account approval page
Redirect to the Tradable account approval page
.showApprovalPageInWindow
Open the Tradable account approval page in a popup window
Open the Tradable account approval page in a popup window
.showBrokerSignUpPage
Redirect to the Tradable Broker sign up page that will allow the user to sign up with a broken
Redirect to the Tradable Broker sign up page that will allow the user to sign up with a broken
.showBrokerSignUpPageInWindow
Open the Tradable Broker sign up page that will allow the user to sign up with a broken in a popup window
Open the Tradable Broker sign up page that will allow the user to sign up with a broken in a popup window
.showLoginPage(brokerId)
Redirect to the Tradable Login page
Redirect to the Tradable Login page
number
brokerId
:
(optional) If the login page needs to be opened for a certain broker, this is the id (v1/brokers)
.showLoginPageInWindow(brokerId)
Open the Tradable Login page in a popup window
Open the Tradable Login page in a popup window
number
brokerId
:
(optional) If the login page needs to be opened for a certain broker, this is the id (v1/brokers)
.signOut
Drops authentication token and notifies embed callbacks
Drops authentication token and notifies embed callbacks
.startCandleUpdates(instrumentId, from, aggregation, callback)
Provides candle updates (new prices) with the same frequency as the account update frequency. The provided candle list will be for the selectedAccount, given instrument Id, aggregation and range (from-to current time). It is only possible to start updates for one instrument, range and aggregation at a time.
Provides candle updates (new prices) with the same frequency as the account update frequency. The provided candle list will be for the selectedAccount, given instrument Id, aggregation and range (from-to current time). It is only possible to start updates for one instrument, range and aggregation at a time.
String
instrumentId
:
The instrument id for the candles
number
from
:
The start of the candle range. In milliseconds since epoch
number
aggregation
:
The aggregation interval in minutes. Allowed values: 1,5,15,30,60,1440,21600,40320
Function
callback
:
Callback function that wiil receive the updates
// Updates for 30 minute Candles starting 3 hours ago:
var from = Date.now() - (1000 * 60 * 60 * 3);
tradable.startCandleUpdates("EURUSD", from, 30, function(data) {
console.log("Received candles: " + JSON.stringify(data, null, 2));
});
This is an example object returned by the callback from this method:
[
{
"timestamp": 1433908800000,
"open": 1.10023,
"close": 1.100054,
"high": 1.100101,
"low": 1.100001,
"volume": 160
}
]
.stopCandleUpdates
Stops the candle updates if any in progress
Stops the candle updates if any in progress
.submitTwoFactorAuthenticationCode(code)
When a twoFactorAuthentication event is fired. If the received object's requiredUserInput field is true, this method will have to be called back with the user's entered two factor authentication code.
When a twoFactorAuthentication event is fired. If the received object's requiredUserInput field is true, this method will have to be called back with the user's entered two factor authentication code.
String
code
:
Two factor authentication code entered by the user