Exemplo n.º 1
0
        static async Task Main()
        {
            var container      = new UnityContainer();
            var unityContainer = new DependencyInjectionContainer(container);

            container.RegisterType <KuCoinKeyAndSecret>(new ContainerControlledLifetimeManager());
            container.RegisterFactory <IFileRepositoryConfig>(t => t.Resolve <KuCoinKeyAndSecret>());

            var accountFileRepository = unityContainer.Get <AccountFileRepository>();

            Console.WriteLine($"Starts KuCoin Extract for account {accountFileRepository.Account}");
            var kuCoinEndPoints = unityContainer.Get <KuCoinEndPoints>();

            var trades = await kuCoinEndPoints.GetAllTrades(new DateTime(2020, 01, 01));

            accountFileRepository.Save(trades);

            var deposits = await kuCoinEndPoints.GetDeposit();

            accountFileRepository.Save(deposits);

            var withdrawals = await kuCoinEndPoints.GetWithdrawals();

            accountFileRepository.Save(withdrawals);

            var balances = await kuCoinEndPoints.GetBalances();

            accountFileRepository.Save(balances.ToImmutableArray());
        }
Exemplo n.º 2
0
        public static async Task Main()
        {
            var container      = new UnityContainer();
            var unityContainer = new DependencyInjectionContainer(container);

            container.RegisterType <BinanceKeyAndSecret>(new ContainerControlledLifetimeManager());
            container.RegisterFactory <IFileRepositoryConfig>(t => t.Resolve <BinanceKeyAndSecret>());

            var fileRepository = unityContainer.Get <AccountFileRepository>();

            Console.WriteLine($"Starts {DateTime.Now:HH:mm:ss tt zz} - {fileRepository.Account}");
            var tradingRules = await unityContainer.Get <TradingRulesEndPoint>().GetTradingRules();

            var symbols = tradingRules.Symbols.Select(t => t.SymbolName)
                          .OrderBy(t => t)
                          .ToArray();

            var allMyTradesEndPoint = unityContainer.Get <AllMyTradesEndPoint>();

            var allTradesSet = symbols.Tag(allMyTradesEndPoint.GetAllTrades);

            using (StreamWriter file = fileRepository.GetTradesStreamWriter())
            {
                int i = 0;
                int j = 0;

                foreach (var allTrades in allTradesSet)
                {
                    var trades = await allTrades.tag.ToList().FirstAsync();

                    foreach (var tradeSet in trades)
                    {
                        foreach (var trade in tradeSet)
                        {
                            if (trade == null)
                            {
                                throw new ArgumentException();
                            }

                            var tradeString = JsonConvert.SerializeObject(trade);
                            file.WriteLine(tradeString);
                            i++;
                        }
                    }

                    j++;
                    Console.WriteLine($"{DateTime.Now:HH:mm:ss tt zz} - {j}/{symbols.Length} - {allTrades.value}: {trades.Sum(t => t.Count):N0} trade(s) - Total {i:N0}");
                }

                Console.WriteLine($"Finished {DateTime.Now:HH:mm:ss tt zz} - {i:N0} trades");
            }
        }
Exemplo n.º 3
0
        static async Task Main(string[] args)
        {
            var container      = new UnityContainer();
            var unityContainer = new DependencyInjectionContainer(container);

            container.RegisterType <BinanceKeyAndSecret>(new ContainerControlledLifetimeManager());
            container.RegisterFactory <IFileRepositoryConfig>(t => t.Resolve <BinanceKeyAndSecret>());

            var depositHistoryEndPoint = unityContainer.Get <DepositHistoryEndPoint>();
            var fileRepository         = unityContainer.Get <AccountFileRepository>();

            Console.WriteLine($"Starts {DateTime.Now:HH:mm:ss tt zz} - {fileRepository.Account}");

            Console.WriteLine("Saving AccountInfo");

            var accountInfo = await unityContainer.Get <AccountInfoEndPoint>().GetAccountInfo();

            fileRepository.SaveAccountInfo(accountInfo);

            Console.WriteLine("Saving Withdraw");

            var withdrawHistory = await depositHistoryEndPoint.GetWithdrawHistory(new DateTime(2017, 01, 01));

            fileRepository.SaveWithdraws(withdrawHistory);

            Console.WriteLine("Saving Deposit");

            var depositHistory = await depositHistoryEndPoint.GetDepositHistory(new DateTime(2017, 01, 01));

            fileRepository.SaveDeposits(depositHistory);

            Console.WriteLine("Saving Dividend");

            var dividendHistory = await depositHistoryEndPoint.GetDividendHistory(new DateTime(2017, 01, 01));

            fileRepository.SaveDividends(dividendHistory);

            Console.WriteLine("Saving Dust");

            var dustHistory = await depositHistoryEndPoint.GetDustHistory();

            fileRepository.SaveDusts(dustHistory);
        }
        public T GetService <T>(Type serviceType) where T : class
        {
            T t = _ServiceCollection.BuildServiceProvider().GetRequiredService(typeof(T)) as T;

            if (t != null) //the build in dependecy injection container
            {
                return(t);
            }
            else //Check in the dependency injection container
            {
                return(_DependencyInjectionContainer.Get(serviceType) as T);
            }
        }
Exemplo n.º 5
0
        static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += LogUnhandledException;
            Log.Debug("Initialise DependencyInjection");
            var container = DependencyInjectionContainer.Get();

            using (container.BeginScope())
            {
                var game = container.GetInstance <UnknownProjectGame>();
                Log.Debug("Starting UnknownProjectGame");
                game.Run();
            }
        }
Exemplo n.º 6
0
        internal static T GetPlugin <T>(string key, DependencyInjectionContainer dependencyInjectionContainer, KraftModuleConfigurationSettings kraftConfigurationSettings, ELoaderType pluginType, bool isIterator = false) where T : class
        {
            LoaderProperties loaderProperties = GetLoaderProperties(key, kraftConfigurationSettings, pluginType, isIterator);

            return(dependencyInjectionContainer.Get(loaderProperties.InterfaceAsType, kraftConfigurationSettings.ModuleName + loaderProperties.ImplementationAsString) as T);
        }
Exemplo n.º 7
0
        static void Main()
        {
            //create readme
            Console.WriteLine($"Starts {DateTime.Now:HH:mm:ss tt zz} - Capital gain calculation for tax purpose");
            var unityContainer = new UnityContainer();
            var dependencyInjectionContainer = new DependencyInjectionContainer(unityContainer);

            unityContainer.RegisterInstance(JsonConvert.DeserializeObject <Config>(File.ReadAllText(@".\Config.json")));
            unityContainer.RegisterFactory <ICurrentFiatConfig>(t => t.Resolve <Config>());
            unityContainer.RegisterFactory <ILocalDataRetrieverCompositeConfig>(t => t.Resolve <Config>());
            unityContainer.RegisterFactory <IPortfolioAcrossTimeConfig>(t => t.Resolve <Config>());
            unityContainer.RegisterFactory <ITaxMethodologyConfig>(t => t.Resolve <Config>());

            unityContainer.RegisterType <LocalDataRetrieverComposite>(new ContainerControlledLifetimeManager());
            unityContainer.RegisterType <CapitalGainReportSaver>(new ContainerControlledLifetimeManager());
            unityContainer.RegisterType <LoggerFactory>(new ContainerControlledLifetimeManager());

            unityContainer.RegisterInstance <Func <LocalDataRetrieverComposite.ManuallySetFileRepositoryConfig, AccountFileRepository> >(t =>
                                                                                                                                         unityContainer.Resolve <AccountFileRepository>(new DependencyOverride <IFileRepositoryConfig>(t)));

            dependencyInjectionContainer.Get <EndOfFinancialYearPortfolioLogger>();
            var currentFiat        = dependencyInjectionContainer.Get <CurrentFiat>();
            var localDataRetriever = dependencyInjectionContainer.Get <LocalDataRetrieverComposite>();

            Console.WriteLine($"Accounts {localDataRetriever.Account}");
            Console.WriteLine($"Currency {currentFiat.Name}, {dependencyInjectionContainer.Get<TaxMethodology>()}");

            var portfolioAcrossTime = dependencyInjectionContainer.Get <PortfolioAcrossTime>();

            portfolioAcrossTime.Run();

            var capitalGains = portfolioAcrossTime.GetCapitalGains();

            dependencyInjectionContainer.Get <CapitalGainPlotter>().Log(capitalGains);
            dependencyInjectionContainer.Get <BalanceDifferencesPortfolioLogger>().LogDifferences();
            dependencyInjectionContainer.Get <PortfolioBreachesLogger>().Log();
            var financialYearLogger = dependencyInjectionContainer.Get <TaxReportLogger>();
            var totalCapitalGain    = financialYearLogger.Log(capitalGains);

            dependencyInjectionContainer.Get <CapitalGainPerCategoryLogger>().Log(capitalGains);
            dependencyInjectionContainer.Get <CapitalGainPerAssetLogger>().Log(capitalGains);
            dependencyInjectionContainer.Get <InputOutputLogger>().Log();
            dependencyInjectionContainer.Get <OffExchangeAssetPortfolioLogger>().Log();
            var totalUnrealized = dependencyInjectionContainer.Get <UnrealizedCapitalGainLogger>().Log();

            financialYearLogger.LogLine($"\nUnrealized {totalUnrealized:N2} {currentFiat.Name}");
            financialYearLogger.LogLine($"\nCapital Gain + unrealized {totalCapitalGain + totalUnrealized:N2} {currentFiat.Name}");
        }
Exemplo n.º 8
0
        static async Task Main(string[] args)
        {
            var container      = new UnityContainer();
            var unityContainer = new DependencyInjectionContainer(container);

            container.RegisterType <BinanceKeyAndSecret>(new ContainerControlledLifetimeManager());
            container.RegisterFactory <IFileRepositoryConfig>(t => t.Resolve <BinanceKeyAndSecret>());

            Console.WriteLine($"Starts {DateTime.Now:HH:mm:ss tt zz}");
            Console.WriteLine("This Extract is only needed once. Its data will be used by all accounts.");

            var fileRepository = unityContainer.Get <AccountFileRepository>();

            Console.WriteLine("Saving Trading Rules");

            var tradingRules = await unityContainer.Get <TradingRulesEndPoint>().GetTradingRules();

            fileRepository.SaveTradingRules(tradingRules);

            Console.WriteLine("Saving Histo prices");
            var ccyPairs = tradingRules.Symbols
                           .Where(t => t.QuoteAsset == "USDT" || t.BaseAsset == "USDT" || t.QuoteAsset == "BTC" || t.BaseAsset == "BTC" || t.QuoteAsset == "BUSD" || t.BaseAsset == "BUSD")
                           .ToArray();

            var candleStickEndpoint = unityContainer.Get <CandlesticksEndPoint>();

            await using StreamWriter file = fileRepository.GetHistoPricesStreamWriter();
            var i = 0;

            foreach (var ccyPair in ccyPairs)
            {
                var candles = await candleStickEndpoint.GetCandlesticks(ccyPair.SymbolName, TimeInterval.Days_1, limit : 1000);

                foreach (var candlestick in candles)
                {
                    var openTime  = candlestick.OpenTimeTimeReadable.Date;
                    var closeDate = candlestick.CloseTimeReadable.Date;

                    if (openTime != closeDate)
                    {
                        Console.WriteLine($"Candle not valid for {ccyPair.SymbolName}");
                        continue;
                    }

                    var usdtPrice = new HistoSymbolPrice
                    {
                        Base   = ccyPair.BaseAsset,
                        Quote  = ccyPair.QuoteAsset,
                        Date   = closeDate.ToUnixDateTime(),
                        Symbol = ccyPair.SymbolName,
                        Price  = candlestick.Close
                    };
                    var serializeObject = JsonConvert.SerializeObject(usdtPrice);
                    file.WriteLine(serializeObject);
                }

                i++;

                if (i % 20 == 0)
                {
                    Console.WriteLine($"Saved {i}/{ccyPairs.Length}");
                }
            }

            Console.WriteLine($"Saved {i}/{ccyPairs.Length}");
        }