Exemple #1
0
        public override Task <ExecutionReport> AddOrderAndWaitExecution(TradingSignal signal, TranslatedSignalTableEntity translatedSignal, TimeSpan timeout)
        {
            translatedSignal.RequestSentMessage("stub exchange don't send actual request");
//
//	        SimulateWork();
//	        SimulateException();
//
            translatedSignal.ResponseReceived("stub exchange don't recevie actual response");
            lock (syncRoot)
            {
                var s = new TradingSignal(signal.Instrument, Guid.NewGuid().ToString(), signal.Command, signal.TradeType, signal.Price, signal.Volume, signal.Time, signal.OrderType, signal.TimeInForce);
                ActualSignals[signal.Instrument.Name].AddLast(s);
                translatedSignal.ExternalId = s.OrderId;

                return(Task.FromResult(new ExecutionReport(s.Instrument, DateTime.UtcNow, s.Price ?? 0, s.Volume, s.TradeType, s.OrderId, OrderExecutionStatus.New)));
            }
        }
Exemple #2
0
        public override Task <ExecutionReport> CancelOrderAndWaitExecution(TradingSignal signal, TranslatedSignalTableEntity translatedSignal, TimeSpan timeout)
        {
            translatedSignal.RequestSentMessage("stub exchange don't send actual request");
//	        SimulateWork();
//	        SimulateException();
            translatedSignal.ResponseReceived("stub exchange don't recevie actual response");

            bool isCanceled = false;

            lock (syncRoot)
            {
                TradingSignal existing = ActualSignals[signal.Instrument.Name].FirstOrDefault(x => x.OrderId == signal.OrderId);
                if (existing != null)
                {
                    ActualSignals[signal.Instrument.Name].Remove(existing);
                    isCanceled = true;
                }
            }

            return(Task.FromResult(new ExecutionReport(signal.Instrument, DateTime.UtcNow, signal.Price ?? 0, signal.Volume, signal.TradeType, signal.OrderId,
                                                       isCanceled ? OrderExecutionStatus.Cancelled : OrderExecutionStatus.Unknown)));
        }