<commit_before>"use strict";

(function () {
    angular
        .module("argo")
        .factory("positionsService", positionsService);

    positionsService.$inject = ["$http", "$q", "sessionService"];
    function positionsService($http, $q, sessionService) {
        var service = {
            getPositions: getPositions
        };

        return service;

        function getPositions() {
            var deferred = $q.defer();

            sessionService.isLogged().then(function (credentials) {
                $http.post("/api/positions", {
                    environment: credentials.environment,
                    token: <PASSWORD>,
                    accountId: credentials.accountId
                }).then(function (positions) {
                    var data = [];

                    positions.data.forEach(function (position) {
                        var side,
                            longUnits,
                            shortUnits,
                            units,
                            avgPrice;

                        longUnits = position.long &&
                            parseInt(position.long.units, 10);
                        shortUnits = position.short &&
                            parseInt(position.short.units, 10);
                        units = longUnits || shortUnits;
                        side = position.longUnits > 0 ? "buy" : "sell";
                        avgPrice = (longUnits && position.long.averagePrice)
                             || (shortUnits && position.short.averagePrice);

                        data.push({
                            side: side,
                            instrument: position.instrument,
                            units: units,
                            avgPrice: avgPrice
                        });
                    });
                    deferred.resolve(data);
                });
            });

            return deferred.promise;
        }

    }

}());<commit_msg>fix(positions): use units to get the side<commit_after>"use strict";

(function () {
    angular
        .module("argo")
        .factory("positionsService", positionsService);

    positionsService.$inject = ["$http", "$q", "sessionService"];
    function positionsService($http, $q, sessionService) {
        var service = {
            getPositions: getPositions
        };

        return service;

        function getPositions() {
            var deferred = $q.defer();

            sessionService.isLogged().then(function (credentials) {
                $http.post("/api/positions", {
                    environment: credentials.environment,
                    token: <PASSWORD>,
                    accountId: credentials.accountId
                }).then(function (positions) {
                    var data = [];

                    positions.data.forEach(function (position) {
                        var side,
                            longUnits,
                            shortUnits,
                            units,
                            avgPrice;

                        longUnits = position.long &&
                            parseInt(position.long.units, 10);
                        shortUnits = position.short &&
                            parseInt(position.short.units, 10);
                        units = longUnits || shortUnits;
                        side = units > 0 ? "buy" : "sell";
                        avgPrice = (longUnits && position.long.averagePrice)
                             || (shortUnits && position.short.averagePrice);

                        data.push({
                            side: side,
                            instrument: position.instrument,
                            units: units,
                            avgPrice: avgPrice
                        });
                    });
                    deferred.resolve(data);
                });
            });

            return deferred.promise;
        }

    }

}());
{'fraction_non_alphanumeric': 0.09776886437703686, 'fraction_numerical': 0.00250689395838556, 'mean_word_length': 1.0377936670071501, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7141394', 'n_tokens_mistral': 904, 'n_tokens_neox': 837, 'n_words': 166}