<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 tfc
STX.TFC The TFC object
order
object 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.
cb
function Callback function fc(err)
-
closeAllPositions(tfc, cb)
-
Abstract for Closing all positions
Parameters:
Name Type Description tfc
STX.TFC The TFC object
cb
function Callback function fc(err)
-
closePosition(tfc, position, cb)
-
Abstract for Closing a position
Parameters:
Name Type Description tfc
STX.TFC The TFC object
position
object position to close
cb
function Callback function fc(err)
-
closeTrade(tfc, trade, cb)
-
Abstract for Closing a trade
Parameters:
Name Type Description tfc
STX.TFC The TFC object
trade
object trade to close
cb
function 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 tfc
STX.TFC The TFC object
order
object The order to confirm
cb
Confirmation 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 cb
funcion 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 cb
funcion 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 cb
funcion 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 cb
funcion 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 symbol
String 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 tfc
STX.TFC The TFC object
order
object 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 type
string "order" (as opposed to "replace")
symbol
string The security symbol
action
string "buy","sell"
quantity
number The quantity to trade
limit
number <optional>
The limit price, optional (if no limit or stop then the order is a market order)
stop
number <optional>
The stop price, optional.
marketIfTouched
number <optional>
The market if touched price, optional.
tif
string "GTC" or "DAY"
oto
array <optional>
Optional OTO array, each array element contains an order in this same format
cb
function Callback function fc(err)
-
replaceOrder(tfc, order, cb)
-
Abstract for Modifying an order (cancel/replace)
Parameters:
Name Type Description tfc
STX.TFC The TFC object
order
object 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 type
string "replace" (as opposed to "order")
symbol
string The security symbol
id
string The ID of the order being modified
action
string "buy" or "sell"
limit
object Limit price (if one exists)
Properties
Name Type Description old
number Old limit price if there was one
new
number New limit price if there is one
stop
object Stop price (if one exists)
Properties
Name Type Description old
number Old stop price if there was one
new
number New stop price if there is one
marketIfTouched
object Market If Touched price (if one exists)
Properties
Name Type Description old
number Old market if touched price if there was one
new
number New market if touched price if there is one
quantity
object Quantity tuple
Properties
Name Type Description old
number Old quantity
new
number New quantity
tif
object TIF tuple
Properties
Name Type Description old
string Old TIF
new
string New TIF
oto
object <optional>
Optional tuple containing old and new oto
Properties
Name Type Argument Description old
object <optional>
Old OTO
new
object <optional>
New OTO
cb
function Callback function fc(err)
-
setProtection(tfc, array, cb)
-
Abstract for protecting a trade
Parameters:
Name Type Description tfc
STX.TFC The TFC object
array
Array of orders constituting protection (the bracket)
cb
function 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 symbol
string Symbol to check
cb
Tradability Callback with tradability status
-
tradesLikeForex(symbol)
-
Function used for determining labeling throughout. Your implementation should check symbol properties
Parameters:
Name Type Description symbol
String 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 balances
object A balances object
Properties
Name Type Description liquidity
number The liquidation value for the account
cash
number Trading cash in the account
profitLoss
number Gain or loss in the account
unsettledCash
number Unsettled cash for the account
buyingPower
number 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 commission
number <optional>
The commission amount if available
fees
number <optional>
The fee amount if available
total
number <optional>
Total amount of trade
errors
array <optional>
Any errors
warnings
array <optional>
Any warnings
-
OpenOrders(openOrders)
-
OpenOrders STX.Account.OpenOrders
Parameters:
Name Type Description openOrders
object 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 positions
object 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 tradable
boolean True if the symbol can be traded
shortable
boolean True if the symbol can be shorted
marketable
boolean True if the symbol can be traded as a market order
-
Trades(trades)
-
Trades object required by Account.Trades
Parameters:
Name Type Description trades
object 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"} ] };