{"action":"created","comment":{"url":"https://api.github.com/repos/QuantConnect/Lean/pulls/comments/42691049","id":42691049,"diff_hunk":"@@ -0,0 +1,364 @@\n+﻿/*\n+ * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.\n+ * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.\n+ * \n+ * Licensed under the Apache License, Version 2.0 (the \"License\"); \n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\n+ * \n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+*/\n+\n+using System;\n+using System.Collections.Concurrent;\n+using System.Collections.Generic;\n+using System.Linq;\n+using System.Threading;\n+using com.fxcm.external.api.transport;\n+using com.fxcm.external.api.transport.listeners;\n+using com.fxcm.external.api.util;\n+using com.fxcm.fix;\n+using com.fxcm.fix.pretrade;\n+using com.fxcm.fix.trade;\n+using QuantConnect.Interfaces;\n+using QuantConnect.Logging;\n+using QuantConnect.Orders;\n+using QuantConnect.Securities;\n+\n+namespace QuantConnect.Brokerages.Fxcm\n+{\n+    /// <summary>\n+    /// The FXCM brokerage implementation\n+    /// </summary>\n+    public partial class FxcmBrokerage : Brokerage, IDataQueueHandler, IGenericMessageListener, IStatusMessageListener\n+    {\n+        private readonly IOrderProvider _orderProvider;\n+        private readonly IHoldingsProvider _holdingsProvider;\n+        private readonly string _server;\n+        private readonly string _terminal;\n+        private readonly string _userName;\n+        private readonly string _password;\n+\n+        private Thread _orderEventThread;\n+        private volatile bool _orderEventThreadStopped;\n+        private readonly ConcurrentQueue<OrderEvent> _orderEventQueue = new ConcurrentQueue<OrderEvent>();\n+\n+        /// <summary>\n+        /// Creates a new instance of the <see cref=\"FxcmBrokerage\"/> class\n+        /// </summary>\n+        /// <param name=\"orderProvider\">The order provider</param>\n+        /// <param name=\"holdingsProvider\">The holdings provider</param>\n+        /// <param name=\"server\">The url of the server</param>\n+        /// <param name=\"terminal\">The terminal name</param>\n+        /// <param name=\"userName\">The user name (login id)</param>\n+        /// <param name=\"password\">The user password</param>\n+        public FxcmBrokerage(IOrderProvider orderProvider, IHoldingsProvider holdingsProvider, string server, string terminal, string userName, string password)\n+            : base(\"FXCM Brokerage\")\n+        {\n+            _orderProvider = orderProvider;\n+            _holdingsProvider = holdingsProvider;\n+            _server = server;\n+            _terminal = terminal;\n+            _userName = userName;\n+            _password = password;\n+        }\n+\n+        #region IBrokerage implementation\n+\n+        /// <summary>\n+        /// Returns true if we're currently connected to the broker\n+        /// </summary>\n+        public override bool IsConnected\n+        {\n+            get\n+            {\n+                return _gateway != null && _gateway.isConnected();\n+            }\n+        }\n+\n+        /// <summary>\n+        /// Connects the client to the broker's remote servers\n+        /// </summary>\n+        public override void Connect()\n+        {\n+            if (IsConnected) return;\n+\n+            Log.TraceFormat(\"FxcmBrokerage.Connect()\");\n+\n+            // create new thread to fire order events in queue\n+            _orderEventThread = new Thread(() =>\n+            {\n+                while (!_orderEventThreadStopped)\n+                {\n+                    OrderEvent orderEvent;\n+                    if (_orderEventQueue.IsEmpty || !_orderEventQueue.TryDequeue(out orderEvent))\n+                    {\n+                        Thread.Sleep(1);\n+                        continue;\n+                    }\n+\n+                    OnOrderEvent(orderEvent);\n+                }\n+            });\n+            _orderEventThread.Start();\n+            while (!_orderEventThread.IsAlive) {}","path":"Brokerages/Fxcm/FxcmBrokerage.cs","position":108,"original_position":108,"commit_id":"f9c0bb3be83ca6a78cd35aff269acdfd9e4b6796","original_commit_id":"f9c0bb3be83ca6a78cd35aff269acdfd9e4b6796","user":{"login":"StefanoRaggi","id":7236689,"avatar_url":"https://avatars.githubusercontent.com/u/7236689?v=3","gravatar_id":"","url":"https://api.github.com/users/StefanoRaggi","html_url":"https://github.com/StefanoRaggi","followers_url":"https://api.github.com/users/StefanoRaggi/followers","following_url":"https://api.github.com/users/StefanoRaggi/following{/other_user}","gists_url":"https://api.github.com/users/StefanoRaggi/gists{/gist_id}","starred_url":"https://api.github.com/users/StefanoRaggi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefanoRaggi/subscriptions","organizations_url":"https://api.github.com/users/StefanoRaggi/orgs","repos_url":"https://api.github.com/users/StefanoRaggi/repos","events_url":"https://api.github.com/users/StefanoRaggi/events{/privacy}","received_events_url":"https://api.github.com/users/StefanoRaggi/received_events","type":"User","site_admin":false},"body":"Absolutely not. I totally forgot the Thread.Sleep. Maybe I was in need of sleep when I wrote that code :smile: ","created_at":"2015-10-21T22:23:50Z","updated_at":"2015-10-21T22:23:50Z","html_url":"https://github.com/QuantConnect/Lean/pull/187#discussion_r42691049","pull_request_url":"https://api.github.com/repos/QuantConnect/Lean/pulls/187","_links":{"self":{"href":"https://api.github.com/repos/QuantConnect/Lean/pulls/comments/42691049"},"html":{"href":"https://github.com/QuantConnect/Lean/pull/187#discussion_r42691049"},"pull_request":{"href":"https://api.github.com/repos/QuantConnect/Lean/pulls/187"}}},"pull_request":{"url":"https://api.github.com/repos/QuantConnect/Lean/pulls/187","id":47844423,"html_url":"https://github.com/QuantConnect/Lean/pull/187","diff_url":"https://github.com/QuantConnect/Lean/pull/187.diff","patch_url":"https://github.com/QuantConnect/Lean/pull/187.patch","issue_url":"https://api.github.com/repos/QuantConnect/Lean/issues/187","number":187,"state":"open","locked":false,"title":"FXCM Brokerage implementation","user":{"login":"StefanoRaggi","id":7236689,"avatar_url":"https://avatars.githubusercontent.com/u/7236689?v=3","gravatar_id":"","url":"https://api.github.com/users/StefanoRaggi","html_url":"https://github.com/StefanoRaggi","followers_url":"https://api.github.com/users/StefanoRaggi/followers","following_url":"https://api.github.com/users/StefanoRaggi/following{/other_user}","gists_url":"https://api.github.com/users/StefanoRaggi/gists{/gist_id}","starred_url":"https://api.github.com/users/StefanoRaggi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefanoRaggi/subscriptions","organizations_url":"https://api.github.com/users/StefanoRaggi/orgs","repos_url":"https://api.github.com/users/StefanoRaggi/repos","events_url":"https://api.github.com/users/StefanoRaggi/events{/privacy}","received_events_url":"https://api.github.com/users/StefanoRaggi/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-15T21:30:03Z","updated_at":"2015-10-21T22:23:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b8bd6984e4616b85584aaccbb1c861305efc54a9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/QuantConnect/Lean/pulls/187/commits","review_comments_url":"https://api.github.com/repos/QuantConnect/Lean/pulls/187/comments","review_comment_url":"https://api.github.com/repos/QuantConnect/Lean/pulls/comments{/number}","comments_url":"https://api.github.com/repos/QuantConnect/Lean/issues/187/comments","statuses_url":"https://api.github.com/repos/QuantConnect/Lean/statuses/f9c0bb3be83ca6a78cd35aff269acdfd9e4b6796","head":{"label":"StefanoRaggi:fxcm","ref":"fxcm","sha":"f9c0bb3be83ca6a78cd35aff269acdfd9e4b6796","user":{"login":"StefanoRaggi","id":7236689,"avatar_url":"https://avatars.githubusercontent.com/u/7236689?v=3","gravatar_id":"","url":"https://api.github.com/users/StefanoRaggi","html_url":"https://github.com/StefanoRaggi","followers_url":"https://api.github.com/users/StefanoRaggi/followers","following_url":"https://api.github.com/users/StefanoRaggi/following{/other_user}","gists_url":"https://api.github.com/users/StefanoRaggi/gists{/gist_id}","starred_url":"https://api.github.com/users/StefanoRaggi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefanoRaggi/subscriptions","organizations_url":"https://api.github.com/users/StefanoRaggi/orgs","repos_url":"https://api.github.com/users/StefanoRaggi/repos","events_url":"https://api.github.com/users/StefanoRaggi/events{/privacy}","received_events_url":"https://api.github.com/users/StefanoRaggi/received_events","type":"User","site_admin":false},"repo":{"id":36553432,"name":"Lean","full_name":"StefanoRaggi/Lean","owner":{"login":"StefanoRaggi","id":7236689,"avatar_url":"https://avatars.githubusercontent.com/u/7236689?v=3","gravatar_id":"","url":"https://api.github.com/users/StefanoRaggi","html_url":"https://github.com/StefanoRaggi","followers_url":"https://api.github.com/users/StefanoRaggi/followers","following_url":"https://api.github.com/users/StefanoRaggi/following{/other_user}","gists_url":"https://api.github.com/users/StefanoRaggi/gists{/gist_id}","starred_url":"https://api.github.com/users/StefanoRaggi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefanoRaggi/subscriptions","organizations_url":"https://api.github.com/users/StefanoRaggi/orgs","repos_url":"https://api.github.com/users/StefanoRaggi/repos","events_url":"https://api.github.com/users/StefanoRaggi/events{/privacy}","received_events_url":"https://api.github.com/users/StefanoRaggi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/StefanoRaggi/Lean","description":"Lean Algorithmic Trading Engine by QuantConnect","fork":true,"url":"https://api.github.com/repos/StefanoRaggi/Lean","forks_url":"https://api.github.com/repos/StefanoRaggi/Lean/forks","keys_url":"https://api.github.com/repos/StefanoRaggi/Lean/keys{/key_id}","collaborators_url":"https://api.github.com/repos/StefanoRaggi/Lean/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/StefanoRaggi/Lean/teams","hooks_url":"https://api.github.com/repos/StefanoRaggi/Lean/hooks","issue_events_url":"https://api.github.com/repos/StefanoRaggi/Lean/issues/events{/number}","events_url":"https://api.github.com/repos/StefanoRaggi/Lean/events","assignees_url":"https://api.github.com/repos/StefanoRaggi/Lean/assignees{/user}","branches_url":"https://api.github.com/repos/StefanoRaggi/Lean/branches{/branch}","tags_url":"https://api.github.com/repos/StefanoRaggi/Lean/tags","blobs_url":"https://api.github.com/repos/StefanoRaggi/Lean/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/StefanoRaggi/Lean/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/StefanoRaggi/Lean/git/refs{/sha}","trees_url":"https://api.github.com/repos/StefanoRaggi/Lean/git/trees{/sha}","statuses_url":"https://api.github.com/repos/StefanoRaggi/Lean/statuses/{sha}","languages_url":"https://api.github.com/repos/StefanoRaggi/Lean/languages","stargazers_url":"https://api.github.com/repos/StefanoRaggi/Lean/stargazers","contributors_url":"https://api.github.com/repos/StefanoRaggi/Lean/contributors","subscribers_url":"https://api.github.com/repos/StefanoRaggi/Lean/subscribers","subscription_url":"https://api.github.com/repos/StefanoRaggi/Lean/subscription","commits_url":"https://api.github.com/repos/StefanoRaggi/Lean/commits{/sha}","git_commits_url":"https://api.github.com/repos/StefanoRaggi/Lean/git/commits{/sha}","comments_url":"https://api.github.com/repos/StefanoRaggi/Lean/comments{/number}","issue_comment_url":"https://api.github.com/repos/StefanoRaggi/Lean/issues/comments{/number}","contents_url":"https://api.github.com/repos/StefanoRaggi/Lean/contents/{+path}","compare_url":"https://api.github.com/repos/StefanoRaggi/Lean/compare/{base}...{head}","merges_url":"https://api.github.com/repos/StefanoRaggi/Lean/merges","archive_url":"https://api.github.com/repos/StefanoRaggi/Lean/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/StefanoRaggi/Lean/downloads","issues_url":"https://api.github.com/repos/StefanoRaggi/Lean/issues{/number}","pulls_url":"https://api.github.com/repos/StefanoRaggi/Lean/pulls{/number}","milestones_url":"https://api.github.com/repos/StefanoRaggi/Lean/milestones{/number}","notifications_url":"https://api.github.com/repos/StefanoRaggi/Lean/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/StefanoRaggi/Lean/labels{/name}","releases_url":"https://api.github.com/repos/StefanoRaggi/Lean/releases{/id}","created_at":"2015-05-30T10:20:39Z","updated_at":"2015-05-30T10:20:41Z","pushed_at":"2015-10-21T21:03:05Z","git_url":"git://github.com/StefanoRaggi/Lean.git","ssh_url":"git@github.com:StefanoRaggi/Lean.git","clone_url":"https://github.com/StefanoRaggi/Lean.git","svn_url":"https://github.com/StefanoRaggi/Lean","homepage":"https://lean.quantconnect.com","size":70378,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"QuantConnect:master","ref":"master","sha":"1e4114dc1ec280a1e8991997955bc3f33c0224ee","user":{"login":"QuantConnect","id":3912814,"avatar_url":"https://avatars.githubusercontent.com/u/3912814?v=3","gravatar_id":"","url":"https://api.github.com/users/QuantConnect","html_url":"https://github.com/QuantConnect","followers_url":"https://api.github.com/users/QuantConnect/followers","following_url":"https://api.github.com/users/QuantConnect/following{/other_user}","gists_url":"https://api.github.com/users/QuantConnect/gists{/gist_id}","starred_url":"https://api.github.com/users/QuantConnect/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QuantConnect/subscriptions","organizations_url":"https://api.github.com/users/QuantConnect/orgs","repos_url":"https://api.github.com/users/QuantConnect/repos","events_url":"https://api.github.com/users/QuantConnect/events{/privacy}","received_events_url":"https://api.github.com/users/QuantConnect/received_events","type":"Organization","site_admin":false},"repo":{"id":27251463,"name":"Lean","full_name":"QuantConnect/Lean","owner":{"login":"QuantConnect","id":3912814,"avatar_url":"https://avatars.githubusercontent.com/u/3912814?v=3","gravatar_id":"","url":"https://api.github.com/users/QuantConnect","html_url":"https://github.com/QuantConnect","followers_url":"https://api.github.com/users/QuantConnect/followers","following_url":"https://api.github.com/users/QuantConnect/following{/other_user}","gists_url":"https://api.github.com/users/QuantConnect/gists{/gist_id}","starred_url":"https://api.github.com/users/QuantConnect/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QuantConnect/subscriptions","organizations_url":"https://api.github.com/users/QuantConnect/orgs","repos_url":"https://api.github.com/users/QuantConnect/repos","events_url":"https://api.github.com/users/QuantConnect/events{/privacy}","received_events_url":"https://api.github.com/users/QuantConnect/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/QuantConnect/Lean","description":"Lean Algorithmic Trading Engine by QuantConnect (C#, Python, F#, VB, Java)","fork":false,"url":"https://api.github.com/repos/QuantConnect/Lean","forks_url":"https://api.github.com/repos/QuantConnect/Lean/forks","keys_url":"https://api.github.com/repos/QuantConnect/Lean/keys{/key_id}","collaborators_url":"https://api.github.com/repos/QuantConnect/Lean/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/QuantConnect/Lean/teams","hooks_url":"https://api.github.com/repos/QuantConnect/Lean/hooks","issue_events_url":"https://api.github.com/repos/QuantConnect/Lean/issues/events{/number}","events_url":"https://api.github.com/repos/QuantConnect/Lean/events","assignees_url":"https://api.github.com/repos/QuantConnect/Lean/assignees{/user}","branches_url":"https://api.github.com/repos/QuantConnect/Lean/branches{/branch}","tags_url":"https://api.github.com/repos/QuantConnect/Lean/tags","blobs_url":"https://api.github.com/repos/QuantConnect/Lean/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/QuantConnect/Lean/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/QuantConnect/Lean/git/refs{/sha}","trees_url":"https://api.github.com/repos/QuantConnect/Lean/git/trees{/sha}","statuses_url":"https://api.github.com/repos/QuantConnect/Lean/statuses/{sha}","languages_url":"https://api.github.com/repos/QuantConnect/Lean/languages","stargazers_url":"https://api.github.com/repos/QuantConnect/Lean/stargazers","contributors_url":"https://api.github.com/repos/QuantConnect/Lean/contributors","subscribers_url":"https://api.github.com/repos/QuantConnect/Lean/subscribers","subscription_url":"https://api.github.com/repos/QuantConnect/Lean/subscription","commits_url":"https://api.github.com/repos/QuantConnect/Lean/commits{/sha}","git_commits_url":"https://api.github.com/repos/QuantConnect/Lean/git/commits{/sha}","comments_url":"https://api.github.com/repos/QuantConnect/Lean/comments{/number}","issue_comment_url":"https://api.github.com/repos/QuantConnect/Lean/issues/comments{/number}","contents_url":"https://api.github.com/repos/QuantConnect/Lean/contents/{+path}","compare_url":"https://api.github.com/repos/QuantConnect/Lean/compare/{base}...{head}","merges_url":"https://api.github.com/repos/QuantConnect/Lean/merges","archive_url":"https://api.github.com/repos/QuantConnect/Lean/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/QuantConnect/Lean/downloads","issues_url":"https://api.github.com/repos/QuantConnect/Lean/issues{/number}","pulls_url":"https://api.github.com/repos/QuantConnect/Lean/pulls{/number}","milestones_url":"https://api.github.com/repos/QuantConnect/Lean/milestones{/number}","notifications_url":"https://api.github.com/repos/QuantConnect/Lean/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/QuantConnect/Lean/labels{/name}","releases_url":"https://api.github.com/repos/QuantConnect/Lean/releases{/id}","created_at":"2014-11-28T04:20:19Z","updated_at":"2015-10-21T22:00:21Z","pushed_at":"2015-10-21T18:36:52Z","git_url":"git://github.com/QuantConnect/Lean.git","ssh_url":"git@github.com:QuantConnect/Lean.git","clone_url":"https://github.com/QuantConnect/Lean.git","svn_url":"https://github.com/QuantConnect/Lean","homepage":"https://lean.quantconnect.com","size":74426,"stargazers_count":292,"watchers_count":292,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":197,"mirror_url":null,"open_issues_count":35,"forks":197,"open_issues":35,"watchers":292,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/QuantConnect/Lean/pulls/187"},"html":{"href":"https://github.com/QuantConnect/Lean/pull/187"},"issue":{"href":"https://api.github.com/repos/QuantConnect/Lean/issues/187"},"comments":{"href":"https://api.github.com/repos/QuantConnect/Lean/issues/187/comments"},"review_comments":{"href":"https://api.github.com/repos/QuantConnect/Lean/pulls/187/comments"},"review_comment":{"href":"https://api.github.com/repos/QuantConnect/Lean/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/QuantConnect/Lean/pulls/187/commits"},"statuses":{"href":"https://api.github.com/repos/QuantConnect/Lean/statuses/f9c0bb3be83ca6a78cd35aff269acdfd9e4b6796"}}}}