Ejemplo n.º 1
0
        public static TickSet FromFile(string fileName, bool load = false)
        {
            var nameOnly = Path.GetFileName(fileName);

            if (!nameOnly.StartsWith("FXCM_FCAPI_"))
            {
                throw new ArgumentOutOfRangeException(nameof(fileName));
            }

            if (!nameOnly.EndsWith("_00_24H_EST.csv"))
            {
                throw new ArgumentOutOfRangeException(nameof(fileName));
            }

            var fields = nameOnly.Split('_');

            var symbol = (Symbol)Enum.Parse(typeof(Symbol), fields[2]);

            var year  = int.Parse(fields[3]);
            var month = int.Parse(fields[4]);
            var day   = int.Parse(fields[5]);

            var date = new DateTime(year, month, day);

            var tickSet = new TickSet(symbol, date);

            if (load)
            {
                tickSet.Load(fileName);
            }

            return(tickSet);
        }
Ejemplo n.º 2
0
        public void Fetch(Symbol symbol, DateTime date)
        {
            if (!symbol.IsDefinedEnum())
            {
                throw new ArgumentOutOfRangeException(nameof(symbol));
            }

            if (date.Kind != DateTimeKind.Unspecified)
            {
                throw new ArgumentException("\"date.Kind\" must be \"Unspecified\"!");
            }

            var ticks = new SortedDictionary <DateTime, Tick>();

            O2GSession session = null;

            try
            {
                session = O2GTransport.createSession();

                var statusListener = new StatusListener(session);

                statusListener.OnStatus += (s, e) =>
                                           OnStatus?.Invoke(this, new StatusArgs((Status)(int)e.Status));

                statusListener.OnError += (s, e) =>
                                          OnError?.Invoke(this, new ErrorArgs(e.Kind, e.Message));

                session.subscribeSessionStatus(statusListener);

                statusListener.Reset();

                session.login(userName, password, URL, connection);

                if (statusListener.WaitEvents() && statusListener.IsConnected)
                {
                    var canUnsubscribeResponse = false;

                    ResponseListener responseListener = null;

                    try
                    {
                        responseListener = new ResponseListener(session);

                        responseListener.OnRequestFailed += (s, e) =>
                                                            OnError?.Invoke(this, new ErrorArgs(ErrorKind.Session, e.ErrorMessage));

                        //????????????????????
                        responseListener.OnNoTicks += (s, e) =>
                        {
                        };

                        session.subscribeResponse(responseListener);

                        canUnsubscribeResponse = true;

                        GetTicks(ticks, symbol, date, session, responseListener);

                        var tickSet = new TickSet(symbol, date);

                        tickSet.Load(ticks.Values);

                        OnTickSet?.Invoke(this, new TickSetArgs(tickSet));
                    }
                    catch (Exception error)
                    {
                        OnError?.Invoke(this, new ErrorArgs(ErrorKind.Client, error.Message));
                    }
                    finally
                    {
                        statusListener.Reset();

                        session.logout();

                        statusListener.WaitEvents();

                        if (canUnsubscribeResponse)
                        {
                            session.unsubscribeResponse(responseListener);
                        }
                    }
                }

                session.unsubscribeSessionStatus(statusListener);
            }
            catch (TimeoutException error)
            {
                OnError?.Invoke(this, new ErrorArgs(ErrorKind.Timeout, error.Message));
            }
            catch (Exception error)
            {
                OnError?.Invoke(this, new ErrorArgs(ErrorKind.Client, error.Message));
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Ejemplo n.º 3
0
 internal TickSetArgs(TickSet tickSet)
 {
     TickSet = tickSet;
 }