Exemplo n.º 1
0
        public int GetPos()
        {
            var hold = _holdings.GetHoldings(_account.AccountID).FirstOrDefault(r => r.InsID == _instrum.InsID);

            if (hold == null)
            {
                return(0);
            }

            return(hold.LotCount);
        }
Exemplo n.º 2
0
        public void OnRecv(byte[] data)
        {
            if (data == null)
            {
                return;
            }

            string str;

            int[] ids;

            try
            {
                str = Encoding.UTF8.GetString(data);
            }
            catch
            {
                return;
            }

            string cmd = CmdParse(str, out ids);

            if (string.IsNullOrEmpty(cmd))
            {
                return;
            }

            if (cmd == "GetInstrumList")
            {
                var instrums = _instrumTable.GetInstrums();
                var json     = JsonConvert.SerializeObject(instrums);
                var bytes    = Encoding.UTF8.GetBytes(json);
                _core.SendResponseAsync(this, bytes).Wait();
            }
            else if (cmd == "GetAccountList")
            {
                var accounts = _accountTable.GetAccounts();
                var json     = JsonConvert.SerializeObject(accounts);
                var bytes    = Encoding.UTF8.GetBytes(json);
                _core.SendResponseAsync(this, bytes).Wait();
            }
            else if (cmd == "GetStopOrders")
            {
                if (ids.Length == 2)
                {
                    var list  = _stopOrderTable.GetStopOrders(ids[0], ids[1]);
                    var json  = JsonConvert.SerializeObject(list);
                    var bytes = Encoding.UTF8.GetBytes(json);
                    _core.SendResponseAsync(this, bytes).Wait();
                }
                else
                {
                    _core.SendResponseAsync(this, null).Wait();
                }
            }
            else if (cmd == "GetStopOrdersByIds")
            {
                if (ids.Length > 0)
                {
                    var list  = _stopOrderTable.GetStopOrdersByIds(ids);
                    var json  = JsonConvert.SerializeObject(list);
                    var bytes = Encoding.UTF8.GetBytes(json);
                    _core.SendResponseAsync(this, bytes).Wait();
                }
                else
                {
                    _core.SendResponseAsync(this, null).Wait();
                }
            }
            else if (cmd == "GetOrders")
            {
                if (ids.Length == 2)
                {
                    var list  = _orderTable.GetOrders(ids[0], ids[1]);
                    var json  = JsonConvert.SerializeObject(list);
                    var bytes = Encoding.UTF8.GetBytes(json);
                    _core.SendResponseAsync(this, bytes).Wait();
                }
                else
                {
                    _core.SendResponseAsync(this, null).Wait();
                }
            }
            else if (cmd == "GetOrdersByIds")
            {
                if (ids.Length > 0)
                {
                    var list  = _orderTable.GetOrdersByIds(ids);
                    var json  = JsonConvert.SerializeObject(list);
                    var bytes = Encoding.UTF8.GetBytes(json);
                    _core.SendResponseAsync(this, bytes).Wait();
                }
                else
                {
                    _core.SendResponseAsync(this, null).Wait();
                }
            }
            else if (cmd == "GetTrades") // GetTrades accountId fromId
            {
                if (ids.Length == 2)
                {
                    var list  = _tradeTable.GetTrades(ids[0], ids[1]);
                    var json  = JsonConvert.SerializeObject(list);
                    var bytes = Encoding.UTF8.GetBytes(json);
                    _core.SendResponseAsync(this, bytes).Wait();
                }
                else
                {
                    _core.SendResponseAsync(this, null).Wait();
                }
            }
            else if (cmd == "GetCash")
            {
                if (ids.Length == 1)
                {
                    var cash  = _cashTable.GetCash(ids[0]);
                    var json  = JsonConvert.SerializeObject(cash);
                    var bytes = Encoding.UTF8.GetBytes(json);
                    _core.SendResponseAsync(this, bytes).Wait();
                }
                else
                {
                    _core.SendResponseAsync(this, null).Wait();
                }
            }
            else if (cmd == "GetHoldingList")
            {
                if (ids.Length == 1)
                {
                    var list  = _holdingTable.GetHoldings(ids[0]);
                    var json  = JsonConvert.SerializeObject(list);
                    var bytes = Encoding.UTF8.GetBytes(json);
                    _core.SendResponseAsync(this, bytes).Wait();
                }
                else
                {
                    _core.SendResponseAsync(this, null).Wait();
                }
            }
            else
            {
                _core.SendResponseAsync(this, null).Wait();
            }
        }