示例#1
0
        public void Test_GetQuotationsByMaxEndTime()
        {
            var context      = new QuotationContext();
            var providerTime = DateTimeOffset.Now.ToUnixTimeSeconds();
            var arrivedTime  = DateTime.Today.AddHours(10).AddMinutes(10).AddSeconds(10);

            context.Add(new Quotation(_symbol, providerTime, arrivedTime.AddMilliseconds(-100))
            {
                Bid = 1
            });
            context.Add(new Quotation(_symbol, providerTime, arrivedTime.AddMilliseconds(20))
            {
                Bid = 2
            });

            context.Add(new Quotation(_symbol, providerTime, arrivedTime.AddMilliseconds(990))
            {
                Bid = 3
            });
            context.Add(new Quotation(_symbol, providerTime, arrivedTime.AddMilliseconds(1020))
            {
                Bid = 4
            });

            var actual = context.GetQuotationsByMaxEndTime(1, arrivedTime);

            Assert.Equal(actual.Length, 2);
            Assert.Equal(actual[0].Bid, 2);
            Assert.Equal(actual[1].Bid, 3);
        }
        public UncloseOrderWatcher(OrderContext orderContext,
                                   QuotationContext qutationContext, IOrderStore store,
                                   IPricePolicyStore pricePolicyStore, OrderServiceBuilder builder, OrderNotifyManager orderNotifyer)
        {
            if (orderContext == null)
            {
                throw new ArgumentNullException(nameof(orderContext));
            }
            if (qutationContext == null)
            {
                throw new ArgumentNullException(nameof(qutationContext));
            }
            if (store == null)
            {
                throw new ArgumentNullException(nameof(store));
            }
            if (pricePolicyStore == null)
            {
                throw new ArgumentNullException(nameof(pricePolicyStore));
            }
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            _orderContext     = orderContext;
            _qutationContext  = qutationContext;
            _store            = store;
            _pricePolicyStore = pricePolicyStore;
            _builder          = builder;
            _orderNotifyer    = orderNotifyer;

            DefaultClosePricePolicy = new RealTimeCloseOpenPricePolicy();
        }
 public SymbolsController(ISymbolStore symbolStore, QuotationContext quotationContext)
 {
     if (symbolStore == null)
     {
         throw new ArgumentNullException(nameof(symbolStore));
     }
     _symbolStore      = symbolStore;
     _quotationContext = quotationContext;
 }
        public bool TryGetPrice(QuotationContext context, OpenOrderInfo openOrder, Game game, out Quotation price)
        {
            if (game.Symbol == null)
            {
                throw new ArgumentNullException(nameof(game), "game.Synbol should not be null.");
            }
            var startDateTime = openOrder.ClientPostTime ?? openOrder.ArriveDateTime; //客户端提交时间。


            return(context.TryGetQuotation(game.Symbol.Id, startDateTime, out price));
        }
        public bool TryGetPrice(QuotationContext context, OpenOrderInfo openOrder, Game game, out Quotation price)
        {
            if (game.Symbol == null)
            {
                throw new ArgumentNullException(nameof(game), "game.Symbol should not be null.");
            }
            var startDateTime = openOrder.ClientPostTime ?? openOrder.ArriveDateTime; //客户端提交时间。


            var prices = context.GetQuotationsByMaxEndTime(game.Symbol.Id, startDateTime);

            price = openOrder.Direction == Direction.Down ? prices.Max() : prices.Min();

            return(price != null);
        }
示例#6
0
        /// <summary>
        /// </summary>
        /// <param name="orderContext"></param>
        /// <param name="qutationContext"></param>
        /// <param name="orderStore"></param>
        /// <param name="orderPolicyStore"></param>
        /// <param name="pricePolicyStore"></param>
        /// <param name="generator"></param>
        /// <param name="notify"></param>
        /// <param name="logger"></param>
        public OrderService(OrderContext orderContext, QuotationContext qutationContext, IOrderStore orderStore,
                            IOrderPolicyStore orderPolicyStore, IPricePolicyStore pricePolicyStore,
                            IOrderIdGenerator generator, IOrderNotify notify, ILogger <OrderService> logger)
        {
            if (orderContext == null)
            {
                throw new ArgumentNullException(nameof(orderContext));
            }
            if (qutationContext == null)
            {
                throw new ArgumentNullException(nameof(qutationContext));
            }
            if (orderStore == null)
            {
                throw new ArgumentNullException(nameof(orderStore));
            }
            if (generator == null)
            {
                throw new ArgumentNullException(nameof(generator));
            }
            if (notify == null)
            {
                throw new ArgumentNullException(nameof(notify));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _orderContext     = orderContext;
            _qutationContext  = qutationContext;
            _orderStore       = orderStore;
            _orderPolicyStore = orderPolicyStore;
            _pricePolicyStore = pricePolicyStore;


            _orderIdGenerator          = generator;
            _notify                    = notify;
            _logger                    = logger;
            DefaultOpenOpenPricePolicy = new RealTimeOpenPricePolicy();
        }
示例#7
0
        public void TestAddQuoataionOrder()
        {
            var context = new QuotationContext();
            var now     = DateTimeOffset.Now;

            context.Add(new Quotation(_symbol, now.ToUnixTimeSeconds())
            {
                Bid = 1
            });
            context.Add(new Quotation(_symbol, now.AddMilliseconds(100).ToUnixTimeSeconds())
            {
                Bid = 2
            });
            context.Add(new Quotation(_symbol, now.AddMilliseconds(100).ToUnixTimeSeconds())
            {
                Bid = 3
            });

            var s = context.GetList(1).ToArray();

            Assert.Equal(1, s[0].Bid);
            Assert.Equal(2, s[1].Bid);
            Assert.Equal(3, s[2].Bid);
        }
示例#8
0
        public bool TryGetPrice(QuotationContext context, Order order, out Quotation price)
        {
            var matchesPrice = context.GetQuotationsInSecond(
                order.Game.Symbol.Id,
                order.CloseTime, false);

            price = null;
            if (!matchesPrice.Any())
            {
                return(false);
            }
            switch (order.Direction)
            {
            case Direction.Up:
                price = matchesPrice.Min();
                break;

            case Direction.Down:
                price = matchesPrice.Max();
                break;
            }

            return(true);
        }
 public QuotationContextPublisher(QuotationContext context)
 {
     _context = context;
 }
 public QuotationRepository(QuotationContext db)
 {
     DB = db;
 }
示例#11
0
 public DummyController(QuotationContext ctx)
 {
     _ctx = ctx ?? throw new ArgumentNullException(nameof(ctx));
 }
示例#12
0
 public UserRepository(QuotationContext quotationContext)
 {
     _quotationContext = quotationContext;
 }
示例#13
0
 public static void InitializeTests(TestContext testContext)
 {
     DB = ConfigurationHelper.GetQuotationContextTest();
 }
示例#14
0
 public CryptoRepository(QuotationContext db)
 {
     DB = db;
 }
示例#15
0
 public QuotationRepository(QuotationContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
 public QuotationStatusPublisher(QuotationContext contetContext, ISymbolStore symbolStore)
 {
     _contetContext = contetContext;
     _symbolStore   = symbolStore;
 }
 public UserController(QuotationContext quotationContext, ILogger <UserController> logger)
 {
     _quotationContext = quotationContext;
     _logger           = logger;
 }
示例#18
0
 public PurchaseRepository(QuotationContext quotationContext)
 {
     _quotationContext = quotationContext;
 }