Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
feat(v20): support rest-v20 calls
Browse files Browse the repository at this point in the history
This is a massive change due to breaking changes of a new REST calls.
There is something to complete (and to fix).
  • Loading branch information
albertosantini committed Nov 1, 2016
1 parent 129f6de commit 178db02
Show file tree
Hide file tree
Showing 23 changed files with 264 additions and 219 deletions.
30 changes: 11 additions & 19 deletions src/client/app/account/account.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<md-content ng-show="$ctrl.account.accountId">
<b>Account Summary ({{ $ctrl.account.accountCurrency }}) {{ $ctrl.account.timestamp | date:"MMM d, HH:mm:ss" }}</b>
<md-content ng-show="$ctrl.account.id">
<b>Account Summary ({{ $ctrl.account.currency }}) {{ $ctrl.account.timestamp | date:"MMM d, HH:mm:ss" }}</b>

<md-list layout="column">
<md-item layout="row" layout-align="space-between end">
Expand All @@ -8,47 +8,39 @@
</md-item>
<md-item layout="row" layout-align="space-between end">
<b>Unrealized P&amp;L</b>
<span>{{ $ctrl.account.unrealizedPl | number: 2 }}</span>
<span>{{ $ctrl.account.unrealizedPL | number: 2 }}</span>
</md-item>
<md-item layout="row" layout-align="space-between end">
<b>Unrealized P&amp;L (%)</b>
<span>{{ $ctrl.account.unrealizedPlPerc | number: 2 }}</span>
<span>{{ $ctrl.account.unrealizedPLPercent | number: 2 }}</span>
</md-item>
<md-item layout="row" layout-align="space-between end">
<b>Net Asset Value</b>
<span>{{ $ctrl.account.netAssetValue | number: 2 }}</span>
<span>{{ $ctrl.account.NAV | number: 2 }}</span>
</md-item>
<!--
<md-item layout="row" layout-align="space-between end">
<b>Margin Alert</b>
<span>{{ $ctrl.account.marginAlert }}</span>
</md-item>
-->
<md-item layout="row" layout-align="space-between end">
<b>Realized P&amp;L</b>
<span>{{ $ctrl.account.realizedPl | number: 2 }}</span>
<span>{{ $ctrl.account.pl | number: 2 }}</span>
</md-item>
<md-item layout="row" layout-align="space-between end">
<b>Margin Used</b>
<span>{{ $ctrl.account.marginUsed | number: 2 }}</span>
<span>{{ $ctrl.account.marginCallMarginUsed | number: 2 }}</span>
</md-item>
<md-item layout="row" layout-align="space-between end">
<b>Margin Available</b>
<span>{{ $ctrl.account.marginAvail | number: 2 }}</span>
<span>{{ $ctrl.account.marginAvailable | number: 2 }}</span>
</md-item>
<!--
<md-item layout="row" layout-align="space-between end">
<b>Margin Closeout Value</b>
<span>{{ $ctrl.account.marginCloseoutValue }}</span>
<span>{{ $ctrl.account.marginCloseoutPositionValue | number: 2 }}</span>
</md-item>
<md-item layout="row" layout-align="space-between end">
<b>Margin Closeout Value (%)</b>
<span>{{ $ctrl.account.marginCloseoutValuePerc }}</span>
<span>{{ $ctrl.account.marginCloseoutPercent | number: 2 }}</span>
</md-item>
<md-item layout="row" layout-align="space-between end">
<b>Position Value</b>
<span>{{ $ctrl.account.positionValue }}</span>
<span>{{ $ctrl.account.positionValue | number: 2 }}</span>
</md-item>
-->
</md-list>
</md-content>
6 changes: 3 additions & 3 deletions src/client/app/account/accounts-bottomsheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<md-list-item ng-repeat="account in vm.accounts">
<md-button aria-label="{{account.accountName}}"
ng-click="vm.onAccountClick($index)">
<span>{{ account.accountName }}</span>
<span>{{ account.accountId }}</span>
<span>{{ account.accountCurrency }}</span>
<!-- <span>{{ account.accountName }}</span> -->
<span>{{ account.id }}</span>
<!-- <span>{{ account.accountCurrency }}</span> -->
</md-button>
</md-list-item>
</md-list>
Expand Down
11 changes: 5 additions & 6 deletions src/client/app/account/accounts.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@
}

if (!accounts.length) {
angular.merge(account, response.data);
angular.merge(account, response.data.account);

account.timestamp = new Date();

account.unrealizedPlPerc =
account.unrealizedPl / account.balance * 100;
account.netAssetValue =
account.balance + account.unrealizedPl;
account.unrealizedPLPercent =
account.unrealizedPL / account.balance * 100;

if (!account.instruments) {
$http.post("/api/instruments", {
Expand All @@ -67,7 +65,8 @@
account.instruments = instruments.data;
account.pips = {};
angular.forEach(account.instruments, function (i) {
account.pips[i.instrument] = i.pip;
account.pips[i.name] =
Math.pow(10, i.pipLocation);
});
});
}
Expand Down
4 changes: 0 additions & 4 deletions src/client/app/activity/activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<b flex="10">Market</b>
<b flex="5">Units</b>
<b flex="10">Price</b>
<b flex="10">Interest</b>
<b flex="5">Profit</b>
<b flex="10">Balance</b>
<b flex="10">Date/Time</b>
Expand All @@ -20,9 +19,6 @@
<span flex="10">{{ activity.instrument }}</span>
<span flex="5">{{ activity.units | number }}</span>
<span flex="10">{{ activity.price }}</span>
<span flex="10" ng-class="activity.interest >= 0 ? 'highlight-green' : 'highlight-red'">
{{ activity.interest }}
</span>
<span flex="10" ng-class="activity.pl >= 0 ? 'highlight-green' : 'highlight-red'">
{{ activity.pl | number:4 }}
</span>
Expand Down
15 changes: 9 additions & 6 deletions src/client/app/activity/activity.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
.module("argo")
.factory("activityService", activityService);

activityService.$inject = ["$http", "$q", "sessionService"];
function activityService($http, $q, sessionService) {
activityService.$inject = ["$http", "$q",
"sessionService", "accountsService"];
function activityService($http, $q, sessionService, accountsService) {
var activities = [],
service = {
getActivities: getActivities,
Expand All @@ -16,15 +17,18 @@
return service;

function getActivities() {
var deferred = $q.defer();
var deferred = $q.defer(),
account = accountsService.getAccount(),
lastTransactionID = account.lastTransactionID;

sessionService.isLogged().then(function (credentials) {
$http.post("/api/transactions", {
environment: credentials.environment,
token: credentials.token,
accountId: credentials.accountId
accountId: credentials.accountId,
lastTransactionID: lastTransactionID
}).then(function (transactions) {
activities = transactions.data;
activities = transactions.data.reverse();
deferred.resolve(activities);
});
});
Expand All @@ -39,7 +43,6 @@
instrument: activity.instrument,
units: activity.units,
price: activity.price,
interest: activity.interest,
pl: activity.pl,
// PROFIT (PIPS)
// PROFIT (%)
Expand Down
2 changes: 0 additions & 2 deletions src/client/app/charts/charts.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
var instrument = opt && opt.instrument || "EUR_USD",
granularity = opt && opt.granularity || "M5",
count = opt && opt.count || 251,
candleFormat = opt && opt.candleFormat || "midpoint",
alignmentTimezone = opt && opt.alignmentTimezone
|| "America/New_York",
dailyAlignment = opt && opt.dailyAlignment || "0";
Expand All @@ -31,7 +30,6 @@
instrument: instrument,
granularity: granularity,
count: count,
candleFormat: candleFormat,
alignmentTimezone: alignmentTimezone,
dailyAlignment: dailyAlignment
}).then(function (candles) {
Expand Down
83 changes: 55 additions & 28 deletions src/client/app/charts/order-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
vm.changeMarket = changeMarket;
vm.changeMeasure = changeMeasure;

vm.type = "market";
vm.type = "MARKET";
vm.side = params.side;
vm.instruments = params.instruments;
vm.selectedInstrument = params.selectedInstrument;
Expand Down Expand Up @@ -56,18 +56,19 @@
return;
}

fixed = (pips[vm.selectedInstrument].match(/0/g) || []).length;
fixed = ((pips[vm.selectedInstrument] + "")
.match(/0/g) || []).length;

vm.measure = "price";
vm.step = parseFloat(pips[vm.selectedInstrument]);
if (vm.side === "buy") {
vm.quote = price && price.ask;
vm.quote = parseFloat(price && price.ask);
vm.takeProfit = parseFloat((vm.quote + vm.step * 10)
.toFixed(fixed));
vm.stopLoss = parseFloat((vm.quote - vm.step * 10)
.toFixed(fixed));
} else {
vm.quote = price && price.bid;
vm.quote = parseFloat(price && price.bid);
vm.takeProfit = parseFloat((vm.quote - vm.step * 10)
.toFixed(fixed));
vm.stopLoss = parseFloat((vm.quote + vm.step * 10)
Expand Down Expand Up @@ -102,7 +103,10 @@
vm.answer = function (action) {
var order = {},
isBuy = vm.side === "buy",
isMeasurePips = vm.measure === "pips";
isMeasurePips = vm.measure === "pips",
fixed = ((pips[vm.selectedInstrument] + "")
.match(/0/g) || []).length;



$mdDialog.hide(action);
Expand All @@ -111,78 +115,101 @@

order.instrument = vm.selectedInstrument;
order.units = vm.units;
if (vm.units && !isBuy) {
order.units = "-" + order.units;
}

order.side = vm.side;
order.type = vm.type;

if (order.type === "limit") {
if (order.type === "LIMIT") {
order.price = vm.quote;
order.expiry = new Date(Date.now() + vm.selectedExpire);
}

if (isMeasurePips) {
if (vm.isLowerBound) {
order.lowerBound = parseFloat(vm.quote -
vm.step * vm.lowerBound);
order.priceBound =
parseFloat(vm.quote - vm.step * vm.lowerBound) + "";
}
if (vm.isUpperBound) {
order.upperBound = parseFloat(vm.quote +
vm.step * vm.lowerBound);
order.priceBound =
parseFloat(vm.quote + vm.step * vm.upperBound) + "";
}
if (isBuy) {
if (vm.isTakeProfit) {
order.takeProfit = parseFloat(vm.quote +
vm.step * vm.takeProfit);
order.takeProfitOnFill = {};
order.takeProfitOnFill.price =
parseFloat(vm.quote + vm.step * vm.takeProfit) + "";
}
if (vm.isStopLoss) {
order.stopLoss = parseFloat(vm.quote -
vm.step * vm.stopLoss);
order.stopLossOnFill = {};
order.order.takeProfitOnFill.price =
parseFloat(vm.quote - vm.step * vm.stopLoss) + "";
}
} else {
if (vm.isTakeProfit) {
order.takeProfit = parseFloat(vm.quote -
vm.step * vm.takeProfit);
order.takeProfitOnFill = {};
order.takeProfitOnFill.price =
parseFloat(vm.quote - vm.step * vm.takeProfit) + "";
}
if (vm.isStopLoss) {
order.stopLoss = parseFloat(vm.quote +
vm.step * vm.stopLoss);
order.stopLossOnFill = {};
order.order.takeProfitOnFill.price =
parseFloat(vm.quote + vm.step * vm.stopLoss) + "";
}
}
} else {
if (vm.isLowerBound) {
order.lowerBound = vm.lowerBound;
order.priceBound = vm.lowerBound + "";
}
if (vm.isUpperBound) {
order.upperBound = vm.upperBound;
order.priceBound = vm.upperBound + "";
}
if (vm.isTakeProfit) {
order.takeProfit = vm.takeProfit;
order.takeProfitOnFill = {};
order.takeProfitOnFill.price = vm.takeProfit + "";
}
if (vm.isStopLoss) {
order.stopLoss = vm.stopLoss;
order.stopLossOnFill = {};
order.stopLossOnFill.price = vm.stopLoss + "";
}
}
if (vm.isTrailingStop) {
order.trailingStop = vm.trailingStop;
order.trailingStopLossOnFill = {};
if (isBuy) {
order.trailingStopLossOnFill.distance =
(vm.quote - vm.step * vm.trailingStop).toFixed(fixed);
} else {
order.trailingStopLossOnFill.distance =
(vm.quote + vm.step * vm.trailingStop).toFixed(fixed);
}
}

if (action === "submit") {
ordersService.putOrder(order).then(function (transaction) {
var opened,
side,
message;

if (transaction.code && transaction.message) {
message = "ERROR " +
transaction.code + " " +
transaction.message;

toastService.show(message);
} else if (transaction.errorMessage) {
message = "ERROR " + transaction.errorMessage;

toastService.show(message);
} else {
opened = transaction.tradeOpened ||
transaction.orderOpened;
message = opened.side + " " +
transaction.instrument +
opened = transaction.orderFillTransaction ||
transaction.orderFillTransaction;
side = opened.units > 0 ? "buy" : "sell";
message = side + " " +
opened.instrument +
" #" + opened.id +
" @" + transaction.price +
" @" + opened.price +
" for " + opened.units;

toastService.show(message);
Expand Down
8 changes: 6 additions & 2 deletions src/client/app/components/charts.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@

if (tick && data && lastHistUpdate !== nextHistUpdate) {
data.shift();
tick.bid = parseFloat(tick.bid);
tick.ask = parseFloat(tick.ask);
midPrice = (tick.bid + tick.ask) / 2;
feedVolume = 0;
data.push({
Expand All @@ -73,6 +75,8 @@
feedVolume += 1;
}

tick.bid = parseFloat(tick.bid);
tick.ask = parseFloat(tick.ask);
midPrice = (tick.bid + tick.ask) / 2;

lastData = data && data[data.length - 1];
Expand Down Expand Up @@ -332,8 +336,8 @@
svg.append("g").attr("class", "tradearrow");
myTrades = scope.trades.map(function (trade) {
return {
date: new Date(trade.time),
type: trade.side,
date: new Date(trade.openTime),
type: trade.currentUnits > 0 ? "buy" : "sell",
price: trade.price
};
});
Expand Down
11 changes: 2 additions & 9 deletions src/client/app/exposure/exposure.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@
exps[legs[0]] = exps[legs[0]] || 0;
exps[legs[1]] = exps[legs[1]] || 0;

if (trade.side === "buy") {
exps[legs[0]] += trade.units;
exps[legs[1]] -= trade.units * trade.price;
}
if (trade.side === "sell") {
exps[legs[0]] -= trade.units;
exps[legs[1]] += trade.units * trade.price;
}

exps[legs[0]] += parseInt(trade.currentUnits, 10);
exps[legs[1]] -= trade.currentUnits * trade.price;
});

Object.keys(exps).forEach(function (exp) {
Expand Down
Loading

0 comments on commit 178db02

Please sign in to comment.