Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
            }
        }