<abstract> new Account()
Account object used by STX.TFC. Derive an account object from this basic template and ensure that each of the functions works correctly and that the data is stored in the specified format.
See Trade From Chart introduction for implementation details.
Example
// Required data format for the TFC Account object.
this.currency="USD";
this.balances={
liquidity: 100000,
unsettledCash: 0,
cash: 100000,
profitLoss: 0,
buyingPower: 200000
};
this.positions={
"IBM":{quantity:1000,basis:126.13, price:129.13, prevClose:123.13, currency:"USD"},
"GE":{quantity:100,basis:26.11, price:24.11, prevClose:26.11, currency:"USD"},
"SPY":{quantity:-1000,basis:187.11, price:187.11, prevClose:190.11, currency:"USD"},
"LNKD":{quantity:-100,basis:230, price:186, prevClose:240, currency:"USD"}
};
this.trades={
"IBM":
[
{id:"IBM001", time:1366206180000, quantity:300, basis:124.13, price:129.13, currency:"USD", protect:{limit:165, stop:135}},
{id:"IBM002", time:1366910520000, quantity:600, basis:127.13, price:129.13, currency:"USD"},
{id:"IBM003", time:1407181680000, quantity:100, basis:126.13, price:129.13, currency:"USD"}
],
"GE":
[
{id:"GE001", time:1433779740000, quantity:100, basis:26.11, price:24.11, currency:"USD", protect:{limit:30, stop:25}}
],
"SPY":
[
{id:"SPY001", time:1419262080000, quantity:-700, basis:190.45, price:187.11, currency:"USD"},
{id:"SPY002", time:1419262380000, quantity:-300, basis:179.32, price:187.11, currency:"USD"}
],
"LNKD":
[
{id:"LNKD001", time:1420740540000, quantity:-100, basis:230, price:186, currency:"USD"}
]
};
this.openOrders={
"IBM":
[
{id:"1", action:"sell", quantity:500, limit:197, tif:"GTC", currency:"USD"},
{id:"2", action:"sell", quantity:500, limit:196, tif:"GTC", currency:"USD"},
{id:"9", tradeid:"IBM001", action:"sell", quantity:300, limit:165, tif:"GTC", currency:"USD", oco:"10"},
{id:"10", tradeid:"IBM001", action:"sell", quantity:300, stop:135, tif:"GTC", currency:"USD", oco:"9"}
],
"TSLA":
[
{id:"3", action:"buy", quantity:10, limit:170, tif:"DAY", currency:"USD"}
],
"GE":
[
{id:"4", tradeid:"GE001", action:"sell", quantity:100, limit:30, tif:"GTC", currency:"USD", oco:"5"},
{id:"5", tradeid:"GE001", action:"sell", quantity:100, stop:25, tif:"GTC", currency:"USD", oco:"4"}
],
"LNKD":
[
{id:"6", action:"buy", quantity:100, limit:112, tif:"DAY", currency:"USD", oto:
[
{id:"7", action:"sell", quantity:100, limit:130, tif:"GTC", currency:"USD", oco:"8"},
{id:"8", action:"sell", quantity:100, stop:110, tif:"GTC", currency:"USD", oco:"7"}
]
},
{id:"9", action:"buy", quantity:100, limit:112, tif:"DAY", currency:"USD", oto:
[
{id:"10", action:"sell", quantity:100, limit:130, tif:"GTC", currency:"USD", oco:true} // if only one leg, set oco to true.
]
},
]
};
this.config={
oto:true,
oco:true,
closeAll:true, // Set to true to enable close all capability
disableModifyOrderQuantity:false,
gtcOnly:false,
tradeActions:true // set to true to enable to protection/actions tab in the enhanced view
reducePosition:true,
hedging:false,
vsp:""
};
Methods
-
<static> Demo()
-
Demo account - A demo implementation of the STX.Account abstract class. This class supports placing, modifying and canceling orders. The openOrders will reflect the changes but are never executed. Market orders execute immediately and update positions. Balances and P&L are static.
You should add your own code to the account fetch and order management functions. See Trade From Chart introduction for implementation details. -
cancelOrder(tfc, order, cb)
-
Abstract for Canceling an order
Parameters:
Name Type Description tfcSTX.TFC The TFC object
orderobject The order to cancel, in native TFC format. The abstract interface is responsible for converting this order into the format required by the broker interface.
cbfunction Callback function fc(err)
-
closeAllPositions(tfc, cb)
-
Abstract for Closing all positions
Parameters:
Name Type Description tfcSTX.TFC The TFC object
cbfunction Callback function fc(err)
-
closePosition(tfc, position, cb)
-
Abstract for Closing a position
Parameters:
Name Type Description tfcSTX.TFC The TFC object
positionobject position to close
cbfunction Callback function fc(err)
-
closeTrade(tfc, trade, cb)
-
Abstract for Closing a trade
Parameters:
Name Type Description tfcSTX.TFC The TFC object
tradeobject trade to close
cbfunction Callback function fc(err)
-
confirmOrder(tfc, order, cb)
-
Confirm an order before placing it. This is optional and only for firms that support a server side order confirmation (Are you sure) process. If not supported then simply call the callback
Parameters:
Name Type Description tfcSTX.TFC The TFC object
orderobject The order to confirm
cbConfirmation The callback when confirmed with Confirmation object.
-
fetchBalances(cb)
-
Function used for fetching balances. Your implementation should set
this.balances. The server fetch callback function should return data in STX.Account.Balances format, or you must format it once received.Parameters:
Name Type Description cbfuncion Required Callback function to track data fetch progress. Do not remove.
-
fetchOpenOrders(cb)
-
Function used for fetching Open Orders. Your implementation should set
this.openOrders. The server fetch callback function should return data in STX.Account.OpenOrders format, or you must format it once received.Parameters:
Name Type Description cbfuncion Required Callback function to track data fetch progress. Do not remove.
-
fetchPositions(cb)
-
Function used for fetching Positions. Your implementation should
set this.positions. The server fetch callback function should return data in STX.Account.Positions format, or you must format it once receivedParameters:
Name Type Description cbfuncion Required Callback function to track data fetch progress. Do not remove.
-
fetchTrades(cb)
-
Function used for fetching Trades. Your implementation should
set this.trades. The server fetch callback function should return data in STX.Account.Trades format, or you must format it once receivedParameters:
Name Type Description cbfuncion Required Callback function to track data fetch progress. Do not remove.
-
isForex(symbol)
-
Function used for determining FOREX. Your implementation should check symbol properties
Parameters:
Name Type Description symbolString Symbol to test
- Since:
-
- 2015-11-1
Returns:
true if Forex
- Type
- boolean
-
placeOrder(tfc, order, cb)
-
Abstract for Placing an order
Parameters:
Name Type Description tfcSTX.TFC The TFC object
orderobject The order, in native TFC format. The abstract interface is responsible for converting this order into the format required by the broker interface.
Properties
Name Type Argument Description typestring "order" (as opposed to "replace")
symbolstring The security symbol
actionstring "buy","sell"
quantitynumber The quantity to trade
limitnumber <optional>
The limit price, optional (if no limit or stop then the order is a market order)
stopnumber <optional>
The stop price, optional.
marketIfTouchednumber <optional>
The market if touched price, optional.
tifstring "GTC" or "DAY"
otoarray <optional>
Optional OTO array, each array element contains an order in this same format
cbfunction Callback function fc(err)
-
replaceOrder(tfc, order, cb)
-
Abstract for Modifying an order (cancel/replace)
Parameters:
Name Type Description tfcSTX.TFC The TFC object
orderobject The modification order, in native TFC format. The abstract interface is responsible for converting this order into the format required by the broker interface.
Properties
Name Type Argument Description typestring "replace" (as opposed to "order")
symbolstring The security symbol
idstring The ID of the order being modified
actionstring "buy" or "sell"
limitobject Limit price (if one exists)
Properties
Name Type Description oldnumber Old limit price if there was one
newnumber New limit price if there is one
stopobject Stop price (if one exists)
Properties
Name Type Description oldnumber Old stop price if there was one
newnumber New stop price if there is one
marketIfTouchedobject Market If Touched price (if one exists)
Properties
Name Type Description oldnumber Old market if touched price if there was one
newnumber New market if touched price if there is one
quantityobject Quantity tuple
Properties
Name Type Description oldnumber Old quantity
newnumber New quantity
tifobject TIF tuple
Properties
Name Type Description oldstring Old TIF
newstring New TIF
otoobject <optional>
Optional tuple containing old and new oto
Properties
Name Type Argument Description oldobject <optional>
Old OTO
newobject <optional>
New OTO
cbfunction Callback function fc(err)
-
setProtection(tfc, array, cb)
-
Abstract for protecting a trade
Parameters:
Name Type Description tfcSTX.TFC The TFC object
arrayArray of orders constituting protection (the bracket)
cbfunction Callback function fc(err)
-
tradability(symbol, cb)
-
Determines the tradability of the requested symbol. This includes whether it's tradable at all and whether it can be shorted. Override this with your own firm's logic and query.
Parameters:
Name Type Description symbolstring Symbol to check
cbTradability Callback with tradability status
-
tradesLikeForex(symbol)
-
Function used for determining labeling throughout. Your implementation should check symbol properties
Parameters:
Name Type Description symbolString Symbol to test
- Since:
-
- 2015-11-1
Returns:
true if using Forex labeling (pips, amount, units) vs equity labeling (points, dollars, shares)
- Type
- boolean
Type Definitions
-
Balances(balances)
-
Balances object required by Account.Balances
Parameters:
Name Type Description balancesobject A balances object
Properties
Name Type Description liquiditynumber The liquidation value for the account
cashnumber Trading cash in the account
profitLossnumber Gain or loss in the account
unsettledCashnumber Unsettled cash for the account
buyingPowernumber Buying power for the account. Null if not a margin account.
Example
this.balances={ liquidity: 100000, unsettledCash: 0, cash: 100000, profitLoss: 0, buyingPower: 200000 }; -
Confirmation( [commission] [, fees] [, total] [, errors] [, warnings])
-
Parameters:
Name Type Argument Description commissionnumber <optional>
The commission amount if available
feesnumber <optional>
The fee amount if available
totalnumber <optional>
Total amount of trade
errorsarray <optional>
Any errors
warningsarray <optional>
Any warnings
-
OpenOrders(openOrders)
-
OpenOrders STX.Account.OpenOrders
Parameters:
Name Type Description openOrdersobject An open orders object. Contains a field for each security symbol. Each symbol contains an array of open orders. It is assumed that each open order is referenced by a unique id. An optional "oco" field should reference the id of a linked order. An optional "oto" field contains an array of orders that will be triggered on execution.
Example
this.openOrders={ "IBM": [ {id:"1", action:"sell", quantity:500, limit:197, tif:"GTC", currency:"USD"}, {id:"2", action:"sell", quantity:500, limit:196, tif:"GTC", currency:"USD"}, {id:"9", tradeid:"IBM001", action:"sell", quantity:300, limit:165, tif:"GTC", currency:"USD", oco:"10"}, {id:"10", tradeid:"IBM001", action:"sell", quantity:300, stop:135, tif:"GTC", currency:"USD", oco:"9"} ], "TSLA": [ {id:"3", action:"buy", quantity:10, limit:170, tif:"DAY", currency:"USD"} ], "GE": [ {id:"4", tradeid:"GE001", action:"sell", quantity:100, limit:30, tif:"GTC", currency:"USD", oco:"5"}, {id:"5", tradeid:"GE001", action:"sell", quantity:100, stop:25, tif:"GTC", currency:"USD", oco:"4"} ], "LNKD": [ {id:"6", action:"buy", quantity:100, limit:112, tif:"DAY", currency:"USD", oto: [ {id:"7", action:"sell", quantity:100, limit:130, tif:"GTC", currency:"USD", oco:"8"}, {id:"8", action:"sell", quantity:100, stop:110, tif:"GTC", currency:"USD", oco:"7"} ] }, {id:"9", action:"buy", quantity:100, limit:112, tif:"DAY", currency:"USD", oto: [ {id:"10", action:"sell", quantity:100, limit:130, tif:"GTC", currency:"USD", oco:true} // if only one leg, set oco to true. ] }, ] }; -
Positions(positions)
-
Positions object required by Account.Positions
Parameters:
Name Type Description positionsobject A positions object. Contains a field for each security symbol.
Example
this.positions={ "IBM":{quantity:1000,basis:126.13, price:129.13, prevClose:123.13, currency:"USD"}, // "basis" is the (current, cumulative) cost-basis for the position "GE":{quantity:100,basis:26.11, price:24.11, prevClose:26.11, currency:"USD"}, "SPY":{quantity:-1000,basis:187.11, price:187.11, prevClose:190.11, currency:"USD"}, // Use negative values for short positions "LNKD":{quantity:-100,basis:230, price:186, prevClose:240, currency:"USD"} }; -
Tradability(tradable, shortable, marketable)
-
Parameters:
Name Type Description tradableboolean True if the symbol can be traded
shortableboolean True if the symbol can be shorted
marketableboolean True if the symbol can be traded as a market order
-
Trades(trades)
-
Trades object required by Account.Trades
Parameters:
Name Type Description tradesobject A trades object. Contains a field for each security symbol. Each symbol contains an array of trades. It is assumed that each trade is referenced by a unique id. An optional "protect" field should reference the ids of a linked take profit and/or stop loss order.
Example
this.trades={ "IBM": [ {id:"IBM001", time:1366206180000, quantity:300, basis:124.13, price:129.13, currency:"USD", protect:{limit:165, stop:135}}, {id:"IBM002", time:1366910520000, quantity:600, basis:127.13, price:129.13, currency:"USD"}, {id:"IBM003", time:1407181680000, quantity:100, basis:126.13, price:129.13, currency:"USD"} ], "GE": [ {id:"GE001", time:1433779740000, quantity:100, basis:26.11, price:24.11, currency:"USD", protect:{limit:30, stop:25}} ], "SPY": [ {id:"SPY001", time:1419262080000, quantity:-700, basis:190.45, price:187.11, currency:"USD"}, {id:"SPY002", time:1419262380000, quantity:-300, basis:179.32, price:187.11, currency:"USD"}], "LNKD": [ {id:"LNKD001", time:1420740540000, quantity:-100, basis:230, price:186, currency:"USD"} ] };