コード例 #1
0
        public static void Run([TimerTrigger("0 0 22 * * *", RunOnStartup = false)] TimerInfo myTimer, TraceWriter log)
        {
            try
            {
                Logger = new Logger(log);
                Logger.Write("Starting new process");

                StockReader  stockReader = new StockReader();
                List <Stock> stocks      = stockReader.ReadShares();

                CurrencyReader    currencyReader    = new CurrencyReader();
                List <Currency>   currencies        = currencyReader.ReadCurrencies();
                CurrencyConverter currencyConverter = new CurrencyConverter(currencies);

                PriceReader priceReader = new PriceReader(currencyConverter);
                stocks = priceReader.ReadValueOfStocks(stocks);

                DynamoWriter stockWriter = new DynamoWriter();
                stockWriter.WriteStockValues(stocks);
                stockWriter.WriteDailyTotal(stocks.Sum(x => x.TotalValue));

                Logger.Write("Process complete");
            }
            catch (Exception e)
            {
                log.Info(String.Format("Exception thrown: {0} - {1}", e.Message, e.StackTrace));
            }
        }
コード例 #2
0
        public void InvalidPriceTests(string price)
        {
            // When
            bool actualResult = PriceReader.IsPriceValid(price);

            // Then
            Assert.False(actualResult);
        }
コード例 #3
0
        public void Configure(PriceReader reader)
        {
            var configurable = Slicer as IConfigurable;

            if (configurable != null)
            {
                configurable.Configure(reader);
            }
        }
コード例 #4
0
        private List <FormalizationPosition> Read()
        {
            var reader = new PriceReader(new FakePrser(table), "", info);

            reader.CostDescriptions = costDescriptions;
            var positions = reader.Read().ToList();

            return(positions);
        }
コード例 #5
0
 public void Configure(PriceReader reader)
 {
     PeriodField = reader.GetFieldName(PriceFields.Period);
 }
 public GetPricingByPriceIdHandler(PriceReader pricingReader, IMapper mapper)
 {
     this.pricingReader = pricingReader;
     this.mapper        = mapper;
 }
コード例 #7
0
 public GetPricesHandler(PriceReader priceReader, IMapper mapper)
 {
     this.priceReader = priceReader;
     this.mapper      = mapper;
 }
 public GetPricingByPriceIdHandler(PriceReader pricingReader, IMapper mapper)
 {
     _pricingReader = pricingReader;
     _mapper        = mapper;
 }
コード例 #9
0
 public void Configure(PriceReader reader)
 {
     _reader = reader;
     _costs  = reader.CostDescriptions;
     _rules  = LoadRules(_table);
 }
コード例 #10
0
 public GetPriceBySolutionIdHandler(PriceReader priceReader, SolutionVerifier verifier, IMapper mapper)
 {
     _priceReader = priceReader;
     _verifier    = verifier;
     _mapper      = mapper;
 }
コード例 #11
0
        /// <summary>Create a CryptoLadder.</summary>
        public async Task CreateLadder(string apiKey, string apiSign)
        {
            _logger.LogInformation(0, "Starting creating CryptoLadder");
            ConsoleColor defaultConsoleForegroundColor = Console.ForegroundColor;

            SymbolEnum symbol        = SymbolReader.Get();
            double     startPrice    = PriceReader.Get(true);
            double     endPrice      = PriceReader.Get(false);
            int        ladderRungs   = RungsReader.Get();
            int        totalQuantity = QuantityReader.Get(ladderRungs);

            Configuration.Default.ApiKey.Add("api_key", apiKey);
            Configuration.Default.ApiKey.Add("sign", apiSign);

            KeyInfo apiKeyInfo = new KeyInfo();
            // Get account api-key information.
            APIKeyBase resultKeyInfo = await apiKeyInfo.CallApiAsync();

            _logger.LogDebug(0, resultKeyInfo.ToJson());
            SideEnum orderSide = SideEnum.Buy;

            if (startPrice < endPrice)
            {
                orderSide = SideEnum.Sell;
            }
            double        gaps         = SharedBusinessLogic.Ladder.Calculate(startPrice, endPrice, ladderRungs);
            StringBuilder confirmation = new StringBuilder();

            confirmation.Append("\nORDER DETAILS\n");
            confirmation.Append("=============\n");
            confirmation.Append($"Side: {orderSide}\n");
            confirmation.Append($"Symbol: {symbol}\n");
            confirmation.Append($"Order Type: {OrderTypeEnum.Limit}\n");
            confirmation.Append($"Time in force: {TimeInForceEnum.GoodTillCancel}\n");
            List <LinearRungs> linearLadder = SharedBusinessLogic.Ladder.Linear(startPrice, endPrice, ladderRungs, totalQuantity);
            int totalOrderQuantity          = 0;

            for (int rungs = 0; rungs < linearLadder.Count; rungs++)
            {
                totalOrderQuantity += linearLadder[rungs].Quantity;
                confirmation.Append($"\tRung {rungs + 1}: {linearLadder[rungs].Quantity} @ {linearLadder[rungs].Price}\n");
            }

            confirmation.Append($"TOTAL Quantity: {totalOrderQuantity}\n");

            Console.WriteLine(confirmation);
            Console.Write("\n\nDo you want to execute this order?");
            ConsoleKeyInfo confirm = Console.ReadKey();

            if (confirm.Key == ConsoleKey.Y)
            {
                _logger.LogDebug(1, confirmation.ToString());
                Console.WriteLine("PLACING ORDER......");
                foreach (OrderResBase result in from LinearRungs rung in linearLadder
                         where rung.Quantity > 0
                         let apiOrderCreate = new OrderCreate()
                                              let result = apiOrderCreate.CallApi(orderSide, symbol, OrderTypeEnum.Limit, TimeInForceEnum.GoodTillCancel, rung.Quantity, rung.Price)
                                                           select result)
                {
                    if (result.RetCode != 0)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        _logger.LogError(1, result.RetMsg);
                    }
                    else
                    {
                        _logger.LogDebug(2, result.ToJson());
                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                        Console.WriteLine($"Order submitted: {result.Result.Qty} @ {result.Result.Price}");
                        Task.Delay(1000).Wait();
                    }

                    Console.ForegroundColor = defaultConsoleForegroundColor;
                }

                Console.WriteLine("Order(s) Placed!  Good luck!");
            }
            else
            {
                Console.WriteLine("Order canceled! Good luck!");
            }
        }