Пример #1
0
        /// <summary>
        /// Get user's last 20 deals
        /// </summary>
        /// <param name="type">Type of system</param>
        /// <param name="market">Market</param>
        public List <DataDeal> GetDeals(SysType type, MarketType market)
        {
            List <DataDeal> result = null;

            // check params
            if (type == SysType.Empty)
            {
                throw new ArgumentNullException("type");
            }
            if (market == MarketType.Empty)
            {
                throw new ArgumentNullException("market");
            }

            // request formation
            var request = type == SysType.Real ? new Request(MethodType.Deals) : new Request(MethodType.DemoDeals);

            request.Params.Add("market", EnumValue.GetValue(market));
            request.Prepare(public_key, private_key);

            // request execution
            var response = ExecQuery(request);

            // response analysis
            if (response.IsSuccessfully)
            {
                result = (response.ResponseObject as ResponseDeals)?.Data;
            }

            return(result);
        }
        public static SysTypesDto ToSysDto(this SysType rst)
        {
            switch (rst)
            {
            case SysType.EusET:
                return(SysTypesDto.EusET);

            case SysType.ElioET:
                return(SysTypesDto.ElioET);

            case SysType.Rn:
                return(SysTypesDto.Rn);

            case SysType.SabreET:
                return(SysTypesDto.SabreET);

            case SysType.EusTest:
                return(SysTypesDto.EusTest);

            case SysType.Default:
                return(SysTypesDto.Default);

            default:
                throw new InvalidOperationException();
            }
        }
Пример #3
0
        /// <summary>
        /// Closes the connection.
        /// </summary>
        /// <param name="sysType">Type of the system.</param>
        public void CloseConnection(SysType sysType)
        {
            switch (sysType)
            {
            case SysType.Peer:
                foreach (var con in _netPeer.Connections)
                {
                    con.Disconnect("Disconnecting");
                }

                break;

            case SysType.Client:
                foreach (var con in _netClient.Connections)
                {
                    con.Disconnect("Disconnecting");
                }

                break;

            case SysType.Server:
                foreach (var con in _netServer.Connections)
                {
                    con.Disconnect("Disconnecting");
                }

                break;
            }

            Thread.Sleep(1000);
        }
 public T getSys <T>(SysType sysType) where T : SysBase
 {
     if (m_sys.ContainsKey(sysType))
     {
         return((T)m_sys[sysType]);
     }
     return(default(T));
 }
    public void addSys(SysBase sys, SysType t)
    {
        if (sys == null)
        {
            return;
        }

        m_sys.Add(t, sys);
    }
Пример #6
0
        /// <summary>
        /// Move order
        /// </summary>
        /// <param name="type">Type of system</param>
        /// <param name="market">Market</param>
        /// <param name="order">Order data</param>
        public DataOrder OrderMove(SysType type, MarketType market, Order order)
        {
            DataOrder result = null;

            // check params
            if (type == SysType.Empty)
            {
                throw new ArgumentNullException("type");
            }
            if (market == MarketType.Empty)
            {
                throw new ArgumentNullException("market");
            }
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }

            // request formation
            var request = type == SysType.Real ? new Request(MethodType.OrderMove) : new Request(MethodType.DemoMove);

            request.Params.Add("market", EnumValue.GetValue(market));
            request.Params.Add("id", order.OrderID);
            request.Params.Add("price", order.Price);
            request.Prepare(public_key, private_key);

            // request execution
            var response = ExecQuery(request);

            // response analysis
            if (response.IsSuccessfully)
            {
                result = (response.ResponseObject as ResponseOrderResult)?.Data;
            }
            else
            {
                string mess = string.Empty;

                if (string.IsNullOrWhiteSpace(response?.RetMessage))
                {
                    mess = "Empty error message";
                }
                else
                {
                    var res = JsonConvert.DeserializeObject <ResponseBase>(response?.RetMessage);
                    mess = res.Message;
                }

                result = new DataOrder
                {
                    ErrorMessage = mess
                };
            }

            return(result);
        }
Пример #7
0
 public static int GetChannelsG(SysType s)
 {
     if ((int)s < 0x08)
     {
         return(1);
     }
     if ((int)s < 0x0c)
     {
         return(2);
     }
     return(3);
 }
Пример #8
0
 public static int GetChannelsPorT(SysType s)
 {
     if ((int)s < 0x01)
     {
         return(0);
     }
     if ((int)s < 0x03)
     {
         return(1);
     }
     if ((int)s < 0x0a)
     {
         return(2);
     }
     return(3);
 }
Пример #9
0
        /// <summary>
        /// Get user's balances
        /// </summary>
        /// <param name="type">Type of system</param>
        public Dictionary <MarketType, DataBalances> GetBalances(SysType type)
        {
            Dictionary <MarketType, DataBalances> result = null;

            // check params
            if (type == SysType.Empty)
            {
                throw new ArgumentNullException("type");
            }

            // request formation
            var request = type == SysType.Real ? new Request(MethodType.Balances) : new Request(MethodType.DemoBalances);

            request.Prepare(public_key, private_key);

            // request execution
            var response = ExecQuery(request);

            // response analysis
            if (response.IsSuccessfully)
            {
                result = new Dictionary <MarketType, DataBalances>();

                var data = (response.ResponseObject as ResponseBalances)?.Data;

                // fill result
                foreach (var item in data)
                {
                    string market_name = item.Key;
                    market_name = market_name.Replace(demo, string.Empty);
                    var market = EnumValue.GetEnum <MarketType>(market_name);

                    if (market == MarketType.Empty)
                    {
                        logger.Error("Undeclared market value: {0}", item.Key);
                    }
                    else
                    {
                        result.Add(market, item.Value);
                    }
                }
            }

            return(result);
        }
Пример #10
0
        /// <summary>
        /// Ends the peer.
        /// </summary>
        /// <param name="sysType">Type of the system.</param>
        public void EndPeer(SysType sysType)
        {
            switch (sysType)
            {
            case SysType.Peer:
                if (_netPeer == null)
                {
                    return;
                }

                if (_netPeer.Status == NetPeerStatus.Running)
                {
                    _netPeer.Shutdown("Shutting Down");
                }

                break;

            case SysType.Client:
                if (_netClient == null)
                {
                    return;
                }

                if (_netClient.Status == NetPeerStatus.Running)
                {
                    _netClient.Shutdown("Shutting Down");
                }

                break;

            case SysType.Server:
                if (_netServer == null)
                {
                    return;
                }

                if (_netServer.Status == NetPeerStatus.Running)
                {
                    _netServer.Shutdown("Shutting Down");
                }

                break;
            }
        }
        public static string ToLtSystem(this SysType SysType)
        {
            switch (SysType)
            {
            case SysType.EusET:
                return(LtSystems.Eus);

            case SysType.ElioET:
                return(LtSystems.Elio);

            case SysType.SabreET:
                return(LtSystems.Sabre);

            case SysType.Rn:
                return(LtSystems.Rn);

            default:
                throw new ArgumentOutOfRangeException(nameof(SysType), SysType.ToString(), null);
            }
        }
        public static EntitySysType ToEntitySys(this SysType dataAccessRsystem)
        {
            switch (dataAccessRsystem)
            {
            case SysType.EusET:
                return(EntitySysType.EusET);

            case SysType.ElioET:
                return(EntitySysType.ElioET);

            case SysType.SabreET:
                return(EntitySysType.SabreET);

            case SysType.Rn:
                return(EntitySysType.Rn);

            default:
                return(EntitySysType.Unknown);
            }
        }
Пример #13
0
        /// <summary>
        /// Establish connection to port and host.
        /// </summary>
        /// <param name="type">The type of the system (only peer or client are supported).</param>
        /// <param name="host">The host. Example: 129.12.12.12</param>
        /// <param name="port">The port.</param>
        /// <returns>True if connection was succesfully opened.</returns>
        public bool OpenConnection(SysType type, string host, int port)
        {
            NetConnection connection = null;

            if (type == SysType.Peer)
            {
                // START FIRST!
                var hail = _netPeer.CreateMessage("OpenConnection");
                connection = _netPeer.Connect(host, port, hail);
            }

            if (type == SysType.Client)
            {
                // START FIRST!
                var hail = _netClient.CreateMessage("OpenConnection");
                connection = _netClient.Connect(host, port, hail);
            }

            return
                ((connection != null) && connection.Status == NetConnectionStatus.Connected);
        }
        private MainPoint CreateEntityMainPoint(Guid id, SysType systemType, EusMainPoint asp, bool isTest, DateTime now, string userName, Guid EntityId, MainPointType MainPointType)
        {
            var sp = new MainPoint
            {
                MainPointGuid       = Guid.NewGuid(),
                Sys                 = systemType,
                IsTest              = isTest,
                AgentCode           = asp.AgentCode,
                CityCode            = asp.CityCode,
                Address             = asp.Address ?? string.Empty,
                SalingType          = asp.SaleType == (byte)EntitySales.SaleTypes.Own,
                IsBlock             = false,
                Qaa                 = false,
                InterfaceOfArs      = 0,
                EthereumIsConnected = false,
                IsCharter           = false,
                CreatedDate         = now,
                ModifiedDate        = now,
                EusMainPointGuid    = asp.Id,
                CreatedBy           = userName,
                ModifiedBy          = userName,
                MainPointType       = MainPointType
            };

            sp.EntityExpirations.Add(new EntityExpiration
            {
                EntityExpirationGuid = id,
                ValidFrom            = now.Date,
                ValidTo      = new DateTime(2050, 1, 1),
                EntityGuid   = EntityId,
                ModifiedDate = now,
                IsActive     = true
            });

            return(sp);
        }
Пример #15
0
        DataTable ToSqlBulkCopyDataTable <TModel>(List <TModel> modelList, TypeDescriptor typeDescriptor, string tableName)
        {
            DataTable dt = new DataTable();

            List <SysColumn>     columns        = GetTableColumns(tableName);
            List <ColumnMapping> columnMappings = new List <ColumnMapping>();

            var mappingPropertyDescriptors = typeDescriptor.PropertyDescriptors.ToList();

            for (int i = 0; i < columns.Count; i++)
            {
                var column = columns[i];
                PropertyDescriptor mappingPropertyDescriptor = mappingPropertyDescriptors.Find(a => string.Equals(a.Column.Name, column.Name));
                if (mappingPropertyDescriptor == null)
                {
                    mappingPropertyDescriptor = mappingPropertyDescriptors.Find(a => string.Equals(a.Column.Name, column.Name, StringComparison.OrdinalIgnoreCase));
                }

                ColumnMapping columnMapping = new ColumnMapping(column);
                Type          dataType;
                if (mappingPropertyDescriptor == null)
                {
                    /*
                     * 由于 SqlBulkCopy 要求传入的列必须与表列一一对应,因此,如果 model 中没有与列对应的属性,则使用列数据类型的默认值
                     */

                    SysType sysType = GetSysTypeByTypeName(column.TypeName);
                    columnMapping.DefaultValue = column.IsNullable ? null : sysType.DefaultValue;
                    dataType = sysType.CSharpType;
                }
                else
                {
                    columnMapping.MapMember = mappingPropertyDescriptor.Property;
                    dataType = mappingPropertyDescriptor.PropertyType.GetUnderlyingType();
                    if (dataType.IsEnum)
                    {
                        dataType = Enum.GetUnderlyingType(dataType);
                    }
                }

                columnMappings.Add(columnMapping);
                dt.Columns.Add(new DataColumn(column.Name, dataType));
            }

            foreach (var model in modelList)
            {
                DataRow dr = dt.NewRow();
                for (int i = 0; i < columnMappings.Count; i++)
                {
                    ColumnMapping columnMapping = columnMappings[i];
                    MemberInfo    member        = columnMapping.MapMember;
                    object        value         = null;
                    if (member == null)
                    {
                        value = columnMapping.DefaultValue;
                    }
                    else
                    {
                        value = member.GetMemberValue(model);
                        if (member.GetMemberType().GetUnderlyingType().IsEnum)
                        {
                            if (value != null)
                            {
                                value = Convert.ChangeType(value, Enum.GetUnderlyingType(value.GetType()));
                            }
                        }
                    }

                    dr[i] = value ?? DBNull.Value;
                }

                dt.Rows.Add(dr);
            }

            return(dt);
        }
Пример #16
0
 /// <summary>
 /// Create a JSON-string for subs to user balances
 /// </summary>
 /// <param name="subs">Subscription type</param>
 /// <param name="sys_type">Type of system</param>
 public static string Balances(SubsType subs, SysType sys_type) => JsonConvert.SerializeObject(new MessSendSubs(MessType.UserSubs, ProcType.Balances, subs, MarketType.Empty, null, sys_type));
 /// <summary>
 /// Opens the connection.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="ip">The ip.</param>
 /// <returns>True if connection was succesfully opened.</returns>
 public bool OpenConnection(SysType type, IPEndPoint ip)
 {
     return OpenConnection(type, ip.Address.ToString(), ip.Port);
 }
        /// <summary>
        /// Establish connection to port and host.
        /// </summary>
        /// <param name="type">The type of the system (only peer or client are supported).</param>
        /// <param name="host">The host. Example: 129.12.12.12</param>
        /// <param name="port">The port.</param>
        /// <returns>True if connection was succesfully opened.</returns>
        public bool OpenConnection(SysType type, string host, int port)
        {
            NetConnection connection = null;

            if (type == SysType.Peer)
            {
                // START FIRST!
                var hail = _netPeer.CreateMessage("OpenConnection");
                connection = _netPeer.Connect(host, port, hail);
            }

            if (type == SysType.Client)
            {
                // START FIRST!
                var hail = _netClient.CreateMessage("OpenConnection");
                connection = _netClient.Connect(host, port, hail);
            }

            return
                (connection != null) && connection.Status == NetConnectionStatus.Connected;
        }
        /// <summary>
        /// Closes the connection.
        /// </summary>
        /// <param name="sysType">Type of the system.</param>
        public void CloseConnection(SysType sysType)
        {
            switch (sysType)
            {
                case SysType.Peer:
                    foreach (var con in _netPeer.Connections)
                        con.Disconnect("Disconnecting");

                    break;

                case SysType.Client:
                    foreach (var con in _netClient.Connections)
                        con.Disconnect("Disconnecting");

                    break;

                case SysType.Server:
                    foreach (var con in _netServer.Connections)
                        con.Disconnect("Disconnecting");

                    break;
            }

            Thread.Sleep(1000);
        }
        /// <summary>
        /// Ends the peer.
        /// </summary>
        /// <param name="sysType">Type of the system.</param>
        public void EndPeer(SysType sysType)
        {
            switch (sysType)
            {
                case SysType.Peer:
                    if (_netPeer == null) return;

                    if (_netPeer.Status == NetPeerStatus.Running)
                        _netPeer.Shutdown("Shutting Down");

                    break;

                case SysType.Client:
                    if (_netClient == null) return;

                    if (_netClient.Status == NetPeerStatus.Running)
                        _netClient.Shutdown("Shutting Down");

                    break;

                case SysType.Server:
                    if (_netServer == null) return;

                    if (_netServer.Status == NetPeerStatus.Running)
                        _netServer.Shutdown("Shutting Down");

                    break;
            }
        }
Пример #21
0
 /// <summary>
 /// Opens the connection.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="ip">The ip.</param>
 /// <returns>True if connection was succesfully opened.</returns>
 public bool OpenConnection(SysType type, IPEndPoint ip)
 {
     return(OpenConnection(type, ip.Address.ToString(), ip.Port));
 }
Пример #22
0
 public bool OpenConnection(SysType type, string host, int port)
 {
     return(false);
 }
Пример #23
0
 public MessBase(MessType type, ProcType proc, MarketType market = MarketType.Empty, string pair = null, SysType sys_type = SysType.Empty) : this()
 {
     Type = type;
     Key  = new SKey(proc, market, pair, sys_type);
 }
Пример #24
0
 public bool OpenConnection(SysType type, string host, int port)
 {
     throw new System.NotImplementedException();
 }
Пример #25
0
 /// <summary>
 /// Create a JSON-string for the order moving task
 /// </summary>
 /// <param name="sys_type">Type of system</param>
 /// <param name="market">Market</param>
 /// <param name="order">Order data with order id and new price</param>
 public static string OrderMove(SysType sys_type, MarketType market, Order order) =>
 sys_type == SysType.Real ?
 JsonConvert.SerializeObject(new MessSendControl(ActionType.OrderMove, market, order)) :
 JsonConvert.SerializeObject(new MessSendControl(ActionType.DemoMove, market, order));
Пример #26
0
 /// <summary>
 /// Create a JSON-string for subs to user last 20 deals
 /// </summary>
 /// <param name="subs">Subscription type</param>
 /// <param name="market">Market</param>
 /// <param name="sys_type">Type of system</param>
 public static string Deals(SubsType subs, MarketType market, SysType sys_type) => JsonConvert.SerializeObject(new MessSendSubs(MessType.UserSubs, ProcType.Deals, subs, market, null, sys_type));
    public static T getGlobalSys <T>(SysType sysType) where T : SysBase
    {
        SysMgr mgr = (SysMgr)HttpContext.Current.Application["sys"];

        return(mgr.getSys <T>(sysType));
    }
Пример #28
0
        DataTable ToSqlBulkCopyDataTable <TModel>(List <TModel> modelList, TypeDescriptor typeDescriptor)
        {
            DataTable dt = new DataTable();

            List <SysColumn>     columns        = GetTableColumns(typeDescriptor.Table.Name);
            List <ColumnMapping> columnMappings = new List <ColumnMapping>();

            var mappingMemberDescriptors = typeDescriptor.MappingMemberDescriptors.Select(a => a.Value).ToList();

            for (int i = 0; i < columns.Count; i++)
            {
                var column = columns[i];
                MappingMemberDescriptor mappingMemberDescriptor = mappingMemberDescriptors.Where(a => a.Column.Name == column.Name).FirstOrDefault();
                ColumnMapping           columnMapping           = new ColumnMapping(column);
                Type dataType;
                if (mappingMemberDescriptor == null)
                {
                    /*
                     * 由于 SqlBulkCopy 要求传入的列必须与表列一一对应,因此,如果 model 中没有与列对应的属性,则使用列数据类型的默认值
                     */

                    SysType sysType = GetSysTypeByTypeName(column.TypeName);
                    columnMapping.DefaultValue = column.IsNullable ? null : sysType.DefaultValue;
                    dataType = sysType.CSharpType;
                }
                else
                {
                    columnMapping.MapMember = mappingMemberDescriptor.MemberInfo;
                    dataType = mappingMemberDescriptor.MemberInfoType.GetUnderlyingType();
                    if (dataType.IsEnum)
                    {
                        dataType = typeof(int);
                    }
                }

                columnMappings.Add(columnMapping);
                dt.Columns.Add(new DataColumn(column.Name, dataType));
            }

            foreach (var model in modelList)
            {
                DataRow dr = dt.NewRow();
                for (int i = 0; i < columnMappings.Count; i++)
                {
                    ColumnMapping columnMapping = columnMappings[i];
                    MemberInfo    member        = columnMapping.MapMember;
                    object        value         = null;
                    if (member == null)
                    {
                        value = columnMapping.DefaultValue;
                    }
                    else
                    {
                        value = member.GetMemberValue(model);
                        if (member.GetMemberType().GetUnderlyingType().IsEnum)
                        {
                            if (value != null)
                            {
                                value = Convert.ChangeType(value, Enum.GetUnderlyingType(value.GetType()));
                            }
                        }
                    }

                    dr[i] = value ?? DBNull.Value;
                }

                dt.Rows.Add(dr);
            }

            return(dt);
        }
Пример #29
0
 /// <summary>
 /// Create a JSON-string for the order placement task
 /// </summary>
 /// <param name="sys_type">Type of system</param>
 /// <param name="market">Market</param>
 /// <param name="order">Order data</param>
 /// <param name="api_guid">GUID to track an order placed</param>
 public static string OrderPlace(SysType sys_type, MarketType market, Order order, string api_guid = null) =>
 sys_type == SysType.Real ?
 JsonConvert.SerializeObject(new MessSendControl(ActionType.OrderPlace, market, order, api_guid)) :
 JsonConvert.SerializeObject(new MessSendControl(ActionType.DemoPlace, market, order, api_guid));