<abstract> new Account()
Account object used by CIQ.TFC.
This will contain all of the data related to this account, including initial configuration and account configuration.
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.
For proper functionality, this object should only be pre-set with the desired CIQ.Account.Config and currency. Let let CIQ.Account.Balances, CIQ.Account.OpenOrders, CIQ.Account.Positions and CIQ.Account.Trades be loaded using their corresponding fetch methods and not set manually in the Account object.
currency
is a simplestring
. See CIQ.convertCurrencyCode and CIQ.Account#tradesLikeForex for more details on labeling}
For example:
CIQ.Account.Demo = function() {
this.currency = "EUR";
this.config = {
oto: false,
oco: false,
closeAll: true,
tradeActions: true,
vsp: "M"
}
}
See the Trade From Chart Introduction for implementation details. See plugins/tfc/tfc-demo.js for a full demo account sample implementation.
Example
Sample data format for the Trade From Chart CIQ.Account
object.
// After balances, openOrders, positions and trades are loaded using their corresponding fetch methods.
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"},
"MSFT":{quantity:-100,basis:230, price:58, 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"}
],
"MSFT":
[
{id:"MSFT001", time:1420740540000, quantity:-100, basis:230, price:58, 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"}
],
"MSFT":
[
{id:"6", action:"buy", quantity:100, limit:61, tif:"DAY", currency:"USD", oto:
[
{id:"7", action:"sell", quantity:100, limit:61, tif:"GTC", currency:"USD", oco:"8"},
{id:"8", action:"sell", quantity:100, stop:61, tif:"GTC", currency:"USD", oco:"7"}
]
},
{id:"9", action:"buy", quantity:100, limit:61, tif:"DAY", currency:"USD", oto:
[
// If only one leg, set oco to true.
{id:"10", action:"sell", quantity:100, limit:61, tif:"GTC", currency:"USD", oco: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: ""
};
Classes
Members
-
Poller :object
-
Polling object. This will periodically update the account information.
Type:
- object
-
balances :object
-
Account balances
Type:
- object
-
openOrders :object
-
Open orders
Type:
- object
-
positions :object
-
Account positions
Type:
- object
-
trades :object
-
Trades" from Forex systems. If this exists then the "lots" view will be enabled.
Type:
- object
Methods
-
cancelOrder(tfc, order, cb)
-
Abstract for Canceling an order
Parameters:
Name Type Description tfc
CIQ.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
CIQ.TFC The TFC object
cb
function Callback function fc(err)
-
closePosition(tfc, position, cb)
-
Abstract for Closing a position
Parameters:
Name Type Description tfc
CIQ.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
CIQ.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
CIQ.TFC The TFC object
order
object The order to confirm
cb
function The callback when confirmed with Confirmation object
-
disconnect()
-
Disconnect an account when done using it. This should be called when detaching an account. If a Poller exists and is polling for quote updates, should stop the polling. See tfc-demo.js for example of a Poller.
- Since:
-
7.0.0
-
fetchBalances(cb)
-
Function used for fetching balances. Your implementation should set
this.balances
inside this function. The server fetch callback function should return data in CIQ.Account.Balances format, or you must format it once received.Parameters:
Name Type Description cb
function 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
inside this function. The server fetch callback function should return data in CIQ.Account.OpenOrders format, or you must format it once received.Parameters:
Name Type Description cb
function Required Callback function to track data fetch progress. Do not remove.
-
fetchPositions(cb)
-
Function used for fetching Positions. Your implementation should
set this.positions
inside this function. The server fetch callback function should return data in CIQ.Account.Positions format, or you must format it once receivedParameters:
Name Type Description cb
function Required Callback function to track data fetch progress. Do not remove.
-
fetchTrades(cb)
-
Function used for fetching Trades. Your implementation should
set this.trades
inside this function. The server fetch callback function should return data in CIQ.Account.Trades format, or you must format it once receivedParameters:
Name Type Description cb
function Required Callback function to track data fetch progress. Do not remove.
-
getPoller()
-
The Poller object factory function invoked by the CIQ.Account constructor. The return value of this function is assigned to the
Poller
property of CIQ.Account instances. CIQ.Account provides the prototype object of derived custom account objects such asCIQ.Account.Demo
. ThePoller
property can then be accessed on the prototype object, for example:CIQ.Account.Demo = function () {...}; CIQ.inheritsFrom(CIQ.Account.Demo, CIQ.Account); CIQ.Account.Demo.prototype.Poller.intervals = {...};
The poller updates the account at intervals you specify in the
Poller.intervals
object. The object should contain two properties:quotes
— The number of milliseconds between updates of the bid and ask data and all pricing in the account holdingsaccount
— The number of milliseconds between updates of the holdings themselves
Set the polling intervals as follows:
CIQ.Account.Demo.prototype.Poller.intervals = { "quotes": {timer: null, poll: 5000}, // Five-second poll of the quotes. "account": {timer: null, poll: 20000} // 20-second poll of the account data. };
See the tfc-demo.js file in the plugins/tfc folder for an example account implementation.
- Since:
-
8.1.0 Replaced the
CIQ.Account.prototype.Poller
property definition.
Returns:
A poller of the form:
{ tfcs: [], // TFC instances associated with this account. intervals: {}, // Polling intervals. startPolling: function(tfc) {...}, // Adds the TFC parameter to this account and starts the quotes and account polling. stopPolling: function() {...}, // Stops the quotes and account polling. update: function(tfc, updateType) {...}, // Updates quote or account information for this account's TFC instances. updateQuote: function() {...}, // Updates quotes on this account's TFC instances. updateAccount: function() {...}, // Updates positions and trades on this account's TFC instances. removeInstance: function(tfc) {...} // Removes the TFC parameter instance from this account. }
- Type
- object
-
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
CIQ.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", “short", “cover"
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.<object> <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
CIQ.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", "sell", “short", “cover"
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, order, cb)
-
Abstract for protecting a trade
Parameters:
Name Type Description tfc
CIQ.TFC The TFC object
order
object | Array.<object> 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
function Callback with tradability status