简体   繁体   中英

Event reentry issue. Same event running concurrently

I have a event which in many case fires many times but I want an event to be completed before the next event is ran.

I am trying to create a cryptocurrency trading bot. The event in question is private void CoinInformation_OnNewTradeEvent(object sender, AggregateTradeEventArgs e)

Since that single event fires multiple times, I always thought it would be executed in a synchronous fashion where when one event is running, the next event wont run until this is completed. I tried putting locks but realize that doesnt work.

private void CoinInformation_OnNewTradeEvent(object sender, AggregateTradeEventArgs e)
    {
        lock(myObject)
        {
            try
            {
                Decimal currentTradePrice = e.Trade.Price;

                UpdateSMA(currentTradePrice);

                TryBuy(currentTradePrice);

                TrySell(currentTradePrice);

                TryStopLoss(currentTradePrice);
            }
            catch
            {
                return;
            }


        }

    }

抱歉,我的TryBuy和TrySell似乎不同步,我没有等他们,所以有重入。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM