﻿AG.Data.StockExchange = {
    //    GetPutThroughByDate: function (floor, date, tradingType) {
    //        var obj = AG.ClientAPI;
    //        return obj.createData(PutThroughDaily, 'StockExchangePutThroughByDate', [{ StockExchange: floor, TradingDate: date, Type: tradingType}], { static: ['Id', 'StockExchange', 'Name', 'Price', 'Volume'] });
    //    },
    GetPutThroughByDate: function (floor, startDate, endDate, tradingType) {
        var requestName = 'StockExchangePutThroughByDate' + '_' + floor + '_' + startDate + '_' + endDate + '_' + tradingType;
        return AG.ClientAPI.createData(PutThroughDaily, requestName, [{ StockExchange: floor, Type: tradingType, StartDate: startDate, EndDate: endDate}], { static: ['Id', 'Code', 'Name', 'Price', 'Volume'] });
    },
    GetValueByDate: function (floor, date) {
        var obj = AG.ClientAPI;
        var requestName = 'ValueByDate' + '_' + floor + '_' + date;
        return obj.createData(StockExchangeDaily, requestName, [{ Code: floor }, { SessionDate: date}], { static: ['Id', 'Code', 'Name', 'ClosePrice', 'Diff', 'DiffPercent', 'TotalShare', 'TotalValue', 'TotalTrade'] });
    },
    //Lay ra index the gioi
    GetListWorldIndex: function (region) {
        //        Americas,europe-africa-middle-east,Asia-Pacific
        var requestName = 'GetListWorldIndex_NoLanguage';
        var data = [];
        if (typeof (region) != 'undefined') {
            for (var i = 0; i < region.length; i++) {
                requestName += '_' + region[i];
                data.push({ Code: region[i] });
            }
            var objRegion = AG.ClientAPI.createData(Region, requestName, data, { static: ['Id', 'Code', 'Name'] });
            data = [];
            for (var i = 0; i < objRegion.length; i++) {
                data.push({ ParentId: objRegion[i].Id });
            }
        }
        data.push({ Code: '<![CDATA[NASDAQ COMPOSITE INDEX]]>' });
        data.push({ Code: '<![CDATA[IBEX 35 INDEX]]>' });
        data.push({ Code: '<![CDATA[DAX INDEX]]>' });
        data.push({ Code: '<![CDATA[NZX 15 GROSS INDEX]]>' });
        data.push({ Code: '<![CDATA[STRAITS TIMES INDEX]]>' });
        data.push({ Code: '<![CDATA[FTSE 100 INDEX]]>' });
        data.push({ Code: '<![CDATA[CAC 40 INDEX]]>' });
        data.push({ Code: '<![CDATA[S&P 500 INDEX]]>' });
        data.push({ Code: '<![CDATA[AEX-Index]]>' });
        data.push({ Code: '<![CDATA[S&P/TSX COMPOSITE INDEX]]>' });
        data.push({ Code: '<![CDATA[SSE COMPONENT STOCK IX]]>' });
        data.push({ Code: '<![CDATA[S&P/ASX 200 INDEX]]>' });
        data.push({ Code: '<![CDATA[DOW JONES INDUS. AVG]]>' });
        data.push({ Code: '<![CDATA[NIKKEI 225]]>' });
        data.push({ Code: '<![CDATA[SWISS MARKET INDEX]]>' });
        data.push({ Code: '<![CDATA[HANG SENG INDEX]]>' });
        data.push({ Status: '00000000-0000-0000-0000-000000000002' });
        return AG.ClientAPI.createData(WorldIndex, requestName, data, { static: ['Id', 'Code', 'Value', 'ChangeValue', 'ChangePercent', 'PublishDate'] });
    },
    GetIndexValue: function () {
        var order = [{ Field: 'Id', Direction: 'ASC'}];
        var obj = AG.ClientAPI;
        return obj.createData(StockExchangeRealtime, 'StockExchangeIndexValue' + '_NoLanguage', [{ Code: 'HSX' }, { Code: 'HNX' }, { Code: 'UPCOM'}], { static: ['Id', 'Name', 'Code', 'ClosePrice', 'Diff', 'DiffPercent', 'Modified'] }, order, undefined, undefined, undefined, 0, 60000);
    },
    //    GetStatisticIndex: function (floor, startDate, endDate, startIndex, endIndex, orderBy, orderType) {
    //        var obj = AG.ClientAPI;
    //        var order = [];
    //        if (typeof (orderBy) != "undefined")
    //            order = [{ Field: orderBy, Direction: 'ASC'}];
    //        else
    //            order = [{ Field: 'ID', Direction: 'ASC'}];
    //        if (typeof (orderType) != "undefined")
    //            order[0].Direction = orderType;
    //        if (orderBy != 'Code')
    //            order.push({ Field: 'Code', Direction: 'ASC' });
    //        var requestName = 'StatisticsIndex' + '_' + floor + '_' + startDate + '_' + endDate + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType;
    //        return obj.createData(StockExchangeDaily, requestName, [{ Code: floor }, { StartDate: startDate }, { EndDate: endDate }, { StartIndex: startIndex }, { EndIndex: endIndex}], { static: ['Id', 'SessionDate', 'ClosePrice', 'Diff', 'DiffPercent', 'TotalStockGainCount', 'TotalStockLossCount', 'TotalStockEqualCount', 'TotalShare', 'TotalValue'] }, order);

    //    },
    //    GetCountStatisticIndex: function (floor, startDate, endDate) {
    //        var obj = StockExchangeDaily;
    //        return obj.getCount([{ Code: floor }, { StartDate: startDate }, { EndDate: endDate}]);
    //    },
    //    GetStatisticIndexToExcel: function (floor, startDate, endDate, orderBy, orderType) {
    //        var obj = StockExchangeDaily;
    //        var order = [];
    //        if (typeof (orderBy) != "undefined")
    //            order = [{ Field: orderBy, Direction: 'ASC'}];
    //        else
    //            order = [{ Field: 'ID', Direction: 'ASC'}];
    //        if (typeof (orderType) != "undefined")
    //            order[0].Direction = orderType;
    //        if (orderBy != 'Code')
    //            order.push({ Field: 'Code', Direction: 'ASC' });
    //        obj.toExcel('IndexStatistic', [{ Code: floor }, { StartDate: startDate }, { EndDate: endDate}], { static: ['Id', 'SessionDate', 'ClosePrice', 'Diff', 'DiffPercent', 'TotalStockGainCount', 'TotalStockLossCount', 'TotalShare', 'TotalValue'] }, order);
    //    },
    GetOverview: function (floor) {
        var obj = AG.ClientAPI;
        var requestName = 'StockExchangeOverview' + '_NoLanguage' + '_' + floor;
        return obj.createData(StockExchangeRealtime, requestName, [{ Code: floor}], { static: ['Id', 'Name', 'Code', 'ClosePrice', 'Diff', 'DiffPercent', 'OpenPrice', 'HighestPrice', 'LowestPrice', 'MarketCapitalization', 'Highest52Weeks', 'Lowest52Weeks', 'BidOrder', 'OfferOrder', 'BidVolume', 'OfferVolume', 'Modified'], dynamic: ['TotalShare', 'TotalValue', 'TotalTrade'] }, undefined, undefined, undefined, 0, 60000);

    },
    GetStatisticByStockDiff: function (floor) {
        var requestName = 'StatisticByStockDiff' + '_NoLanguage' + '_' + floor;
        return AG.ClientAPI.createData(StockExchangeRealtime, requestName, [{ Code: floor}], { static: ['Id', 'Name', 'Code', 'TotalStockGainCount', 'TotalStockGainVolume', 'TotalStockGainValue', 'TotalStockLossCount', 'TotalStockLossVolume', 'TotalStockLossValue', 'TotalStockEqualValue', 'TotalStockEqualShare', 'TotalStockEqualCount'], dynamic: ['Diff', 'Modified'] }, undefined, undefined, undefined, 0, 60000);

    },
    //    GetOrderDaily: function (floorId, startDate, endDate, startIndex, endIndex, orderBy, orderType) {
    //        var obj = AG.ClientAPI;
    //        var order = [];
    //        if (typeof (orderBy) != "undefined")
    //            order = [{ Field: orderBy, Direction: 'ASC'}];
    //        else
    //            order = [{ Field: 'ID', Direction: 'ASC'}];
    //        if (typeof (orderType) != "undefined") {
    //            order[0].Direction = orderType;
    //        }
    //        if (orderBy != 'Code')
    //            order.push({ Field: 'Code', Direction: 'ASC' });
    //        var requestName = 'OrderDaily' + '_' + floorId + '_' + startDate + '_' + endDate + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType;
    //        return obj.createData(CompanyDaily, requestName, [{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate }, { StartIndex: startIndex }, { EndIndex: endIndex}], { static: ['Id', 'Code', 'SessionDate', 'OpenPrice', 'ClosePrice', 'Diff', 'DiffPercent', 'BidCountOrder', 'BidVolumeOrder', 'OfferCountOrder', 'BidVolumeOrderSurplus', 'TotalShare', 'TotalValue'] }, order);

    //    },
    //    GetCountOrderDaily: function (floorId, startDate, endDate) {
    //        var obj = CompanyDaily;
    //        return obj.getCount([{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate}]);
    //    },
    //    GetOrderDailyToExcel: function (floorId, startDate, endDate, orderBy, orderType) {
    //        var obj = CompanyDaily;
    //        var order = [];
    //        if (typeof (orderBy) != "undefined")
    //            order = [{ Field: orderBy, Direction: 'ASC'}];
    //        else
    //            order = [{ Field: 'ID', Direction: 'ASC'}];
    //        if (typeof (orderType) != "undefined")
    //            order[0].Direction = orderType;
    //        if (orderBy != 'Code')
    //            order.push({ Field: 'Code', Direction: 'ASC' });
    //        obj.toExcel('OrderStatistics',[{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate}], { static: ['Id', 'Code', 'SessionDate', 'OpenPrice', 'ClosePrice', 'Diff', 'DiffPercent', 'BidCountOrder', 'BidVolumeOrder', 'OfferCountOrder', 'BidVolumeOrderSurplus', 'TotalShare', 'TotalValue'] }, order);
    //    },
    //    GetForeignTradeDaily: function (floorId, stockCode, startDate, endDate, startIndex, endIndex, orderBy, orderType) {
    //        var obj = AG.ClientAPI;
    //        var order = [];
    //        if (typeof (orderBy) != "undefined")
    //            order = [{ Field: orderBy, Direction: 'ASC'}];
    //        else
    //            order = [{ Field: 'ID', Direction: 'ASC'}];
    //        if (typeof (orderType) != "undefined") {
    //            order[0].Direction = orderType;
    //        }
    //        if (orderBy != 'Code')
    //            order.push({ Field: 'Code', Direction: 'ASC' });
    //        var data;
    //        if (stockCode != '')
    //            data = [{ StockExchange: floorId }, { Code: stockCode }, { StartDate: startDate }, { EndDate: endDate }, { StartIndex: startIndex }, { EndIndex: endIndex}];
    //        else
    //            data = [{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate }, { StartIndex: startIndex }, { EndIndex: endIndex}];
    //        var requestName = 'ForeignTradeDaily' + '_' + floorId + '_' + startDate + '_' + endDate + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType;
    //        return obj.createData(CompanyDaily, requestName, data, { static: ['Id', 'Code', 'SessionDate', 'ForeignOwnedVolume', 'ForeignOwnedRatio', 'ForeignCurrentRoom', 'ForeignBuyVolume', 'ForeignBuyVolumeRatio', 'ForeignSellVolume', 'ForeignSellVolumeRatio', 'ForeignBuyValue', 'ForeignBuyValueRatio', 'ForeignSellValue', 'ForeignSellValueRatio'] }, order);

    //    },
    //    GetCountForeignTradeDaily: function (floorId, stockCode, startDate, endDate) {
    //        var obj = CompanyDaily;
    //        var data;
    //        if (stockCode != '')
    //            data = [{ StockExchange: floorId }, { Code: stockCode }, { StartDate: startDate }, { EndDate: endDate}];
    //        else
    //            data = [{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate}];
    //        return obj.getCount(data);
    //    },
    //    GetForeignTradeDailyToExcel: function (floorId, startDate, endDate, orderBy, orderType) {
    //        var obj = CompanyDaily;
    //        var order = [];
    //        if (typeof (orderBy) != "undefined")
    //            order = [{ Field: orderBy, Direction: 'ASC'}];
    //        else
    //            order = [{ Field: 'ID', Direction: 'ASC'}];
    //        if (typeof (orderType) != "undefined")
    //            order[0].Direction = orderType;

    //        if (orderBy != 'Code')
    //            order.push({ Field: 'Code', Direction: 'ASC' });
    //        var data;
    //        if (typeof (stockCode) != 'undefined')
    //            data = [{ StockExchange: floorId }, { Code: stockCode }, { StartDate: startDate }, { EndDate: endDate}];
    //        else
    //            data = [{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate}];
    //        obj.toExcel( 'ForeignTrade',data, { static: ['Id', 'Code', 'SessionDate', 'ForeignOwnedVolume', 'ForeignOwnedRatio', 'ForeignCurrentRoom', 'ForeignBuyVolume', 'ForeignBuyVolumeRatio', 'ForeignSellVolume', 'ForeignSellVolumeRatio', 'ForeignBuyValue', 'ForeignBuyValueRatio', 'ForeignSellValue', 'ForeignSellValueRatio'] }, order);
    //    },
    //    GetStockCodeByExchange: function (floorId) {
    //        var obj = AG.ClientAPI;
    //        return obj.createData(objCompanyDaily, 'StockExchangeStockCodeByExchange', [{ StockExchange: floorId}], { static: ['Id', 'Code'] }, [{ Field: 'Code'}]);

    //    },
    //    GetGeneralInfo: function (floor, startIndex, endIndex, orderBy, orderType) {
    //        var obj = AG.ClientAPI;
    //        var order = [];
    //        if (typeof (orderBy) != "undefined")
    //            order = [{ Field: orderBy, Direction: 'ASC'}];
    //        else
    //            order = [{ Field: 'ID', Direction: 'ASC'}];
    //        if (typeof (orderType) != "undefined") {
    //            order[0].Direction = orderType;
    //        }
    //        if (orderBy != 'Code')
    //            order.push({ Field: 'Code', Direction: 'ASC' });
    //        var requestName = 'StockExchangeGeneralInfo' + '_' + floor + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType;
    //        return obj.createData(StockExchangeDaily, requestName, [{ Code: floor }, { StartIndex: startIndex }, { EndIndex: endIndex}], { static: ['Id', 'SessionDate', 'StockShare', 'PutThroughShare', 'FundShare', 'FundPutThroughShare', 'BondShare', 'TotalShare', 'ForeignBuyVolume', 'ForeignPutThroughBuyVolume', 'ForeignSellVolume', 'ForeignPutThroughSellVolume', 'ForeignBuyVolumeSurplus', 'TotalStockGainCount', 'CeilingStockGainCount', 'TotalStockLossCount', 'FloorStockLossCount', 'StockGainCountSurplus', 'BidOrder', 'OfferOrder', 'BidOrderSurplus', 'BidVolume', 'OfferVolume', 'BidVolumeSurplus'] }, order);

    //    },
    //    GetPriceQuery: function (floorId, startDate, endDate, startIndex, endIndex, orderBy, orderType) {
    //        var obj = AG.ClientAPI;
    //        var order = [];
    //        if (typeof (orderBy) != "undefined")
    //            order = [{ Field: orderBy, Direction: 'ASC'}];
    //        else
    //            order = [{ Field: 'ID', Direction: 'ASC'}];
    //        if (typeof (orderType) != "undefined") {
    //            order[0].Direction = orderType;
    //        }
    //        if (orderBy != 'Code')
    //            order.push({ Field: 'Code', Direction: 'ASC' });
    //        var requestName = 'PriceQuery' + '_' + floorId + '_' + startDate + '_' + endDate + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType;
    //        return obj.createData(CompanyDaily, requestName, [{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate }, { StartIndex: startIndex }, { EndIndex: endIndex}], { static: ['Id', 'Code', 'SessionDate', 'OpenPrice', 'ClosePrice', 'Diff', 'DiffPercent', 'RefPrice', 'CeilingPrice', 'FloorPrice', 'AveragePrice', 'TotalShare'] }, order);

    //    },
    //    GetCountPriceQuery: function (floorId, startDate, endDate) {
    //        var obj = CompanyDaily;
    //        return obj.getCount([{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate}]);
    //    },
    //    GetPriceQueryToExcel: function (floorId, startDate, endDate, orderBy, orderType) {
    //        var obj = CompanyDaily;
    //        var order = [];
    //        if (typeof (orderBy) != "undefined")
    //            order = [{ Field: orderBy, Direction: 'ASC'}];
    //        else
    //            order = [{ Field: 'ID', Direction: 'ASC'}];
    //        if (typeof (orderType) != "undefined")
    //            order[0].Direction = orderType;
    //        if (orderBy != 'Code')
    //            order.push({ Field: 'Code', Direction: 'ASC' });
    //        obj.toExcel('PriceQuery',[{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate}], { static: ['Id', 'Code', 'SessionDate', 'ForeignOwnedVolume', 'ForeignOwnedRatio', 'ForeignCurrentRoom', 'ForeignBuyVolume', 'ForeignBuyVolumeRatio', 'ForeignSellVolume', 'ForeignSellVolumeRatio', 'ForeignBuyValue', 'ForeignBuyValueRatio', 'ForeignSellValue', 'ForeignSellValueRatio'] }, order);
    //    },
    GetGeneralInfo: function (floor, startIndex, endIndex, orderBy, orderType) {

        var order = [];
        if (typeof (orderBy) != "undefined" && orderBy != '')
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined" && orderType != '') {
            order[0].Direction = orderType;
        }
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var requestName = 'StockExchangeGeneralInfo' + '_' + floor + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType + '_NoLanguage';
        return AG.ClientAPI.createData(StockExchangeDaily, requestName, [{ Code: floor }, { StartIndex: startIndex }, { EndIndex: endIndex}], { static: ['Id', 'SessionDate', 'FundShare', 'FundPutThroughShare', 'BondShare', 'TotalShare', 'ForeignBuyVolume', 'ForeignPutThroughBuyVolume', 'ForeignSellVolume', 'ForeignPutThroughSellVolume', 'ForeignBuyVolumeSurplus', 'TotalStockGainCount', 'CeilingStockGainCount', 'TotalStockLossCount', 'FloorStockLossCount', 'StockGainCountSurplus', 'BidOrder', 'OfferOrder', 'BidOrderSurplus', 'BidVolume', 'OfferVolume', 'BidVolumeSurplus'], dynamic: ['MatchTotalShare', 'PutThroughTotalShare'] }, order);

    },
    GetLastSessionDate: function (floorId) {

        var order = [{ Field: 'SessionDate', Direction: 'DESC'}];
        var result = AG.ClientAPI.createData(CompanyDaily, 'StockExchangeLastSessionDate', [{ StockExchange: floorId }, { StartIndex: 1 }, { EndIndex: 1}], { static: ['Id', 'SessionDate'] }, order);
        if (result.length > 0)
            return result[0].SessionDate;
        else
            return '2000-01-01T00:00:00+07:00';

    },
    GetPriceQueryVNSC: function (floorId, stockCode, startDate, endDate, startIndex, endIndex, orderBy, orderType) {
        var obj = AG.ClientAPI;
        var order = [];
        if (typeof (orderBy) != "undefined")
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined") {
            order[0].Direction = orderType;
        }
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var data;
        if (stockCode != '')
            data = [{ StockExchange: floorId }, { Code: stockCode }, { StartIndex: startIndex }, { EndIndex: endIndex}];
        else
            data = [{ StockExchange: floorId }, { StartIndex: startIndex }, { EndIndex: endIndex}];
        if (startDate != '')
            data.push({ StartDate: startDate });
        if (endDate != '')
            data.push({ EndDate: endDate });
        var requestName = 'PriceQuery' + 'NoLanguage' + '_' + floorId + '_' + stockCode + '_' + startDate + '_' + endDate + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType;
        return obj.createData(CompanyDaily, requestName, data, { static: ['Id', 'Code', 'SessionDate', 'RefPrice', 'OpenPrice', 'ClosePrice', 'AveragePrice', 'Diff', 'DiffPercent', 'TotalShare', 'TotalValue', 'BidCountOrder', 'OfferCountOrder', 'BidVolumeOrder', 'ListedShare'], dynamic: ['HighestPrice', 'LowestPrice', 'CourseValue1', 'CourseVolume1', 'CoursePrice2', 'CourseVolume2', 'CourseValue3', 'CourseVolume3', 'OfferVolumeOrder'] }, order);
    },
    GetCountPriceQueryVNSC: function (floorId, stockCode, startDate, endDate) {
        var obj = CompanyDaily;
        var data;
        if (stockCode != '')
            data = [{ StockExchange: floorId }, { Code: stockCode }, { StartDate: startDate }, { EndDate: endDate}];
        else
            data = [{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate}];
        return obj.getCount(data);
        //        if (startDate != '')
        //            data.push({ StartDate: startDate });
        //        if (endDate != '')
        //            data.push({ EndDate: endDate });
    },

    GetPriceQueryToExcelVNSC: function (floorId, stockCode, startDate, endDate, orderBy, orderType) {
        var obj = CompanyDaily;
        var order = [];
        if (typeof (orderBy) != "undefined")
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined")
            order[0].Direction = orderType;
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var data;
        if (stockCode != '')
            data = [{ StockExchange: floorId }, { Code: stockCode }, { StartDate: startDate }, { EndDate: endDate}];
        else
            data = [{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate}];
        obj.toExcel('PriceQuery', data, { static: ['SessionDate', 'Code', 'SessionDate', 'RefPrice', 'OpenPrice', 'ClosePrice', 'AveragePrice', 'Diff', 'DiffPercent', 'TotalShare', 'TotalValue', 'BidCountOrder', 'OfferCountOrder', 'BidVolumeOrder', 'ListedShare'], dynamic: ['HighestPrice', 'LowestPrice', 'CourseValue1', 'CourseVolume1', 'CourseValue2', 'CourseVolume2', 'CourseValue3', 'CourseVolume3', 'OfferVolumeOrder'] }, order);
    },
    GetStatisticIndexVNSC: function (floorId, stockCode, startDate, endDate, startIndex, endIndex, orderBy, orderType) {
        var obj = AG.ClientAPI;
        var order = [];
        if (typeof (orderBy) != "undefined")
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined") {
            order[0].Direction = orderType;
        }
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var data;
        if (stockCode != '')
            data = [{ StockExchange: floorId }, { Code: stockCode }, { StartDate: startDate }, { EndDate: endDate }, { StartIndex: startIndex }, { EndIndex: endIndex}];
        else
            data = [{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate }, { StartIndex: startIndex }, { EndIndex: endIndex}];
        var requestName = 'StatisticIndex' + '_' + floorId + '_' + stockCode + '_' + startDate + '_' + endDate + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType;
        return obj.createData(CompanyDaily, requestName, data, { static: ['Id', 'SessionDate', 'Code', 'OpenPrice', 'ClosePrice', 'Diff', 'DiffPercent', 'BidCountOrder', 'BidVolumeOrder', 'OfferCountOrder', 'TotalShare', 'TotalValue'], dynamic: ['BidCountOrderSurplus'] }, order);
    },
    GetCountStatisticIndexVNSC: function (floorId, stockCode, startDate, endDate) {
        var obj = CompanyDaily;
        var data;
        if (stockCode != '')
            data = [{ StockExchange: floorId }, { Code: stockCode }, { StartDate: startDate }, { EndDate: endDate}];
        else
            data = [{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate}];
        return obj.getCount(data);
    },
    GetStatisticIndexToExcelVNSC: function (floorId, stockCode, startDate, endDate, orderBy, orderType) {
        var obj = CompanyDaily;
        var order = [];
        if (typeof (orderBy) != "undefined")
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined")
            order[0].Direction = orderType;
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var data;
        if (stockCode != '')
            data = [{ StockExchange: floorId }, { Code: stockCode }, { StartDate: startDate }, { EndDate: endDate}];
        else
            data = [{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate}];
        obj.toExcel('PriceQuery', data, { static: ['SessionDate', 'Code', 'OpenPrice', 'ClosePrice', 'Diff', 'DiffPercent', 'BidCountOrder', 'BidVolumeOrder', 'OfferCountOrder', 'TotalShare', 'TotalValue'], dynamic: ['BidCountOrderSurplus'] }, order);
    },
    GetForeignTradeDailyVNSC: function (floorId, stockCode, startDate, endDate, startIndex, endIndex, orderBy, orderType) {
        var obj = AG.ClientAPI;
        var order = [];
        if (typeof (orderBy) != "undefined")
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined") {
            order[0].Direction = orderType;
        }
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        if (orderBy != 'Type')
            order.push({ Field: 'Type', Direction: 'ASC' });
        var data;
        if (stockCode != '')
            data = [{ StockExchange: floorId }, { Code: stockCode }, { Type: '00000000-0000-0000-0000-000000000002' }, { Type: '00000000-0000-0000-0000-000000000005' }, { StartDate: startDate }, { EndDate: endDate }, { StartIndex: startIndex }, { EndIndex: endIndex}];
        else
            data = [{ StockExchange: floorId }, { Type: '00000000-0000-0000-0000-000000000002' }, { Type: '00000000-0000-0000-0000-000000000005' }, { StartDate: startDate }, { EndDate: endDate }, { StartIndex: startIndex }, { EndIndex: endIndex}];
        var requestName = 'ForeignTradeDaily' + '_' + floorId + '_' + stockCode + '_' + startDate + '_' + endDate + '_' + startIndex + '_' + endIndex + '_' + orderBy + '_' + orderType;
        return obj.createData(CompanyDaily, requestName, data, { static: ['Id', 'SessionDate', 'Code', 'Type', 'ForeignCurrentRoom', 'ForeignOwnedVolume'], dynamic: ['ForeignMatchingBuyVolume', 'ForeignMatchingSellVolume', 'ForeignMatchingBuyValue', 'ForeignMatchingSellValue', 'ForeignPutThroughBuyVolume', 'ForeignPutThroughSellVolume', 'ForeignPutThroughBuyValue', 'ForeignPutThroughSellValue'] }, order);

    },
    GetCountForeignTradeDailyVNSC: function (floorId, stockCode, startDate, endDate, type) {
        var obj = CompanyDaily;
        var data;
        if (stockCode != '')
            data = [{ StockExchange: floorId }, { Code: stockCode }, { Type: '00000000-0000-0000-0000-000000000002' }, { Type: '00000000-0000-0000-0000-000000000005' }, { StartDate: startDate }, { EndDate: endDate}];
        else
            data = [{ StockExchange: floorId }, { Type: '00000000-0000-0000-0000-000000000002' }, { Type: '00000000-0000-0000-0000-000000000005' }, { StartDate: startDate }, { EndDate: endDate}];
        return obj.getCount(data);
    },
    GetForeignTradeDailyToExcelVNSC: function (floorId, stockCode, startDate, endDate, orderBy, orderType) {
        var obj = CompanyDaily;
        var order = [];
        if (typeof (orderBy) != "undefined")
            order = [{ Field: orderBy, Direction: 'ASC'}];
        else
            order = [{ Field: 'ID', Direction: 'ASC'}];
        if (typeof (orderType) != "undefined")
            order[0].Direction = orderType;
        if (orderBy != 'Code')
            order.push({ Field: 'Code', Direction: 'ASC' });
        var data;
        if (stockCode != '')
            data = [{ StockExchange: floorId }, { Code: stockCode }, { StartDate: startDate }, { EndDate: endDate}];
        else
            data = [{ StockExchange: floorId }, { StartDate: startDate }, { EndDate: endDate}];
        obj.toExcel('ForeignTrade', data, { static: ['Id', 'Code', 'ForeignCurrentRoom', 'ForeignOwnedVolume'], dynamic: ['ForeignMatchingBuyVolume', 'ForeignMatchingSellVolume', 'ForeignMatchingBuyValue', 'ForeignMatchingSellValue', 'ForeignPutThroughBuyVolume', 'ForeignPutThroughSellVolume', 'ForeignPutThroughBuyValue', 'ForeignPutThroughSellValue'] }, order);
    },
    GetListStockExchange: function () {
        var obj = AG.ClientAPI;
        return obj.createData(StockExchangeRealtime, 'List', [{ Region: '10000000-0000-0000-0000-000000000000'}], { static: ['Id', 'Code', 'Name'] });
    },
    GetSliceStock: function (floorId, startIndex, endIndex) {
        var obj = AG.ClientAPI;
        var order = [];
        order.push({ Field: 'Code', Direction: 'ASC' });
        var requestName = 'SliceStock' + '_' + floorId + '_' + startIndex + '_' + endIndex;
        return obj.createData(CompanyRealtime, requestName, [{ StockExchange: floorId }, { StartIndex: startIndex }, { EndIndex: endIndex}], { static: ['Id', 'Code', 'ClosePrice', 'Diff', 'DiffPercent', 'RefPrice'], dynamic: ['CeilingPrice', 'FloorPrice'] }, order);
    },
    GetCountSliceStock: function (floorId) {
        var obj = CompanyRealtime;
        return obj.getCount([{ StockExchange: floorId}]);
    },
    GetExchangeRate: function () {
        var obj = AG.ClientAPI;
        return obj.createData(ExchangeRate, 'GetExchangeRate', [{ Code: 'USD' }, { Code: 'EUR' }, { Code: 'CAD' }, { Status: '00000000-0000-0000-0000-000000000002'}], { static: ['Id', 'Code', 'Buy', 'Sell'] });
    },
    GetCommodites: function () {
        var obj = AG.ClientAPI;
        return obj.createData(ExchangeRate, 'GetCommodites', [{ Code: 'SJC' }, { Status: '00000000-0000-0000-0000-000000000002'}], { static: ['Id', 'Code', 'Name', 'Buy', 'Sell'] });
    },
    //lay ra tinh thanh khoan
    GetRiskMarket: function (stockExchangeId) {
        return AG.ClientAPI.createData(StockExchangeRealtime, 'GetRiskMarket' + stockExchangeId, [{ Id: stockExchangeId}], { static: ['Id', 'Code'], dynamic: [ /*lai lo binh quan ngay*/'DailyAverageGainLoss', 'WeeklyAverageGainLoss', /*Beta*/'Beta', /*Var95% tuan*/'DailyVaR95', 'ClosePrice', /*Var95% tuan*/'WeeklyVaR95', /*Do lech chuan*/'YearStandardDeviation'] });
    }
}
