Closed Hulkstance closed 3 years ago
You'll need to keep the business logic and the data handler separate. You're currently doing all sort of checks and calls within the event handler of the websocket. Doing this will lead to data being received out of date, because new data can only be processed once the event handler for the previous has been completed.
I'd recommend adding the received data to some sort of queue, then have a separate thread/task process the data from that queue.
Instead a queue with a loop around i would highly recommend using Tasks and switch to Event-Driven actions .. just my 2 cents :)
You'll need to keep the business logic and the data handler separate. You're currently doing all sort of checks and calls within the event handler of the websocket. Doing this will lead to data being received out of date, because new data can only be processed once the event handler for the previous has been completed.
I'd recommend adding the received data to some sort of queue, then have a separate thread/task process the data from that queue.
Hi @JKorf I am implement a algotrading bot too and I am using event handler like this. How to check current price for every tick without using event handler of the websocket? If I use a queue and prices pile up in the queue, Won't this cause delay?
@Amannda123, do you mean the Event-Driven actions used in the microservices architecture? For example: RabbitMQ. https://docs.microsoft.com/en-us/dotnet/architecture/microservices/multi-container-microservice-net-applications/rabbitmq-event-bus-development-test-environment. How do I actually benefit from it?
I was going to implement a trailing stop-loss orders but there is something that worries me. Right now, the code watches for placed StopLossLimit orders, cancels them and places new ones with the updated prices. The whole procedure is performed on
if (!data.Final)
, which means on each price change. What if the price changes so fast? It probably won't catch up. What could you recommend me? Most of you have probably implemented it, since it's useful.