コード例 #1
0
        public bool SendOrder(OrderRequest request, out TabulateData result, out string error)
        {
            CheckDisposed();
            CheckLoggedOn();

            result = null;
            error  = string.Empty;

            string shareholderCode = GetShareholderCode(request.SecurityCode);

            StringBuilder resultInfo = new StringBuilder(MaxResultStringSize);
            StringBuilder errorInfo  = new StringBuilder(MaxErrorStringSize);

            TdxWrapper.SendOrder(
                ClientId,
                (int)request.Category,
                (int)request.PricingType,
                shareholderCode,
                request.SecurityCode,
                request.Price,
                request.Volume,
                resultInfo,
                errorInfo);

            error = errorInfo.ToString();

            bool succeeded = string.IsNullOrEmpty(error);

            if (succeeded)
            {
                result = TabulateData.Parse(resultInfo.ToString());
            }

            return(succeeded);
        }
コード例 #2
0
        public static IEnumerable <QueryStockResult> ExtractFrom(TabulateData data)
        {
            if (columnIndices == null)
            {
                columnIndices = columns.Select(c => data.GetColumnIndex(c)).ToArray();
            }

            var subData = data.GetSubColumns(columnIndices);

            foreach (var row in subData.Rows)
            {
                QueryStockResult result = new QueryStockResult();

                int index = 0;

                result.SecurityCode      = row[index++];
                result.SecurityName      = row[index++];
                result.Volume            = TradingHelper.SafeParseFloat(row[index++]);
                result.SellableVolume    = TradingHelper.SafeParseFloat(row[index++]);
                result.ReferenceCost     = TradingHelper.SafeParseFloat(row[index++]);
                result.CurrentPrice      = TradingHelper.SafeParseFloat(row[index++]);
                result.LatestMarketValue = TradingHelper.SafeParseFloat(row[index++]);
                result.ProfitPercentage  = TradingHelper.SafeParseFloat(row[index++]);

                yield return(result);
            }
        }
コード例 #3
0
        public bool QueryHistoryData(
            HistoryDataCategory category,
            DateTime startDate,
            DateTime endDate,
            out TabulateData result,
            out string error)
        {
            CheckDisposed();
            CheckLoggedOn();

            StringBuilder resultInfo = new StringBuilder(MaxResultStringSize);
            StringBuilder errorInfo  = new StringBuilder(MaxErrorStringSize);

            TdxWrapper.QueryHistoryData(
                ClientId,
                (int)category,
                startDate.ToString("yyyyMMdd"),
                endDate.ToString("yyyyMMdd"),
                resultInfo,
                errorInfo);

            error  = errorInfo.ToString();
            result = null;

            bool succeeded = string.IsNullOrEmpty(error);

            if (succeeded)
            {
                result = TabulateData.Parse(resultInfo.ToString());
            }

            return(succeeded);
        }
コード例 #4
0
        public TabulateData GetSubColumns(IEnumerable <string> columns)
        {
            if (columns == null)
            {
                throw new ArgumentNullException();
            }

            if (columns.Count() == 0)
            {
                // we can't return a sub tabulate result with no column.
                return(null);
            }

            var columnIndices = columns.Select(c => GetColumnIndex(c));

            TabulateData subResult = new TabulateData(columns);

            foreach (var row in _rows)
            {
                var subRow = columnIndices.Select(i => i < 0 ? string.Empty : row[i]);

                subResult.AddRow(subRow);
            }

            return(subResult);
        }
コード例 #5
0
        public static bool TryParse(string s, out TabulateData result)
        {
            if (string.IsNullOrEmpty(s))
            {
                throw new ArgumentNullException();
            }

            // split rows firstly.
            string[] rows = s.Split('\n');

            // row[0] is the header
            string[] columns = rows[0].Split('\t');

            result = new TabulateData(columns);

            for (int i = 1; i < rows.Length; ++i)
            {
                string[] values = rows[i].Split('\t');

                if (!result.AddRow(values))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #6
0
        public static IEnumerable <QueryShareholderRegistryResult> ExtractFrom(TabulateData data)
        {
            if (columnIndices == null)
            {
                columnIndices = columns.Select(c => data.GetColumnIndex(c)).ToArray();
            }

            var subData = data.GetSubColumns(columnIndices);

            foreach (var row in subData.Rows)
            {
                QueryShareholderRegistryResult result = new QueryShareholderRegistryResult();

                int index = 0;
                result.ShareholderCode = row[index++];
                result.Exchange        = row[index] == "0" ? Exchange.ShenzhenExchange : (row[index] == "1" ? Exchange.ShanghaiExchange : null);
                index++;

                result.CapitalAccount = row[index++];
                result.SeatCode       = row[index++];;
                result.Notes          = row[index++];

                yield return(result);
            }
        }
コード例 #7
0
        public static IEnumerable <QueryGeneralOrderResult> ExtractFrom(TabulateData data)
        {
            if (columnIndices == null)
            {
                columnIndices = columns.Select(c => data.GetColumnIndex(c)).ToArray();
            }

            var subData = data.GetSubColumns(columnIndices);

            foreach (var row in subData.Rows)
            {
                QueryGeneralOrderResult result = new QueryGeneralOrderResult();

                int index = 0;
                result.OrderNo        = int.Parse(row[index++]);
                result.SubmissionTime = row[index++];
                result.SecurityCode   = row[index++];
                result.SecurityName   = row[index++];
                result.BuySellFlag    = row[index++];
                result.StatusString   = row[index++];
                result.Status         = TradingHelper.ConvertStringToOrderStatus(result.StatusString);

                result.SubmissionPrice  = TradingHelper.SafeParseFloat(row[index++]);
                result.SubmissionVolume = TradingHelper.SafeParseInt(row[index++]);
                result.DealPrice        = TradingHelper.SafeParseFloat(row[index++]);
                result.DealVolume       = TradingHelper.SafeParseInt(row[index++]);
                result.SubmissionType   = row[index++];
                result.PricingType      = row[index++];

                yield return(result);
            }
        }
コード例 #8
0
        public static IEnumerable <QuerySucceededOrderResult> ExtractFrom(TabulateData data)
        {
            if (columnIndices == null)
            {
                columnIndices = columns.Select(c => data.GetColumnIndex(c)).ToArray();
            }

            var subData = data.GetSubColumns(columnIndices);

            foreach (var row in subData.Rows)
            {
                QuerySucceededOrderResult result = new QuerySucceededOrderResult();

                int index = 0;
                result.OrderNo      = int.Parse(row[index++]);
                result.DealNo       = int.Parse(row[index++]);
                result.DealTime     = row[index++];
                result.SecurityCode = row[index++];
                result.SecurityName = row[index++];
                result.BuySellFlag  = row[index++];
                result.DealPrice    = TradingHelper.SafeParseFloat(row[index++]);
                result.DealVolume   = TradingHelper.SafeParseFloat(row[index++]);
                result.DealAmount   = TradingHelper.SafeParseFloat(row[index++]);

                yield return(result);
            }
        }
コード例 #9
0
        public TabulateData GetSubColumns(IEnumerable <int> columnIndices)
        {
            if (columnIndices == null)
            {
                throw new ArgumentNullException();
            }

            if (columnIndices.Count() == 0)
            {
                // we can't return a sub tabulate result with no column.
                return(null);
            }

            if (columnIndices.Any(i => i < 0 || i >= _columns.Length))
            {
                throw new ArgumentException("column index is out of range");
            }

            var columns = columnIndices.Select(i => _columns[i]);

            TabulateData subResult = new TabulateData(columns);

            foreach (var row in _rows)
            {
                var subRow = columnIndices.Select(i => row[i]);

                subResult.AddRow(subRow);
            }

            return(subResult);
        }
コード例 #10
0
        public bool CancelOrder(string code, int orderNo, out TabulateData result, out string error)
        {
            CheckDisposed();
            CheckLoggedOn();

            StringBuilder resultInfo = new StringBuilder(MaxResultStringSize);
            StringBuilder errorInfo  = new StringBuilder(MaxErrorStringSize);

            Exchange exchange = Exchange.GetTradeableExchangeForSecurity(code);

            if (exchange == null)
            {
                result = null;
                error  = "Invalid code";
                return(false);
            }

            TdxWrapper.CancelOrder(ClientId, exchange.ExchangeId.ToString(), orderNo.ToString(), resultInfo, errorInfo);

            error  = errorInfo.ToString();
            result = null;

            bool succeeded = string.IsNullOrEmpty(error);

            if (succeeded)
            {
                result = TabulateData.Parse(resultInfo.ToString());
            }

            return(succeeded);
        }
コード例 #11
0
        public bool[] SendOrder(OrderRequest[] requests, out TabulateData[] results, out string[] errors)
        {
            CheckDisposed();
            CheckLoggedOn();

            if (requests == null || requests.Length == 0)
            {
                throw new ArgumentNullException();
            }

            IntPtr[] resultInfos = AllocateStringBuffers(requests.Length, MaxResultStringSize);
            IntPtr[] errorInfos  = AllocateStringBuffers(requests.Length, MaxErrorStringSize);

            try
            {
                var shareholderCodes = requests.Select(req => GetShareholderCode(req.SecurityCode)).ToArray();
                var categories       = requests.Select(req => (int)req.Category).ToArray();
                var priceTypes       = requests.Select(req => (int)req.PricingType).ToArray();
                var securityCodes    = requests.Select(req => req.SecurityCode).ToArray();
                var prices           = requests.Select(req => req.Price).ToArray();
                var quantities       = requests.Select(req => req.Volume).ToArray();

                TdxWrapper.SendOrders(
                    ClientId,
                    categories,
                    priceTypes,
                    shareholderCodes,
                    securityCodes,
                    prices,
                    quantities,
                    requests.Count(),
                    resultInfos,
                    errorInfos);

                string[] resultStrings = ConvertStringBufferToString(resultInfos);
                errors = ConvertStringBufferToString(errorInfos);

                bool[] succeeds = new bool[securityCodes.Length];
                results = new TabulateData[securityCodes.Length];

                for (int i = 0; i < results.Length; ++i)
                {
                    succeeds[i] = string.IsNullOrEmpty(errors[i]);

                    results[i] = succeeds[i] ? TabulateData.Parse(resultStrings[i]) : null;
                }

                return(succeeds);
            }
            finally
            {
                FreeStringBuffers(resultInfos);
                FreeStringBuffers(errorInfos);
            }
        }
コード例 #12
0
        public static IEnumerable <FiveLevelQuote> ExtractFrom(TabulateData data, DateTime timestamp)
        {
            if (columnIndices == null)
            {
                columnIndices = columns.Select(c => data.GetColumnIndex(c)).ToArray();
            }

            var subData = data.GetSubColumns(columnIndices);

            foreach (var row in subData.Rows)
            {
                FiveLevelQuote quote = new FiveLevelQuote(timestamp);

                int index = 0;
                quote.SecurityCode        = row[index++];
                quote.SecurityName        = row[index++];
                quote.YesterdayClosePrice = TradingHelper.SafeParseFloat(row[index++]);
                quote.TodayOpenPrice      = TradingHelper.SafeParseFloat(row[index++]);
                quote.CurrentPrice        = TradingHelper.SafeParseFloat(row[index++]);
                quote.BuyPrices           = new float[5];
                quote.BuyVolumesInHand    = new int[5];
                quote.SellPrices          = new float[5];
                quote.SellVolumesInHand   = new int[5];

                quote.BuyPrices[0] = TradingHelper.SafeParseFloat(row[index++]);
                quote.BuyPrices[1] = TradingHelper.SafeParseFloat(row[index++]);
                quote.BuyPrices[2] = TradingHelper.SafeParseFloat(row[index++]);
                quote.BuyPrices[3] = TradingHelper.SafeParseFloat(row[index++]);
                quote.BuyPrices[4] = TradingHelper.SafeParseFloat(row[index++]);

                quote.BuyVolumesInHand[0] = TradingHelper.SafeParseInt(row[index++]);
                quote.BuyVolumesInHand[1] = TradingHelper.SafeParseInt(row[index++]);
                quote.BuyVolumesInHand[2] = TradingHelper.SafeParseInt(row[index++]);
                quote.BuyVolumesInHand[3] = TradingHelper.SafeParseInt(row[index++]);
                quote.BuyVolumesInHand[4] = TradingHelper.SafeParseInt(row[index++]);

                quote.SellPrices[0] = TradingHelper.SafeParseFloat(row[index++]);
                quote.SellPrices[1] = TradingHelper.SafeParseFloat(row[index++]);
                quote.SellPrices[2] = TradingHelper.SafeParseFloat(row[index++]);
                quote.SellPrices[3] = TradingHelper.SafeParseFloat(row[index++]);
                quote.SellPrices[4] = TradingHelper.SafeParseFloat(row[index++]);

                quote.SellVolumesInHand[0] = TradingHelper.SafeParseInt(row[index++]);
                quote.SellVolumesInHand[1] = TradingHelper.SafeParseInt(row[index++]);
                quote.SellVolumesInHand[2] = TradingHelper.SafeParseInt(row[index++]);
                quote.SellVolumesInHand[3] = TradingHelper.SafeParseInt(row[index++]);
                quote.SellVolumesInHand[4] = TradingHelper.SafeParseInt(row[index++]);

                yield return(quote);
            }
        }
コード例 #13
0
        public bool[] CancelOrder(string[] codes, int[] orderNos, out TabulateData[] results, out string[] errors)
        {
            CheckDisposed();
            CheckLoggedOn();

            if (codes == null || codes.Length == 0 || orderNos == null || orderNos.Length != codes.Length)
            {
                throw new ArgumentNullException();
            }

            IntPtr[] resultInfos = AllocateStringBuffers(codes.Length, MaxResultStringSize);
            IntPtr[] errorInfos  = AllocateStringBuffers(codes.Length, MaxErrorStringSize);

            try
            {
                var exchangeIds = codes.Select(c => Exchange.GetTradeableExchangeForSecurity(c))
                                  .Select(e => e == null ? string.Empty : e.ExchangeId.ToString())
                                  .ToArray();
                var orderNoStrings = orderNos.Select(id => id.ToString()).ToArray();

                TdxWrapper.CancelOrders(
                    ClientId,
                    exchangeIds,
                    orderNoStrings,
                    codes.Length,
                    resultInfos,
                    errorInfos);

                string[] resultStrings = ConvertStringBufferToString(resultInfos);
                errors = ConvertStringBufferToString(errorInfos);

                bool[] succeeds = new bool[codes.Length];
                results = new TabulateData[codes.Length];

                for (int i = 0; i < results.Length; ++i)
                {
                    succeeds[i] = string.IsNullOrEmpty(errors[i]);

                    results[i] = succeeds[i] ? TabulateData.Parse(resultStrings[i]) : null;
                }

                return(succeeds);
            }
            finally
            {
                FreeStringBuffers(resultInfos);
                FreeStringBuffers(errorInfos);
            }
        }
コード例 #14
0
        public TabulateData GetSubRows(IEnumerable <int> rowIndices)
        {
            if (rowIndices == null)
            {
                throw new ArgumentNullException();
            }

            var validRowIndices = rowIndices.Where(i => i >= 0 && i < RowCount);

            // even if there is no valid row index, we still need to return a sub tabulate result
            // with no row.
            TabulateData subResult = new TabulateData(_columns);

            foreach (var index in validRowIndices)
            {
                subResult.AddRow(_rows[index]);
            }

            return(subResult);
        }
コード例 #15
0
        public bool[] QueryData(DataCategory[] categories, out TabulateData[] results, out string[] errors)
        {
            CheckDisposed();
            CheckLoggedOn();

            if (categories == null || categories.Length == 0)
            {
                throw new ArgumentNullException();
            }

            IntPtr[] resultInfos = AllocateStringBuffers(categories.Length, MaxResultStringSize);
            IntPtr[] errorInfos  = AllocateStringBuffers(categories.Length, MaxErrorStringSize);

            try
            {
                int[] categoryArray = categories.Select(c => (int)c).ToArray();

                TdxWrapper.QueryDatas(ClientId, categoryArray, categoryArray.Length, resultInfos, errorInfos);

                string[] resultStrings = ConvertStringBufferToString(resultInfos);
                errors = ConvertStringBufferToString(errorInfos);

                bool[] succeeds = new bool[categories.Length];
                results = new TabulateData[categories.Length];

                for (int i = 0; i < results.Length; ++i)
                {
                    succeeds[i] = string.IsNullOrEmpty(errors[i]);

                    results[i] = succeeds[i] ? TabulateData.Parse(resultStrings[i]) : null;
                }

                return(succeeds);
            }
            finally
            {
                FreeStringBuffers(resultInfos);
                FreeStringBuffers(errorInfos);
            }
        }
コード例 #16
0
        public bool GetQuote(string securityCode, out TabulateData result, out string error)
        {
            CheckDisposed();
            CheckLoggedOn();

            StringBuilder resultInfo = new StringBuilder(MaxResultStringSize);
            StringBuilder errorInfo  = new StringBuilder(MaxErrorStringSize);

            TdxWrapper.GetQuote(ClientId, securityCode, resultInfo, errorInfo);

            error  = errorInfo.ToString();
            result = null;

            bool succeeded = string.IsNullOrEmpty(error);

            if (succeeded)
            {
                result = TabulateData.Parse(resultInfo.ToString());
            }

            return(succeeded);
        }
コード例 #17
0
        public bool Payback(float amount, out TabulateData result, out string error)
        {
            CheckDisposed();
            CheckLoggedOn();

            StringBuilder resultInfo = new StringBuilder(MaxResultStringSize);
            StringBuilder errorInfo  = new StringBuilder(MaxErrorStringSize);

            TdxWrapper.Repay(ClientId, amount.ToString("0.00"), resultInfo, errorInfo);

            error  = errorInfo.ToString();
            result = null;

            bool succeeded = string.IsNullOrEmpty(error);

            if (succeeded)
            {
                result = TabulateData.Parse(resultInfo.ToString());
            }

            return(succeeded);
        }
コード例 #18
0
        public static IEnumerable <SendOrderResult> ExtractFrom(TabulateData data)
        {
            if (columnIndices == null)
            {
                columnIndices = columns.Select(c => data.GetColumnIndex(c)).ToArray();
            }

            var subData = data.GetSubColumns(columnIndices);

            foreach (var row in subData.Rows)
            {
                SendOrderResult result = new SendOrderResult();

                int index = 0;
                result.OrderNo          = int.Parse(row[index++]);
                result.ReturnedInfo     = row[index++];
                result.CheckingRiskFlag = row[index++];
                result.ReservedInfo     = row[index++];

                yield return(result);
            }
        }
コード例 #19
0
        public bool[] GetQuote(string[] securityCodes, out TabulateData[] results, out string[] errors)
        {
            CheckDisposed();
            CheckLoggedOn();

            if (securityCodes == null || securityCodes.Length == 0)
            {
                throw new ArgumentNullException();
            }

            IntPtr[] resultInfos = AllocateStringBuffers(securityCodes.Length, MaxResultStringSize);
            IntPtr[] errorInfos  = AllocateStringBuffers(securityCodes.Length, MaxErrorStringSize);

            try
            {
                TdxWrapper.GetQuotes(ClientId, securityCodes, securityCodes.Length, resultInfos, errorInfos);

                string[] resultStrings = ConvertStringBufferToString(resultInfos);
                errors = ConvertStringBufferToString(errorInfos);

                bool[] succeeds = new bool[securityCodes.Length];
                results = new TabulateData[securityCodes.Length];

                for (int i = 0; i < results.Length; ++i)
                {
                    succeeds[i] = string.IsNullOrEmpty(errors[i]);

                    results[i] = succeeds[i] ? TabulateData.Parse(resultStrings[i]) : null;
                }

                return(succeeds);
            }
            finally
            {
                FreeStringBuffers(resultInfos);
                FreeStringBuffers(errorInfos);
            }
        }
コード例 #20
0
        public static IEnumerable <QueryCapitalResult> ExtractFrom(TabulateData data)
        {
            if (columnIndices == null)
            {
                columnIndices = columns.Select(c => data.GetColumnIndex(c)).ToArray();
            }

            var subData = data.GetSubColumns(columnIndices);

            foreach (var row in subData.Rows)
            {
                QueryCapitalResult result = new QueryCapitalResult();

                int index = 0;
                result.RemainingCapital  = TradingHelper.SafeParseFloat(row[index++]);
                result.UsableCapital     = TradingHelper.SafeParseFloat(row[index++]);
                result.FrozenCapital     = TradingHelper.SafeParseFloat(row[index++]);
                result.CashableCapital   = TradingHelper.SafeParseFloat(row[index++]);
                result.TotalEquity       = TradingHelper.SafeParseFloat(row[index++]);
                result.LatestMarketValue = TradingHelper.SafeParseFloat(row[index++]);

                yield return(result);
            }
        }
コード例 #21
0
 public static IEnumerable <FiveLevelQuote> ExtractFrom(TabulateData data)
 {
     return(ExtractFrom(data, DateTime.Now));
 }