Пример #1
0
        /// <summary>
        /// Insert Trade object
        /// </summary>
        /// <param name="trade">Trade object with TradeID = 0</param>
        /// <returns>New TradeID value and set it to object</returns>
        public int InsertTrade(CommonData.Trade trade)
        {
            Trade db_trade = new Trade()
            {
                TradeID   = trade.TradeID,
                OrderID   = trade.OrderID,
                Time      = StorageLib.ToDbTime(trade.Time),
                InsID     = trade.InsID,
                BuySell   = (byte)trade.BuySell,
                LotCount  = trade.LotCount,
                Price     = trade.Price,
                AccountID = trade.AccountID,
                Comm      = trade.Comm,
                TradeNo   = trade.TradeNo
            };

            _da.DbContext.Insert(db_trade);
            trade.TradeID = db_trade.TradeID;

            return(trade.TradeID);
        }
Пример #2
0
        /// <summary>
        /// Get Trades by account, date and id.
        /// </summary>
        /// <param name="accountID">Account</param>
        /// <param name="dateFrom">From date-time (or null)</param>
        /// <param name="idFrom">From tradeId (or zero)</param>
        /// <returns>Trade list</returns>
        public IEnumerable <CommonData.Trade> GetTrades(int accountID, DateTime?dateFrom, int idFrom)
        {
            List <CommonData.Trade> trades = new List <CommonData.Trade>();

            List <Trade> db_trades;
            var          db_alltrades = _da.DbContext.Table <Trade>().Where(r => r.AccountID == accountID && r.TradeID >= idFrom);

            if (dateFrom != null)
            {
                int df = StorageLib.ToDbTime(dateFrom.Value);
                db_trades = db_alltrades.Where(r => r.Time >= df).ToList();
            }
            else
            {
                db_trades = db_alltrades.ToList();
            }

            foreach (var db_trade in db_trades)
            {
                var trade = new CommonData.Trade()
                {
                    TradeID   = db_trade.TradeID,
                    OrderID   = db_trade.OrderID,
                    Time      = StorageLib.ToDateTime(db_trade.Time),
                    InsID     = db_trade.InsID,
                    BuySell   = (BuySell)db_trade.BuySell,
                    LotCount  = db_trade.LotCount,
                    Price     = db_trade.Price,
                    AccountID = db_trade.AccountID,
                    Comm      = db_trade.Comm,
                    TradeNo   = db_trade.TradeNo
                };
                trades.Add(trade);
            }

            return(trades);
        }