예제 #1
0
        private async Task SwapUpdatedHandler(
            object sender,
            SwapEventArgs args,
            CancellationToken cancellationToken = default)
        {
            try
            {
                Log.Debug("Update swap {@swap} in db", args.Swap.Id);

                var result = await _account
                             .UpdateSwapAsync(args.Swap)
                             .ConfigureAwait(false);

                if (!result)
                {
                    Log.Error("Swap update error");
                }

                SwapUpdated?.Invoke(this, args);
            }
            catch (Exception e)
            {
                Log.Error(e, "Swap update error");
            }
        }
예제 #2
0
        private async void SwapUpdatedHandler(
            object sender,
            SwapEventArgs args)
        {
            try
            {
                Log.Debug("Update swap {@swap} in db", args.Swap.Id);

                var result = await _account
                             .UpdateSwapAsync(args.Swap)
                             .ConfigureAwait(false);

                if (!result)
                {
                    Log.Error("Swap update error");
                }

                //_account.AssetWarrantyManager.Alloc()

                SwapUpdated?.Invoke(this, args);
            }
            catch (Exception e)
            {
                Log.Error(e, "Swap update error");
            }
        }
예제 #3
0
        private async void SwapUpdatedHandler(object sender, SwapEventArgs args)
        {
            try
            {
                var result = await _account
                             .UpdateSwapAsync(args.Swap)
                             .ConfigureAwait(false);

                if (!result)
                {
                    Log.Error("Swap update error");
                }

                SwapUpdated?.Invoke(this, args);
            }
            catch (Exception e)
            {
                Log.Error(e, "Swap update error");
            }
        }
예제 #4
0
 protected void RaiseSwapUpdated(ClientSwap swap, SwapStateFlags changedFlag)
 {
     SwapUpdated?.Invoke(this, new SwapEventArgs(swap, changedFlag));
 }
예제 #5
0
        public async Task StartAsync()
        {
            Log.Information("Start terminal services");

            var configuration = Configuration.GetSection($"Services:{Account.Network}");

            // init schemes
            Schemes = new ProtoSchemes(
                currencies: Account.Currencies,
                symbols: Account.Symbols);

            // init market data repository
            MarketDataRepository = new MarketDataRepository(Account.Symbols);

            // init exchange client
            ExchangeClient                = new ExchangeWebClient(configuration, Schemes);
            ExchangeClient.Connected     += OnExchangeConnectedEventHandler;
            ExchangeClient.Disconnected  += OnExchangeDisconnectedEventHandler;
            ExchangeClient.AuthOk        += OnExchangeAuthOkEventHandler;
            ExchangeClient.AuthNonce     += OnExchangeAuthNonceEventHandler;
            ExchangeClient.Error         += OnExchangeErrorEventHandler;
            ExchangeClient.OrderReceived += OnExchangeOrderEventHandler;
            ExchangeClient.SwapReceived  += OnSwapReceivedEventHandler;

            // init market data client
            MarketDataClient                   = new MarketDataWebClient(configuration, Schemes);
            MarketDataClient.Connected        += OnMarketDataConnectedEventHandler;
            MarketDataClient.Disconnected     += OnMarketDataDisconnectedEventHandler;
            MarketDataClient.AuthOk           += OnMarketDataAuthOkEventHandler;
            MarketDataClient.AuthNonce        += OnMarketDataAuthNonceEventHandler;
            MarketDataClient.Error            += OnMarketDataErrorEventHandler;
            MarketDataClient.QuotesReceived   += OnQuotesReceivedEventHandler;
            MarketDataClient.EntriesReceived  += OnEntriesReceivedEventHandler;
            MarketDataClient.SnapshotReceived += OnSnapshotReceivedEventHandler;

            // init swap manager
            SwapManager = new ClientSwapManager(
                account: Account,
                swapClient: ExchangeClient,
                taskPerformer: TaskPerformer);
            SwapManager.SwapUpdated += (sender, args) => SwapUpdated?.Invoke(sender, args);

            // run services
            await Task.WhenAll(
                ExchangeClient.ConnectAsync(),
                MarketDataClient.ConnectAsync())
            .ConfigureAwait(false);

            // run tracker
            TaskPerformer.EnqueueTask(new BalanceUpdateTask
            {
                Account  = Account,
                Interval = TimeSpan.FromSeconds(Account.UserSettings.BalanceUpdateIntervalInSec)
            });
            TaskPerformer.Start();

            // start to track unconfirmed transactions
            await TrackUnconfirmedTransactionsAsync()
            .ConfigureAwait(false);

            // restore swaps
            SwapManager.RestoreSwapsAsync().FireAndForget();
        }
예제 #6
0
 protected Task UpdateSwapAsync(
     Swap swap,
     SwapStateFlags changedFlag,
     CancellationToken cancellationToken = default) =>
 SwapUpdated?.Invoke(this, new SwapEventArgs(swap, changedFlag), cancellationToken);