/// <summary> /// Initializes a new instance of the ExchangeInformationModel class. /// </summary> /// <param name="state">Possible values include: 'Initializing', /// 'Connecting', 'ReconnectingAfterError', 'Connected', /// 'ReceivingPrices', 'ExecuteOrders', 'ErrorState', 'Stopped', /// 'Stopping'</param> public ExchangeInformationModel(ExchangeState state, string name = default(string), IList <Instrument> instruments = default(IList <Instrument>)) { Name = name; Instruments = instruments; State = state; CustomInit(); }
private async Task <IExchangeEventEntity> MapToEntity(EventLog <EthPurchaseEventDTO> eventLog, ExchangeState exchangeState, string tokenAddress) { var(ethBought, tokensSold) = await ConvertEventValuesToDecimal(eventLog.Event.Eth_bought, eventLog.Event.Tokens_sold, tokenAddress); var tokenFee = tokensSold * UniswapUtils.Fee; var exchangeStateAfterEvent = new ExchangeState { EthLiquidity = exchangeState.EthLiquidity - ethBought, TokenLiquidity = exchangeState.TokenLiquidity + tokensSold }; return(await CreateEntityAsync( eventLog, ExchangeEventType.EthPurchase, exchangeState, exchangeStateAfterEvent, eventLog.Event.Buyer, ethBought, tokensSold, NoFee, tokenFee, tokenAddress)); }
private void m_rAllSetThree_Click(object sender, EventArgs e) { Dictionary <string, ExchangeState> rDataMap = new Dictionary <string, ExchangeState>(); for (int index = 0; index < this.dataGridView1.RowCount; ++index) { string szID = this.dataGridView1.Rows[index].Cells["Column1"].Value.ToString(); rSelection[index] = ExchangeState.Normal; ExchangeState eState = this.rSelection[index]; rDataMap.Add(szID, eState); } upDateTable(rDataMap); }
public async Task ProcessAsync(IEnumerable <IEventLog> events) { var groupedByExchangeEvents = events.GroupBy(x => x.Log.Address); foreach (var exchangeEvents in groupedByExchangeEvents) { var groupedAndOrderedByBlockNumberEvents = exchangeEvents.GroupBy(x => x.Log.BlockNumber).OrderBy(x => x.Key.Value); foreach (var orderedBlockEvents in groupedAndOrderedByBlockNumberEvents) { var previousBlockNumber = (ulong)orderedBlockEvents.Key.Value - 1; var tokenAddress = await _exchangeGatewayFactory(exchangeEvents.Key).GetTokenAddressAsync(); var exchangeState = new ExchangeState() { EthLiquidity = await _ethLiquidityProvider.GetAsync(exchangeEvents.Key, previousBlockNumber), TokenLiquidity = await _tokenLiquidityProvider.GetAsync(tokenAddress, exchangeEvents.Key, previousBlockNumber) }; foreach (var eventLog in orderedBlockEvents) { var entity = await _exchangeEventMapper.MapAsync(eventLog, exchangeState, tokenAddress); exchangeState.Update(entity); var totalSupply = await _exchangeTotalSupplyProvider.GetAsync(entity.ExchangeAddress); await _exchangeRepository.Update(entity.ExchangeAddress, entity.EthLiquidityAfterEvent, entity.TokenLiquidityAfterEvent, totalSupply); await _exchangeEventsRepository.AddOrUpdateAsync(entity); _logger.LogInformation("Event txHash {txHash} logIndex {logIndex} was processed", eventLog.Log.TransactionHash, eventLog.Log.LogIndex.Value); _logger.LogInformation("Updated state: {state}", ObjectDumper.Dump(exchangeState)); } } } }
private async Task <IExchangeEventEntity> CreateEntityAsync( IEventLog eventLog, ExchangeEventType eventType, ExchangeState beforeState, ExchangeState afterState, string callerAddress, decimal ethAmount, decimal tokenAmount, decimal ethFee, decimal tokenFee, string tokenAddress) { var blockNumber = (ulong)eventLog.Log.BlockNumber.Value; var blockTimestamp = await _blockTimestampProvider.GetByBlockNumberAsync(blockNumber); var exchangeAddress = eventLog.Log.Address; var callerBalance = await _exchangeGatewayFactory(exchangeAddress).GetBalanceOfAsync(callerAddress, blockNumber); var tokenInfo = await _tokenInfoProvider.GetAsync(tokenAddress); return(_exchangeEventEntityFactory.Create( $"{eventLog.Log.TransactionHash}_{eventLog.Log.LogIndex.Value}", exchangeAddress, callerAddress, eventType, ethAmount, tokenAmount, beforeState.EthLiquidity, afterState.EthLiquidity, beforeState.TokenLiquidity, afterState.TokenLiquidity, eventLog.Log.TransactionHash, (int)eventLog.Log.LogIndex.Value, blockTimestamp, ethFee, tokenFee, tokenAddress, blockNumber, callerBalance.ToDecimal(tokenInfo.Decimals))); }
public Task <IExchangeEventEntity> MapAsync(IEventLog eventLog, ExchangeState exchangeState, string tokenAddress) { switch (eventLog) { case EventLog <TokenPurchaseEventDTO> log: return(MapToEntity(log, exchangeState, tokenAddress)); case EventLog <EthPurchaseEventDTO> log: return(MapToEntity(log, exchangeState, tokenAddress)); case EventLog <AddLiquidityEventDTO> log: return(MapToEntity(log, exchangeState, tokenAddress)); case EventLog <RemoveLiquidityEventDTO> log: return(MapToEntity(log, exchangeState, tokenAddress)); default: throw new ArgumentException("Invalid event log type", nameof(eventLog)); } }
private async Task <IExchangeEventEntity> MapToEntity(EventLog <RemoveLiquidityEventDTO> eventLog, ExchangeState exchangeState, string tokenAddress) { var(ethAmount, tokenAmount) = await ConvertEventValuesToDecimal(eventLog.Event.Eth_amount, eventLog.Event.Token_amount, tokenAddress); var exchangeStateAfterEvent = new ExchangeState { EthLiquidity = exchangeState.EthLiquidity - ethAmount, TokenLiquidity = exchangeState.TokenLiquidity - tokenAmount }; return(await CreateEntityAsync( eventLog, ExchangeEventType.RemoveLiquidity, exchangeState, exchangeStateAfterEvent, eventLog.Event.Provider, ethAmount, tokenAmount, NoFee, NoFee, tokenAddress)); }
private void m_rChangeNode_Click(object sender, EventArgs e) { Dictionary <string, ExchangeState> rDataMap = new Dictionary <string, ExchangeState>(); for (int index = 0; index < this.dataGridView1.RowCount; ++index) { string szID = this.dataGridView1.Rows[index].Cells["Column1"].Value.ToString(); ExchangeState eState = this.rSelection[index]; rDataMap.Add(szID, eState); } getSaveAsPath rGetPathFunc = new getSaveAsPath(() => { if (this.m_rSaveAsDialog.ShowDialog() == DialogResult.OK) { return(m_rSaveAsDialog.FileName); } else { return(string.Empty); } }); this.m_rSaleChange.alterData(rDataMap, rGetPathFunc); }