コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
0
        private void OnOrderStatusChanged(DispatchedOrder dispatchedOrder)
        {
            if (dispatchedOrder == null)
            {
                return;
            }

            if (dispatchedOrder.Request.AssociatedObject != null)
            {
                StoplossOrder order = dispatchedOrder.Request.AssociatedObject as StoplossOrder;

                if (order == null)
                {
                    return;
                }

                if (TradingHelper.IsFinalStatus(dispatchedOrder.LastStatus))
                {
                    lock (_orderLockObj)
                    {
                        if (!IsSentOrder(order))
                        {
                            return;
                        }

                        ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                        if (logger != null)
                        {
                            logger.InfoFormat(
                                "Stoploss order executed:  id {0} code {1} status {2} suceeded volume {3}.",
                                order.OrderId,
                                order.SecurityCode,
                                dispatchedOrder.LastStatus,
                                dispatchedOrder.SucceededVolume);
                        }

                        order.UpdateExistingVolume(dispatchedOrder.SucceededVolume);

                        RemoveSentOrder(order);

                        if (order.ExistingVolume > 0)
                        {
                            // the order has not been finished yet, put it back into active order
                            AddActiveStoplossOrder(order);

                            if (TradingHelper.IsSucceededFinalStatus(dispatchedOrder.LastStatus))
                            {
                                // send out order again
                                SendStoplossOrder(order);
                            }
                        }
                    }
                }
            }
        }
コード例 #5
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);
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
0
        private void QueryOrderStatus(object state)
        {
            if (!Monitor.TryEnter(_dispatcherLockObj))
            {
                // ignore this refresh because previous refreshing is still on going.
                return;
            }

            if (_isStopped)
            {
                return;
            }

            if (_client == null || !_client.IsLoggedOn())
            {
                return;
            }

            try
            {
                bool hasActiveOrder = false;
                lock (_orderLockObj)
                {
                    hasActiveOrder = _allActiveOrders.Count > 0;
                }

                if (!hasActiveOrder)
                {
                    return;
                }

                string error;
                var    submittedOrders = _client.QuerySubmittedOrderToday(out error).ToList();

                if (submittedOrders.Count() == 0)
                {
                    if (!string.IsNullOrEmpty(error))
                    {
                        ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                        if (logger != null)
                        {
                            logger.WarnFormat("Failed to query cancellable order. error: {0}", error);
                        }
                    }
                }
                else
                {
                    foreach (var order in submittedOrders)
                    {
                        DispatchedOrder dispatchedOrder;

                        lock (_orderLockObj)
                        {
                            if (!_allActiveOrders.TryGetValue(order.OrderNo, out dispatchedOrder))
                            {
                                // not submitted by the dispatcher or the order is finished, ignore it.
                                continue;
                            }
                        }

                        // check if order status has been changed and notify client if necessary
                        CheckOrderStatusChangeAndNotify(ref dispatchedOrder, order);

                        // remove order in finished status
                        if (TradingHelper.IsFinalStatus(order.Status))
                        {
                            lock (_orderLockObj)
                            {
                                _allActiveOrders.Remove(dispatchedOrder.OrderNo);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                if (logger != null)
                {
                    logger.ErrorFormat("Exception in querying order status: {0}", ex);
                }
            }
            finally
            {
                Monitor.Exit(_dispatcherLockObj);
            }
        }