{"action":"created","comment":{"url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/comments/30004560","id":30004560,"diff_hunk":"@@ -0,0 +1,148 @@\n+package ch.epfl.ts.example\n+\n+import ch.epfl.ts.component.{ComponentRef, StopSignal, ComponentBuilder}\n+import com.typesafe.config.ConfigFactory\n+import akka.actor.Props\n+import ch.epfl.ts.brokers.StandardBroker\n+import scala.language.postfixOps\n+import scala.concurrent.duration._\n+import ch.epfl.ts.data._\n+import ch.epfl.ts.traders.{MadTrader, MovingAverageTrader, SimpleTraderWithBroker}\n+import ch.epfl.ts.data.Register\n+import ch.epfl.ts.engine._\n+import ch.epfl.ts.data.MarketBidOrder\n+import ch.epfl.ts.data.Register\n+import ch.epfl.ts.engine.FundWallet\n+import ch.epfl.ts.data.MarketAskOrder\n+import ch.epfl.ts.component.fetch.{HistDataCSVFetcher, PullFetchComponent, TrueFxFetcher, MarketNames}\n+import scala.reflect.ClassTag\n+import ch.epfl.ts.data.Currency._\n+import ch.epfl.ts.data.MarketBidOrder\n+import ch.epfl.ts.data.Register\n+import ch.epfl.ts.engine.FundWallet\n+import ch.epfl.ts.data.Quote\n+import ch.epfl.ts.data.Currency\n+import ch.epfl.ts.data.MarketAskOrder\n+import ch.epfl.ts.component.utils.BackLoop\n+import ch.epfl.ts.component.persist.DummyPersistor\n+import java.util.Timer\n+import ch.epfl.ts.engine.rules.{SimulationMarketRulesWrapper, FxMarketRulesWrapper}\n+\n+/**\n+ * Market simulation with first reading historical data and then running simulation on its own.\n+ * Created by sygi on 08.05.15.\n+ */\n+object FullMarketSimulation {\n+  var producers = Map[Class[_], List[ComponentRef]]()\n+  var consuments = Map[Class[_], List[ComponentRef]]()\n+  def main(args: Array[String]): Unit = {\n+    //TODO(sygi): create functions to build multiple components to slim main down\n+    implicit val builder = new ComponentBuilder(\"TestingBroker\", ConfigFactory.parseString(\"akka.loglevel = \\\"DEBUG\\\"\"))\n+    initProducersAndConsuments()\n+\n+    //trader\n+    val parameters = new StrategyParameters(\n+      MadTrader.INITIAL_FUNDS -> WalletParameter(Map(Currency.CHF -> 1000.0)),\n+      MadTrader.INTERVAL -> new TimeParameter(1 seconds),\n+      MadTrader.ORDER_VOLUME -> NaturalNumberParameter(10),\n+      MadTrader.CURRENCY_PAIR -> new CurrencyPairParameter(Currency.USD, Currency.CHF))\n+\n+    val tId = 15L\n+\n+    val trader = MadTrader.getInstance(tId, parameters, \"OneMadTrader\")\n+    addConsument(classOf[Quote], trader)\n+    val broker = builder.createRef(Props(classOf[StandardBroker]), \"Broker\")\n+    addConsument(classOf[Quote], broker)\n+\n+    trader->(broker, classOf[Register])\n+    trader->(broker, classOf[FundWallet])\n+    connectAllOrders(trader, broker)\n+\n+    //fetcher\n+    val useLiveData = false\n+    val symbol = (Currency.USD, Currency.CHF)\n+    val fxQuoteFetcher = createFetcher(useLiveData, builder, symbol)\n+    addProducer(classOf[Quote], fxQuoteFetcher)\n+\n+    //hybrid market\n+    val fetcherRules = new FxMarketRulesWrapper()\n+    val simulationRules = new SimulationMarketRulesWrapper()\n+    val marketForexId = MarketNames.FOREX_ID\n+    val forexMarket = builder.createRef(Props(classOf[HybridMarketSimulator], marketForexId, fetcherRules, simulationRules), MarketNames.FOREX_NAME)\n+\n+    addConsument(classOf[Quote], forexMarket)\n+    addProducer(classOf[Quote], forexMarket)\n+    connectAllOrders(broker, forexMarket)\n+    forexMarket->(broker, classOf[ExecutedBidOrder], classOf[ExecutedAskOrder])\n+\n+    //Backloop\n+    val dummyPersistor = new DummyPersistor()\n+    val backloop = builder.createRef(Props(classOf[BackLoop], marketForexId, dummyPersistor), \"backloop\")\n+\n+    forexMarket->(backloop, classOf[Transaction])\n+    addProducer(classOf[Quote], backloop)\n+\n+    connectProducersWithConsuments()\n+\n+    builder.start\n+    scheduleChange(fxQuoteFetcher, forexMarket)\n+  }\n+\n+  def scheduleChange(quoteFetcher: ComponentRef, market: ComponentRef) = {\n+    val timer = new Timer()\n+    class StopFetcher extends java.util.TimerTask {\n+      def run() {\n+        quoteFetcher.ar ! StopSignal\n+        market.ar ! 'ChangeMarketRules\n+      }\n+    }\n+    timer.schedule(new StopFetcher, 10 * 1000)\n+  }\n+\n+  def initProducersAndConsuments() = {\n+    val messageClasses = List(classOf[Quote], classOf[Transaction])\n+    for(msg <- messageClasses) {\n+      producers = producers + (msg -> List())\n+      consuments = consuments + (msg -> List())\n+    }\n+  }\n+\n+  def addProducer(msg: Class[_], component: ComponentRef) =\n+    producers = addEntity(msg, component, producers)\n+\n+  def addConsument(msg: Class[_], component: ComponentRef) =\n+    consuments = addEntity(msg, component, consuments)\n+\n+  def addEntity(msg: Class[_], component: ComponentRef, mapping: Map[Class[_], List[ComponentRef]]) =\n+    mapping + (msg -> (component :: mapping.getOrElse(msg, List())))\n+\n+  def connectProducersWithConsuments() = {","path":"ts/src/main/scala/ch/epfl/ts/example/FullMarketSimulation.scala","position":112,"original_position":119,"commit_id":"f52d122fc95431056dffe161805c8de27fab24e7","original_commit_id":"8008bead49957be757233dbba05808c4db58f522","user":{"login":"sygi","id":495380,"avatar_url":"https://avatars.githubusercontent.com/u/495380?v=3","gravatar_id":"","url":"https://api.github.com/users/sygi","html_url":"https://github.com/sygi","followers_url":"https://api.github.com/users/sygi/followers","following_url":"https://api.github.com/users/sygi/following{/other_user}","gists_url":"https://api.github.com/users/sygi/gists{/gist_id}","starred_url":"https://api.github.com/users/sygi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sygi/subscriptions","organizations_url":"https://api.github.com/users/sygi/orgs","repos_url":"https://api.github.com/users/sygi/repos","events_url":"https://api.github.com/users/sygi/events{/privacy}","received_events_url":"https://api.github.com/users/sygi/received_events","type":"User","site_admin":false},"body":"It can be done (in the next PR), but actually I don't see the gain from using it when we have only one creator of `Quotes` or one consument of it.","created_at":"2015-05-10T18:17:21Z","updated_at":"2015-05-10T18:17:21Z","html_url":"https://github.com/merlinND/TradingSimulation/pull/45#discussion_r30004560","pull_request_url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/45","_links":{"self":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/comments/30004560"},"html":{"href":"https://github.com/merlinND/TradingSimulation/pull/45#discussion_r30004560"},"pull_request":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/45"}}},"pull_request":{"url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/45","id":35071579,"html_url":"https://github.com/merlinND/TradingSimulation/pull/45","diff_url":"https://github.com/merlinND/TradingSimulation/pull/45.diff","patch_url":"https://github.com/merlinND/TradingSimulation/pull/45.patch","issue_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues/45","number":45,"state":"open","locked":false,"title":"Full market-simulation","user":{"login":"sygi","id":495380,"avatar_url":"https://avatars.githubusercontent.com/u/495380?v=3","gravatar_id":"","url":"https://api.github.com/users/sygi","html_url":"https://github.com/sygi","followers_url":"https://api.github.com/users/sygi/followers","following_url":"https://api.github.com/users/sygi/following{/other_user}","gists_url":"https://api.github.com/users/sygi/gists{/gist_id}","starred_url":"https://api.github.com/users/sygi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sygi/subscriptions","organizations_url":"https://api.github.com/users/sygi/orgs","repos_url":"https://api.github.com/users/sygi/repos","events_url":"https://api.github.com/users/sygi/events{/privacy}","received_events_url":"https://api.github.com/users/sygi/received_events","type":"User","site_admin":false},"body":"Introduces `HybridMarketSimulator`, which first executes like `FxMarketSimulator` (but actually deals with the `LimitOrders`...), and after getting a `'ChangeMarketRules` message changes execution to the regular simulation (like `OrderBookMarketSimulator`. To do it, I added a class of `MarketRulesWrapper` - the _really_ self-contained MarketRules.","created_at":"2015-05-09T19:20:29Z","updated_at":"2015-05-10T18:17:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e60b655ed2bbae2ac2d48f59a62affe247e10da5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/45/commits","review_comments_url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/45/comments","review_comment_url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/comments{/number}","comments_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues/45/comments","statuses_url":"https://api.github.com/repos/merlinND/TradingSimulation/statuses/f52d122fc95431056dffe161805c8de27fab24e7","head":{"label":"merlinND:full-market","ref":"full-market","sha":"f52d122fc95431056dffe161805c8de27fab24e7","user":{"login":"merlinND","id":5563370,"avatar_url":"https://avatars.githubusercontent.com/u/5563370?v=3","gravatar_id":"","url":"https://api.github.com/users/merlinND","html_url":"https://github.com/merlinND","followers_url":"https://api.github.com/users/merlinND/followers","following_url":"https://api.github.com/users/merlinND/following{/other_user}","gists_url":"https://api.github.com/users/merlinND/gists{/gist_id}","starred_url":"https://api.github.com/users/merlinND/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/merlinND/subscriptions","organizations_url":"https://api.github.com/users/merlinND/orgs","repos_url":"https://api.github.com/users/merlinND/repos","events_url":"https://api.github.com/users/merlinND/events{/privacy}","received_events_url":"https://api.github.com/users/merlinND/received_events","type":"User","site_admin":false},"repo":{"id":31139958,"name":"TradingSimulation","full_name":"merlinND/TradingSimulation","owner":{"login":"merlinND","id":5563370,"avatar_url":"https://avatars.githubusercontent.com/u/5563370?v=3","gravatar_id":"","url":"https://api.github.com/users/merlinND","html_url":"https://github.com/merlinND","followers_url":"https://api.github.com/users/merlinND/followers","following_url":"https://api.github.com/users/merlinND/following{/other_user}","gists_url":"https://api.github.com/users/merlinND/gists{/gist_id}","starred_url":"https://api.github.com/users/merlinND/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/merlinND/subscriptions","organizations_url":"https://api.github.com/users/merlinND/orgs","repos_url":"https://api.github.com/users/merlinND/repos","events_url":"https://api.github.com/users/merlinND/events{/privacy}","received_events_url":"https://api.github.com/users/merlinND/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/merlinND/TradingSimulation","description":"TradingSimulation is a modular framework designed for back-testing trading strategies.","fork":true,"url":"https://api.github.com/repos/merlinND/TradingSimulation","forks_url":"https://api.github.com/repos/merlinND/TradingSimulation/forks","keys_url":"https://api.github.com/repos/merlinND/TradingSimulation/keys{/key_id}","collaborators_url":"https://api.github.com/repos/merlinND/TradingSimulation/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/merlinND/TradingSimulation/teams","hooks_url":"https://api.github.com/repos/merlinND/TradingSimulation/hooks","issue_events_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues/events{/number}","events_url":"https://api.github.com/repos/merlinND/TradingSimulation/events","assignees_url":"https://api.github.com/repos/merlinND/TradingSimulation/assignees{/user}","branches_url":"https://api.github.com/repos/merlinND/TradingSimulation/branches{/branch}","tags_url":"https://api.github.com/repos/merlinND/TradingSimulation/tags","blobs_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/refs{/sha}","trees_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/trees{/sha}","statuses_url":"https://api.github.com/repos/merlinND/TradingSimulation/statuses/{sha}","languages_url":"https://api.github.com/repos/merlinND/TradingSimulation/languages","stargazers_url":"https://api.github.com/repos/merlinND/TradingSimulation/stargazers","contributors_url":"https://api.github.com/repos/merlinND/TradingSimulation/contributors","subscribers_url":"https://api.github.com/repos/merlinND/TradingSimulation/subscribers","subscription_url":"https://api.github.com/repos/merlinND/TradingSimulation/subscription","commits_url":"https://api.github.com/repos/merlinND/TradingSimulation/commits{/sha}","git_commits_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/commits{/sha}","comments_url":"https://api.github.com/repos/merlinND/TradingSimulation/comments{/number}","issue_comment_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues/comments{/number}","contents_url":"https://api.github.com/repos/merlinND/TradingSimulation/contents/{+path}","compare_url":"https://api.github.com/repos/merlinND/TradingSimulation/compare/{base}...{head}","merges_url":"https://api.github.com/repos/merlinND/TradingSimulation/merges","archive_url":"https://api.github.com/repos/merlinND/TradingSimulation/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/merlinND/TradingSimulation/downloads","issues_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues{/number}","pulls_url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls{/number}","milestones_url":"https://api.github.com/repos/merlinND/TradingSimulation/milestones{/number}","notifications_url":"https://api.github.com/repos/merlinND/TradingSimulation/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/merlinND/TradingSimulation/labels{/name}","releases_url":"https://api.github.com/repos/merlinND/TradingSimulation/releases{/id}","created_at":"2015-02-21T20:34:13Z","updated_at":"2015-05-07T12:42:48Z","pushed_at":"2015-05-10T18:15:01Z","git_url":"git://github.com/merlinND/TradingSimulation.git","ssh_url":"git@github.com:merlinND/TradingSimulation.git","clone_url":"https://github.com/merlinND/TradingSimulation.git","svn_url":"https://github.com/merlinND/TradingSimulation","homepage":"","size":6050,"stargazers_count":3,"watchers_count":3,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":6,"forks":1,"open_issues":6,"watchers":3,"default_branch":"master"}},"base":{"label":"merlinND:master","ref":"master","sha":"bacab3b2b760475d9c4b1bdaa03f3ab0a31d0912","user":{"login":"merlinND","id":5563370,"avatar_url":"https://avatars.githubusercontent.com/u/5563370?v=3","gravatar_id":"","url":"https://api.github.com/users/merlinND","html_url":"https://github.com/merlinND","followers_url":"https://api.github.com/users/merlinND/followers","following_url":"https://api.github.com/users/merlinND/following{/other_user}","gists_url":"https://api.github.com/users/merlinND/gists{/gist_id}","starred_url":"https://api.github.com/users/merlinND/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/merlinND/subscriptions","organizations_url":"https://api.github.com/users/merlinND/orgs","repos_url":"https://api.github.com/users/merlinND/repos","events_url":"https://api.github.com/users/merlinND/events{/privacy}","received_events_url":"https://api.github.com/users/merlinND/received_events","type":"User","site_admin":false},"repo":{"id":31139958,"name":"TradingSimulation","full_name":"merlinND/TradingSimulation","owner":{"login":"merlinND","id":5563370,"avatar_url":"https://avatars.githubusercontent.com/u/5563370?v=3","gravatar_id":"","url":"https://api.github.com/users/merlinND","html_url":"https://github.com/merlinND","followers_url":"https://api.github.com/users/merlinND/followers","following_url":"https://api.github.com/users/merlinND/following{/other_user}","gists_url":"https://api.github.com/users/merlinND/gists{/gist_id}","starred_url":"https://api.github.com/users/merlinND/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/merlinND/subscriptions","organizations_url":"https://api.github.com/users/merlinND/orgs","repos_url":"https://api.github.com/users/merlinND/repos","events_url":"https://api.github.com/users/merlinND/events{/privacy}","received_events_url":"https://api.github.com/users/merlinND/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/merlinND/TradingSimulation","description":"TradingSimulation is a modular framework designed for back-testing trading strategies.","fork":true,"url":"https://api.github.com/repos/merlinND/TradingSimulation","forks_url":"https://api.github.com/repos/merlinND/TradingSimulation/forks","keys_url":"https://api.github.com/repos/merlinND/TradingSimulation/keys{/key_id}","collaborators_url":"https://api.github.com/repos/merlinND/TradingSimulation/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/merlinND/TradingSimulation/teams","hooks_url":"https://api.github.com/repos/merlinND/TradingSimulation/hooks","issue_events_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues/events{/number}","events_url":"https://api.github.com/repos/merlinND/TradingSimulation/events","assignees_url":"https://api.github.com/repos/merlinND/TradingSimulation/assignees{/user}","branches_url":"https://api.github.com/repos/merlinND/TradingSimulation/branches{/branch}","tags_url":"https://api.github.com/repos/merlinND/TradingSimulation/tags","blobs_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/refs{/sha}","trees_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/trees{/sha}","statuses_url":"https://api.github.com/repos/merlinND/TradingSimulation/statuses/{sha}","languages_url":"https://api.github.com/repos/merlinND/TradingSimulation/languages","stargazers_url":"https://api.github.com/repos/merlinND/TradingSimulation/stargazers","contributors_url":"https://api.github.com/repos/merlinND/TradingSimulation/contributors","subscribers_url":"https://api.github.com/repos/merlinND/TradingSimulation/subscribers","subscription_url":"https://api.github.com/repos/merlinND/TradingSimulation/subscription","commits_url":"https://api.github.com/repos/merlinND/TradingSimulation/commits{/sha}","git_commits_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/commits{/sha}","comments_url":"https://api.github.com/repos/merlinND/TradingSimulation/comments{/number}","issue_comment_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues/comments{/number}","contents_url":"https://api.github.com/repos/merlinND/TradingSimulation/contents/{+path}","compare_url":"https://api.github.com/repos/merlinND/TradingSimulation/compare/{base}...{head}","merges_url":"https://api.github.com/repos/merlinND/TradingSimulation/merges","archive_url":"https://api.github.com/repos/merlinND/TradingSimulation/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/merlinND/TradingSimulation/downloads","issues_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues{/number}","pulls_url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls{/number}","milestones_url":"https://api.github.com/repos/merlinND/TradingSimulation/milestones{/number}","notifications_url":"https://api.github.com/repos/merlinND/TradingSimulation/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/merlinND/TradingSimulation/labels{/name}","releases_url":"https://api.github.com/repos/merlinND/TradingSimulation/releases{/id}","created_at":"2015-02-21T20:34:13Z","updated_at":"2015-05-07T12:42:48Z","pushed_at":"2015-05-10T18:15:01Z","git_url":"git://github.com/merlinND/TradingSimulation.git","ssh_url":"git@github.com:merlinND/TradingSimulation.git","clone_url":"https://github.com/merlinND/TradingSimulation.git","svn_url":"https://github.com/merlinND/TradingSimulation","homepage":"","size":6050,"stargazers_count":3,"watchers_count":3,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":6,"forks":1,"open_issues":6,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/45"},"html":{"href":"https://github.com/merlinND/TradingSimulation/pull/45"},"issue":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/issues/45"},"comments":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/issues/45/comments"},"review_comments":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/45/comments"},"review_comment":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/45/commits"},"statuses":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/statuses/f52d122fc95431056dffe161805c8de27fab24e7"}}}}