@stoqey/ibkr
Version:
NodeJS Interactive Brokers wrapper & utilities using @stoqey/ib
70 lines • 3.5 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccountSummary = void 0;
var IBKRConnection_1 = __importDefault(require("../connection/IBKRConnection"));
var utils_1 = require("../utils");
var DEFAULT_TAGS = "AccountType,NetLiquidation,TotalCashValue,SettledCash,AccruedCash,BuyingPower,EquityWithLoanValue,PreviousDayEquityWithLoanValue,GrossPositionValue,RegTEquity,RegTMargin,SMA,InitMarginReq,MaintMarginReq,AvailableFunds,ExcessLiquidity,Cushion,FullInitMarginReq,FullMaintMarginReq,FullAvailableFunds,FullExcessLiquidity,LookAheadNextChange,LookAheadInitMarginReq,LookAheadMaintMarginReq,LookAheadAvailableFunds,LookAheadExcessLiquidity,HighestSeverity,DayTradesRemaining,Leverage";
;
var AccountSummary = /** @class */ (function () {
function AccountSummary() {
var _this = this;
this.accountSummary = {};
this.init = function () {
var ib = IBKRConnection_1.default.Instance.ib;
if (!_this.ib) {
_this.ib = ib;
}
};
this.getAccountSummaryUpdates = function (group, tags) {
if (group === void 0) { group = "All"; }
if (tags === void 0) { tags = DEFAULT_TAGS; }
_this.GetAccountSummaryUpdates = _this.ib.getAccountSummary(group, tags).subscribe(function (accountSummaryUpdate) {
var firstAccount = accountSummaryUpdate.all.values().next().value;
var accountId = accountSummaryUpdate.all.keys().next().value;
var accountSummary = _this.accountSummary;
accountSummary.accountId = accountId;
firstAccount.forEach(function (tag, tagName) {
tag.forEach(function (value, currency) {
var tagValue = isNaN(+value.value) ? value.value : +value.value;
var tagCurrency = !currency ? null : currency;
if (!accountSummary[tagName]) {
accountSummary[tagName] = {};
}
;
if (tagValue) {
accountSummary[tagName].value = tagValue;
}
if (tagCurrency) {
accountSummary[tagName].currency = tagCurrency;
}
});
});
(0, utils_1.log)("AccountSummary: ".concat(accountId), "NetLiquidation: ".concat(accountSummary.NetLiquidation.value, "(").concat(accountSummary.NetLiquidation.currency, ")"));
_this.accountSummary = accountSummary;
});
};
this.unsubscribeAccountSummary = function () {
_this.GetAccountSummaryUpdates.unsubscribe();
};
}
Object.defineProperty(AccountSummary, "Instance", {
get: function () {
return this._instance || (this._instance = new this());
},
enumerable: false,
configurable: true
});
Object.defineProperty(AccountSummary.prototype, "getAccountSummary", {
get: function () {
return this.accountSummary;
},
enumerable: false,
configurable: true
});
return AccountSummary;
}());
exports.AccountSummary = AccountSummary;
//# sourceMappingURL=AccountSummary.js.map