private void BwBitFinex_DoWork(object sender, DoWorkEventArgs e)
        {
            //  BitfinexWebsocketAPI bitfinx = new BitfinexWebsocketAPI(e.Argument as IObjectSpace);

            //   BitfinexWebsocketAPI.GetData(e.Argument as IObjectSpace);
            Arguements a = e.Argument as Arguements;

            BitFinexLiveScraper bs = new BitFinexLiveScraper(e.Argument as IObjectSpace);

            bs.BitAPi = a.BitAPI;
            bs.QuaAPI = a.QuadAPI;
            bs.GetData();
        }
        protected override void OnStart(string[] args)
        {
            IObjectSpace newSpace = null;

            if (server == null)
            {
                ServerApplication serverApplication = new ServerApplication();
                serverApplication.ApplicationName        = "Apollo11";
                serverApplication.CheckCompatibilityType = CheckCompatibilityType.DatabaseSchema;
                // The service can only manage workflows for those business classes that are contained in Modules specified by the serverApplication.Modules collection.
                // So, do not forget to add the required Modules to this collection via the serverApplication.Modules.Add method.
                serverApplication.Modules.BeginInit();
                serverApplication.Modules.Add(new WorkflowModule());
                serverApplication.Modules.Add(new Apollo11.Module.Apollo11Module());
                serverApplication.Modules.Add(new Apollo11.Module.Win.Apollo11WindowsFormsModule());
                serverApplication.Modules.Add(new Apollo11.Module.Web.Apollo11AspNetModule());
                if (ConfigurationManager.ConnectionStrings["ConnectionString"] != null)
                {
                    serverApplication.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                }
                serverApplication.Setup();
                serverApplication.Logon();

                IObjectSpaceProvider objectSpaceProvider = serverApplication.ObjectSpaceProvider;

                WorkflowCreationKnownTypesProvider.AddKnownType(typeof(DevExpress.Xpo.Helpers.IdList));

                server = new WorkflowServer("http://localhost:46232", objectSpaceProvider, objectSpaceProvider);
                server.StartWorkflowListenerService.DelayPeriod      = TimeSpan.FromSeconds(15);
                server.StartWorkflowByRequestService.DelayPeriod     = TimeSpan.FromSeconds(15);
                server.RefreshWorkflowDefinitionsService.DelayPeriod = TimeSpan.FromMinutes(15);

                server.CustomizeHost += delegate(object sender, CustomizeHostEventArgs e) {
                    e.WorkflowInstanceStoreBehavior.WorkflowInstanceStore.RunnableInstancesDetectionPeriod = TimeSpan.FromSeconds(15);
                };

                server.CustomHandleException += delegate(object sender, CustomHandleServiceExceptionEventArgs e) {
                    Tracing.Tracer.LogError(e.Exception);
                    e.Handled = false;
                };



                //init APIS

                BitfinexRestAPI bitapi = new BitfinexRestAPI();
                Quadrigacx      quaAPI = new Quadrigacx(objectSpaceProvider.CreateObjectSpace());


                Arguements package = new Arguements();
                package.BitAPI  = bitapi;
                package.QuadAPI = quaAPI;

                package.Space = objectSpaceProvider.CreateObjectSpace();

                //    bitapi.CreateTrade(Convert.ToDecimal(1186.1),Convert.ToDecimal(0.016),TradeType.Buy);

                //    Console.WriteLine("Created trade " + DateTime.Now.ToString());
                //   Console.ReadLine();



                //
                //start logging live quad data from html site
                BackgroundWorker qwrBW = new BackgroundWorker();

                qwrBW.DoWork             += Qwr_DoWork;
                qwrBW.RunWorkerCompleted += QwrBW_RunWorkerCompleted;
                qwrBW.ProgressChanged    += QwrBW_ProgressChanged;



                //      qwrBW.RunWorkerAsync(objectSpaceProvider.CreateObjectSpace());
                qwrBW.RunWorkerAsync(objectSpaceProvider.CreateObjectSpace());

                //
                //statrt logging bitstamp data

                //BackgroundWorker bWBitStamp = new BackgroundWorker();
                //bWBitStamp.DoWork += QwrBitStamp_DoWork;
                //bWBitStamp.RunWorkerCompleted += QwrBitStamp_RunWorkerCompleted;
                //bWBitStamp.ProgressChanged += QwrBitStamp_ProgressChanged;

                //bWBitStamp.RunWorkerAsync(objectSpaceProvider.CreateObjectSpace());
                //    StartLiveBitStampScraper(objectSpaceProvider.CreateObjectSpace());



                //
                //start logging Bitfinex orders
                BackgroundWorker bwBitFinex = new BackgroundWorker();
                bwBitFinex.DoWork             += BwBitFinex_DoWork;
                bwBitFinex.RunWorkerCompleted += BwBitFinex_RunWorkerCompleted;
                bwBitFinex.ProgressChanged    += BwBitFinex_ProgressChanged;

                bwBitFinex.RunWorkerAsync(package);



                //create trade
                //       Quadrigacx API = new Quadrigacx(objectSpaceProvider.CreateObjectSpace());



                //  Console.WriteLine(DateTime.Now.ToLongTimeString() + " creating trade");
                //    API.CreateSellTrade(Convert.ToDecimal( 0.005), Convert.ToDecimal(1130.98));

                //API.CreateBuyTrade(Convert.ToDecimal(0.005), Convert.ToDecimal(1110.98));

                //var orders = API.QuadrigaAPIClient.GetOpenOrders("btc_cad");
                //  Console.WriteLine(orders.Count().ToString());
            }
            server.Start();
            LogMessage(DateTime.Now + " Server Started ...");
        }