/// <summary>
        /// Constructor for brokerage
        /// </summary>
        /// <param name="wssUrl">websockets url</param>
        /// <param name="restUrl">rest api url</param>
        /// <param name="apiKey">api key</param>
        /// <param name="apiSecret">api secret</param>
        /// <param name="algorithm">the algorithm instance is required to retrieve account type</param>
        /// <param name="priceProvider">The price provider for missing FX conversion rates</param>
        public BitfinexBrokerage(string wssUrl, string restUrl, string apiKey, string apiSecret, IAlgorithm algorithm, IPriceProvider priceProvider)
            : base(wssUrl, new WebSocketWrapper(), new RestClient(restUrl), apiKey, apiSecret, Market.Bitfinex, "Bitfinex")
        {
            _algorithm        = algorithm;
            _securityProvider = algorithm?.Portfolio;
            _priceProvider    = priceProvider;

            WebSocket.Open += (sender, args) =>
            {
                SubscribeAuth();
            };
        }
        /// <summary>
        /// Constructor for brokerage
        /// </summary>
        /// <param name="wssUrl">websockets url</param>
        /// <param name="websocket">instance of websockets client</param>
        /// <param name="restClient">instance of rest client</param>
        /// <param name="apiKey">api key</param>
        /// <param name="apiSecret">api secret</param>
        /// <param name="passPhrase">pass phrase</param>
        /// <param name="algorithm">the algorithm instance is required to retreive account type</param>
        /// <param name="priceProvider">The price provider for missing FX conversion rates</param>
        /// <param name="aggregator">consolidate ticks</param>
        public GDAXBrokerage(string wssUrl, IWebSocket websocket, IRestClient restClient, string apiKey, string apiSecret, string passPhrase, IAlgorithm algorithm,
                             IPriceProvider priceProvider, IDataAggregator aggregator)
            : base(wssUrl, websocket, restClient, apiKey, apiSecret, "GDAX")
        {
            FillSplit      = new ConcurrentDictionary <long, GDAXFill>();
            _passPhrase    = passPhrase;
            _algorithm     = algorithm;
            _priceProvider = priceProvider;
            _aggregator    = aggregator;

            _isDataQueueHandler = this is GDAXDataQueueHandler;

            _fillMonitorTask = Task.Factory.StartNew(FillMonitorAction, _ctsFillMonitor.Token);
        }
Exemple #3
0
        public SearchQueryViewService(
            ISearchRepository searchRepository,
            IViewModelMapper viewModelMapper,
            IDamProvider damProvider,
            ILocalizationProvider localizationProvider,
            IProductUrlProvider productUrlProvider,
            ISearchUrlProvider searchUrlProvider,
            IFacetFactory facetFactory,
            ISelectedFacetFactory selectedFacetFactory,
            IPriceProvider priceProvider,
            IComposerContext composerContext,
            IProductSettingsViewService productSettings,
            IScopeViewService scopeViewService,
            ISearchQueryRepository searchQueryRepository,
            ISearchQueryUrlProvider searchQueryUrlProvider,
            IProductSettingsRepository productSettingsRepository,
            Repositories.IInventoryRepository inventoryRepository,
            IRecurringOrdersSettings recurringOrdersSettings
            )

            : base(
                searchRepository,
                viewModelMapper,
                damProvider,
                localizationProvider,
                productUrlProvider,
                searchUrlProvider,
                facetFactory,
                selectedFacetFactory,
                priceProvider,
                composerContext,
                productSettings,
                scopeViewService,
                recurringOrdersSettings)
        {
            if (searchQueryRepository == null)
            {
                throw new ArgumentNullException("searchQueryRepository");
            }
            if (searchQueryUrlProvider == null)
            {
                throw new ArgumentNullException("searchQuerySearchRepository");
            }

            SearchQueryRepository     = searchQueryRepository;
            SearchQueryUrlProvider    = searchQueryUrlProvider;
            ProductSettingsRepository = productSettingsRepository;
            InventoryRepository       = inventoryRepository;
        }
Exemple #4
0
        public void Start(IPriceProvider provider)
        {
            // Set up topic details
            var builder = topicControl.CreateDetailsBuilder <ISingleValueTopicDetailsBuilder>();
            var details = builder.Metadata(Diffusion.Metadata.Decimal("Price")).Build();

            // Declare a custom update source implementation.  When the source is set as active, start a periodic task
            // to poll the provider every second and update the topic.  When the source is closed, stop the scheduled
            // task.
            var source = new UpdateSource(provider, updateCallback);

            // Create the topic.  When the callback indicates that the topic has been created, register the topic
            // source for the topic
            topicControl.AddTopicFromValue(TopicName, details, new AddCallback(updateControl, source));
        }
 public ProductSearchViewModelFactory(
     IViewModelMapper viewModelMapper,
     IProductUrlProvider productUrlProvider,
     IRecurringOrdersSettings recurringOrdersSettings,
     IComposerContext composerContext,
     IProductSettingsViewService productSettings,
     IPriceProvider priceProvider)
 {
     ViewModelMapper         = viewModelMapper ?? throw new ArgumentNullException(nameof(viewModelMapper));
     ProductUrlProvider      = productUrlProvider ?? throw new ArgumentNullException(nameof(productUrlProvider));
     RecurringOrdersSettings = recurringOrdersSettings ?? throw new ArgumentNullException(nameof(recurringOrdersSettings));
     ComposerContext         = composerContext ?? throw new ArgumentNullException(nameof(composerContext));
     ProductSettings         = productSettings ?? throw new ArgumentNullException(nameof(productSettings));
     PriceProvider           = priceProvider ?? throw new ArgumentNullException(nameof(priceProvider));
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="GDAXDataQueueHandler"/> class
        /// </summary>
        public GDAXDataQueueHandler(string wssUrl, IWebSocket websocket, IRestClient restClient, string apiKey, string apiSecret, string passPhrase, IAlgorithm algorithm,
                                    IPriceProvider priceProvider, IDataAggregator aggregator)
            : base(wssUrl, websocket, restClient, apiKey, apiSecret, passPhrase, algorithm, priceProvider, aggregator)
        {
            var subscriptionManager = new EventBasedDataQueueHandlerSubscriptionManager();

            subscriptionManager.SubscribeImpl += (s, t) =>
            {
                Subscribe(s);
                return(true);
            };
            subscriptionManager.UnsubscribeImpl += (s, t) => Unsubscribe(s);

            SubscriptionManager = subscriptionManager;
        }
        private void                            TestMarketPrices(IPriceProvider a_PriceProvider, Settings.V2._PriceSettings a_Settings, bool a_Silent)
        {
            ItemFilter filter = new ItemFilter();

            filter.HasMarketGroup  = TristateFilter.Yes;
            filter.IsPricesOk      = TristateFilter.No;
            filter.PriceExpiryDays = a_Settings.ExpiryDays;

            UInt32[] badItems = m_ItemsDB.FilterItems(filter);
            if (0 == badItems.Count())
            {
                return;
            }

            if (!a_Silent)
            {
                if (DialogResult.Yes != MessageBox.Show("You have outdated market prices. Would you like to update them now?", Application.ProductName, MessageBoxButtons.YesNo))
                {
                    return;
                }
            }

            Queue <UInt32> pricesQueue = new Queue <UInt32>();

            foreach (UInt32 currItem in badItems)
            {
                pricesQueue.Enqueue(currItem);
            }

            StopUpdaterThread();

            UpdateThreadParam param = new UpdateThreadParam();

            param.PriceProvider = a_PriceProvider;
            param.UpdateQueue   = pricesQueue;

            ThreadWithParam paramThread = new ThreadWithParam();

            paramThread.Function  = ThreadQueryMarketPrices;
            paramThread.Parameter = param;

            m_EndUpdateThread = false;
            m_UpdateQueue     = pricesQueue;

            m_UpdateThread = paramThread.CreateThread();
            m_UpdateThread.IsBackground = true;
            m_UpdateThread.Start();
        }
Exemple #8
0
        private static ShoppingCart PrepareCart(IWorkContextAccessor wca, IEnumerable <DiscountStub> discounts = null, IEnumerable <ITaxProvider> taxProviders = null)
        {
            var contentItems   = discounts == null ? Products : Products.Cast <IContent>().Union(discounts);
            var contentManager = new ContentManagerStub(contentItems);
            var cartStorage    = new FakeCartStorage();
            var priceProviders = new IPriceProvider[] {
                new DiscountPriceProvider(contentManager, wca, Now)
                {
                    DisplayUrlResolver = item => ((ProductStub)item).Path
                }
            };
            var priceService = new PriceService(priceProviders, new ProductAttributeService(contentManager), new TieredPriceProvider(wca));
            var cart         = new ShoppingCart(contentManager, cartStorage, priceService, null, taxProviders, new Notifier());

            return(cart);
        }
        public async Task PlaceBid(Direction dir, decimal amount, IPriceProvider priceProvider)
        {
            if (IsEnded)
            {
                throw new CannotBidOnEndedGameException();
            }
            if (amount > TotalAmount)
            {
                throw new NotEnoughMoneyException();
            }
            if (CurrentBid != null)
            {
                throw new BidAlreadyPlacedException();
            }

            Produce(new BidPlaced(Id, dir, amount, await priceProvider.GetPrice()));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GDAXDataQueueHandler"/> class
 /// </summary>
 public GDAXDataQueueHandler(string wssUrl, IWebSocket websocket, IRestClient restClient, string apiKey, string apiSecret, string passPhrase, IAlgorithm algorithm,
                             IPriceProvider priceProvider, IDataAggregator aggregator, LiveNodePacket job)
     : base(wssUrl, websocket, restClient, apiKey, apiSecret, passPhrase, algorithm, priceProvider, aggregator, job)
 {
     Initialize(
         wssUrl: wssUrl,
         websocket: websocket,
         restClient: restClient,
         apiKey: apiKey,
         apiSecret: apiSecret,
         passPhrase: passPhrase,
         algorithm: algorithm,
         priceProvider: priceProvider,
         aggregator: aggregator,
         job: job
         );
 }
Exemple #11
0
        public CategoryBrowsingViewService(
            ISearchRepository searchRepository,
            IViewModelMapper viewModelMapper,
            IDamProvider damProvider,
            ILocalizationProvider localizationProvider,
            IProductUrlProvider productUrlProvider,
            ISearchUrlProvider searchUrlProvider,
            ICategoryRepository categoryRepository,
            ICategoryBrowsingUrlProvider categoryBrowsingUrlProvider,
            IFacetFactory facetFactory,
            ISelectedFacetFactory selectedFacetFactory,
            IPriceProvider priceProvider,
            IComposerContext composerContext,
            IProductSettingsViewService productSettings,
            IScopeViewService scopeViewService,
            IRecurringOrdersSettings recurringOrdersSettings)

            : base(
                searchRepository,
                viewModelMapper,
                damProvider,
                localizationProvider,
                productUrlProvider,
                searchUrlProvider,
                facetFactory,
                selectedFacetFactory,
                priceProvider,
                composerContext,
                productSettings,
                scopeViewService,
                recurringOrdersSettings
                )
        {
            if (categoryRepository == null)
            {
                throw new ArgumentNullException(nameof(categoryRepository));
            }
            if (categoryBrowsingUrlProvider == null)
            {
                throw new ArgumentNullException(nameof(categoryBrowsingUrlProvider));
            }

            CategoryRepository          = categoryRepository;
            CategoryBrowsingUrlProvider = categoryBrowsingUrlProvider;
        }
        /// <summary>
        /// Constructor for brokerage
        /// </summary>
        /// <param name="wssUrl">websockets url</param>
        /// <param name="websocket">instance of websockets client</param>
        /// <param name="restClient">instance of rest client</param>
        /// <param name="apiKey">api key</param>
        /// <param name="apiSecret">api secret</param>
        /// <param name="passPhrase">pass phrase</param>
        /// <param name="algorithm">the algorithm instance is required to retreive account type</param>
        /// <param name="priceProvider">The price provider for missing FX conversion rates</param>
        public GDAXBrokerage(string wssUrl, IWebSocket websocket, IRestClient restClient, string apiKey, string apiSecret, string passPhrase, IAlgorithm algorithm,
                             IPriceProvider priceProvider)
            : base(wssUrl, websocket, restClient, apiKey, apiSecret, Market.GDAX, "GDAX")
        {
            FillSplit      = new ConcurrentDictionary <long, GDAXFill>();
            _passPhrase    = passPhrase;
            _algorithm     = algorithm;
            _priceProvider = priceProvider;

            WebSocket.Open += (sender, args) =>
            {
                var tickers = new[]
                {
                    "LTCUSD", "LTCEUR", "LTCBTC",
                    "BTCUSD", "BTCEUR", "BTCGBP",
                    "ETHBTC", "ETHUSD", "ETHEUR",
                    "BCHBTC", "BCHUSD", "BCHEUR"
                };
                Subscribe(tickers.Select(ticker => Symbol.Create(ticker, SecurityType.Crypto, Market.GDAX)));
            };

            _isDataQueueHandler = this is GDAXDataQueueHandler;
        }
Exemple #13
0
        public void                                     DropPrices(IPriceProvider a_PriceProvider)
        {
            StopUpdaterThread();

            ItemPrices.PricesDataTable pricesTable = new ItemPrices.PricesDataTable();

            string selectSQL = "Delete from " + pricesTable.TableName + " where " +
                               "(" + pricesTable.ProviderIDColumn.ColumnName + " = @ProviderID) AND " +
                               "(" + pricesTable.RegionIDColumn.ColumnName + " = @RegionID) AND " +
                               "(" + pricesTable.SolarIDColumn.ColumnName + " = @SolarID) AND " +
                               "(" + pricesTable.StationIDColumn.ColumnName + " = @StationID) AND" +
                               "(" + pricesTable.PriceTypeColumn.ColumnName + " = @PriceType)";

            SQLiteCommand sqlCommand  = new SQLiteCommand(selectSQL, m_DbConnection);
            PriceRecord   priceFilter = a_PriceProvider.GetCurrentFilter();

            sqlCommand.Parameters.AddWithValue("@ProviderID", (UInt32)priceFilter.Provider);
            sqlCommand.Parameters.AddWithValue("@RegionID", priceFilter.RegionID);
            sqlCommand.Parameters.AddWithValue("@SolarID", priceFilter.SolarID);
            sqlCommand.Parameters.AddWithValue("@StationID", priceFilter.StationID);
            sqlCommand.Parameters.AddWithValue("@PriceType", (UInt32)priceFilter.PriceType);

            sqlCommand.ExecuteNonQuery();
        }
        public static ShoppingCart PrepareCart(
            IEnumerable <DiscountStub> discounts,
            IEnumerable <ITaxProvider> taxProviders = null,
            bool applyProductDiscounts = false
            )
        {
            var products       = applyProductDiscounts ? ProductsWithDiscounts : Products;
            var contentItems   = discounts == null ? products : products.Cast <IContent>().Union(discounts);
            var contentManager = new ContentManagerStub(contentItems);
            var cartStorage    = new FakeCartStorage();
            var priceProviders = new IPriceProvider[] {
                new DiscountPriceProvider(contentManager, WorkContextAccessor, Now)
                {
                    DisplayUrlResolver = item => ((ProductStub)item).Path
                },
                new ProductDiscountPriceProvider()
            };
            var priceService = new PriceService(priceProviders, null);
            var cart         = new ShoppingCart(contentManager, cartStorage, priceService, null, taxProviders, new Notifier());

            FillCart(cart);

            return(cart);
        }
Exemple #15
0
 public ButterBreadDiscount(IPriceProvider priceProvider)
 {
     _priceProvider = priceProvider;
 }
Exemple #16
0
 public MilkDiscount(IPriceProvider priceProvider)
 {
     _priceProvider = priceProvider;
 }
Exemple #17
0
 public BinaryOptionGame(Guid gameId, decimal initialAmount, decimal winAmount, IPriceProvider provider) : this(gameId, provider)
 {
     Produce(new GameCreated(Id, initialAmount, winAmount));
 }
        /// <summary>
        /// Constructor for brokerage
        /// </summary>
        /// <param name="websocket">instance of websockets client</param>
        /// <param name="restClient">instance of rest client</param>
        /// <param name="apiKey">api key</param>
        /// <param name="apiSecret">api secret</param>
        /// <param name="algorithm">the algorithm instance is required to retrieve account type</param>
        /// <param name="priceProvider">The price provider for missing FX conversion rates</param>
        /// <param name="aggregator">consolidate ticks</param>
        public BitfinexBrokerage(IWebSocket websocket, IRestClient restClient, string apiKey, string apiSecret, IAlgorithm algorithm, IPriceProvider priceProvider, IDataAggregator aggregator)
            : base(WebSocketUrl, websocket, restClient, apiKey, apiSecret, "Bitfinex")
        {
            SubscriptionManager       = new BitfinexSubscriptionManager(this, WebSocketUrl, _symbolMapper);
            _symbolPropertiesDatabase = SymbolPropertiesDatabase.FromDataFolder();
            _algorithm  = algorithm;
            _aggregator = aggregator;

            WebSocket.Open += (sender, args) =>
            {
                SubscribeAuth();
            };
        }
Exemple #19
0
 public TotalCalculator(IEnumerable <IDiscount> discounts, IPriceProvider priceProvider)
 {
     _priceProvider = priceProvider;
     _discounts     = discounts;
 }
Exemple #20
0
 /// <summary>
 /// Constructor for brokerage
 /// </summary>
 /// <param name="wssUrl">websockets url</param>
 /// <param name="restUrl">rest api url</param>
 /// <param name="apiKey">api key</param>
 /// <param name="apiSecret">api secret</param>
 /// <param name="algorithm">the algorithm instance is required to retrieve account type</param>
 /// <param name="priceProvider">The price provider for missing FX conversion rates</param>
 /// <param name="aggregator">consolidate ticks</param>
 public BitfinexBrokerage(string wssUrl, string restUrl, string apiKey, string apiSecret, IAlgorithm algorithm, IPriceProvider priceProvider, IDataAggregator aggregator)
     : this(wssUrl, new WebSocketClientWrapper(), new RestClient(restUrl), apiKey, apiSecret, algorithm, priceProvider, aggregator)
 {
 }
        /// <summary>
        /// Constructor for brokerage
        /// </summary>
        /// <param name="websocket">instance of websockets client</param>
        /// <param name="restClient">instance of rest client</param>
        /// <param name="apiKey">api key</param>
        /// <param name="apiSecret">api secret</param>
        /// <param name="algorithm">the algorithm instance is required to retrieve account type</param>
        /// <param name="priceProvider">The price provider for missing FX conversion rates</param>
        /// <param name="aggregator">consolidate ticks</param>
        /// <param name="job">The live job packet</param>
        public BitfinexBrokerage(IWebSocket websocket, IRestClient restClient, string apiKey, string apiSecret, IAlgorithm algorithm, IPriceProvider priceProvider, IDataAggregator aggregator, LiveNodePacket job)
            : base(WebSocketUrl, websocket, restClient, apiKey, apiSecret, "Bitfinex")
        {
            _job = job;

            SubscriptionManager = new BrokerageMultiWebSocketSubscriptionManager(
                WebSocketUrl,
                MaximumSymbolsPerConnection,
                0,
                null,
                () => new BitfinexWebSocketWrapper(null),
                Subscribe,
                Unsubscribe,
                OnDataMessage,
                TimeSpan.Zero,
                _connectionRateLimiter);

            _symbolPropertiesDatabase = SymbolPropertiesDatabase.FromDataFolder();
            _algorithm  = algorithm;
            _aggregator = aggregator;

            // load currency map
            using (var wc = new WebClient())
            {
                var json = wc.DownloadString("https://api-pub.bitfinex.com/v2/conf/pub:map:currency:sym");
                var rows = JsonConvert.DeserializeObject <List <List <List <string> > > >(json)[0];
                _currencyMap = rows
                               .ToDictionary(row => row[0], row => row[1].ToUpperInvariant());
            }

            WebSocket.Open += (sender, args) =>
            {
                SubscribeAuth();
            };
        }
        public void Start( IPriceProvider provider )
        {
            // Set up topic details
            var builder = topicControl.CreateDetailsBuilder<ISingleValueTopicDetailsBuilder>();
            var details = builder.Metadata( Diffusion.Metadata.Decimal( "Price" ) ).Build();

            // Declare a custom update source implementation. When the source is set as active, start a periodic task
            // to poll the provider every second and update the topic. When the source is closed, stop the scheduled
            // task.
            var source = new UpdateSource( provider, updateCallback );

            // Create the topic. When the callback indicates that the topic has been created, register the topic
            // source for the topic.
            topicControl.AddTopicFromValue( TopicName, details, new AddCallback( updateControl, source ) );
        }
 /// <summary>
 /// Constructor for brokerage
 /// </summary>
 /// <param name="websocket">instance of websockets client</param>
 /// <param name="restClient">instance of rest client</param>
 /// <param name="apiKey">api key</param>
 /// <param name="apiSecret">api secret</param>
 /// <param name="algorithm">the algorithm instance is required to retrieve account type</param>
 /// <param name="priceProvider">The price provider for missing FX conversion rates</param>
 /// <param name="aggregator">consolidate ticks</param>
 /// <param name="job">The live job packet</param>
 public BitfinexBrokerage(IWebSocket websocket, IRestClient restClient, string apiKey, string apiSecret, IAlgorithm algorithm, IPriceProvider priceProvider, IDataAggregator aggregator, LiveNodePacket job)
     : base("Bitfinex")
 {
     Initialize(
         wssUrl: WebSocketUrl,
         websocket: websocket,
         restClient: restClient,
         apiKey: apiKey,
         apiSecret: apiSecret,
         algorithm: algorithm,
         aggregator: aggregator,
         job: job
         );
 }
Exemple #24
0
 public UpdateSource(IPriceProvider provider, ITopicUpdaterUpdateCallback callback)
 {
     thePriceProvider  = provider;
     theUpdateCallback = callback;
 }
Exemple #25
0
 public BinaryOptionsAggregateConstructor(IPriceProvider provider)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GDAXDataQueueHandler"/> class
 /// </summary>
 public GDAXDataQueueHandler(string wssUrl, IWebSocket websocket, IRestClient restClient, string apiKey, string apiSecret, string passPhrase, IAlgorithm algorithm,
                             IPriceProvider priceProvider)
     : base(wssUrl, websocket, restClient, apiKey, apiSecret, passPhrase, algorithm, priceProvider)
 {
 }
Exemple #27
0
        private void UpdatePricesSettingsHint()
        {
            IPriceProvider priceProvider = PriceProviderAuto.GetPriceProvider(m_Engine.m_Settings.PriceLoad.Items);

            TlbLblPricesType.Text = priceProvider.GetCurrentFilterHint(m_EveDatabase);
        }
 /// <summary>
 /// Constructor for brokerage
 /// </summary>
 /// <param name="apiKey">api key</param>
 /// <param name="apiSecret">api secret</param>
 /// <param name="algorithm">the algorithm instance is required to retrieve account type</param>
 /// <param name="priceProvider">The price provider for missing FX conversion rates</param>
 /// <param name="aggregator">consolidate ticks</param>
 /// <param name="job">The live job packet</param>
 public BitfinexBrokerage(string apiKey, string apiSecret, IAlgorithm algorithm, IPriceProvider priceProvider, IDataAggregator aggregator, LiveNodePacket job)
     : this(new WebSocketClientWrapper(), new RestClient(RestApiUrl), apiKey, apiSecret, algorithm, priceProvider, aggregator, job)
 {
 }
Exemple #29
0
 public Basket(IPriceProvider priceProvider)
 {
     PriceProvider = priceProvider;
     BasketItems   = new List <BasketItem>();
 }
Exemple #30
0
 public BasketCalculator(IPriceProvider priceProvider)
 {
     _priceProvider = priceProvider;
 }
 public UpdateSource( IPriceProvider provider, ITopicUpdaterUpdateCallback callback )
 {
     thePriceProvider = provider;
     theUpdateCallback = callback;
 }
 public GDAXFakeDataQueueHandler(string wssUrl, IWebSocket websocket, IRestClient restClient, string apiKey, string apiSecret, string passPhrase, IAlgorithm algorithm,
     IPriceProvider priceProvider, IDataAggregator aggregator)
 : base(wssUrl, websocket, restClient, apiKey, apiSecret, passPhrase, algorithm, priceProvider, aggregator, null)
 {
 }
Exemple #33
0
 public BasicPriceCache(IPriceProvider baseProvider)
 {
     this.baseProvider = baseProvider;
 }