2

I'm looking at Chronicle and I don't understand one thing.

An example - I have a queue with one writer - market data provider writes tick data as they appear. Let's say queue has 10 readers - each reader is a different trading strategy that reads the new tick, and might send buy or sell order, let's name them Strategy1 .. Strategy10. Let's say there is a rule that I can have only one trade open at any given time.

Now the problem - as far as I understand, there is no guarantee on the order how these subscribed readers process the tick event. Each strategy is subscribed to the queue, so each of them will get the new tick asynchronously.

So when I run it for the first time, it might be that Strategy1 receives the tick first and places the order, all the other strategies will then be not able to place their orders.

If I'll replay the same sequence of events, it might be that a different strategy processes the tick first, and places its order.

This will result in totally different results while using the same sequence of initial events.

Am I understanding something wrong or is this how it really works? What are the possible solutions to this problem?

What I want to achieve is that the same sequence of source events (ticks) produces always the same sequence of trades.

Mark Fric
  • 21
  • 2

2 Answers2

1

If you want determinism in your system, then you need to remove sources of non-determinism. In your case, since you can only have a single trade open at one time, it sounds like it would be sensible to run all 10 strategies on a single thread (reader). This would also remove the need for any synchronisation on the reader side to ensure that there is only one open trade.

You can then use some fixed ordering to your strategies (e.g. round-robin) that will always produce the same output for a given set of inputs. Alternatively, if the decision logic is too expensive to run in serial, it could be executed in parallel, with each reader feeding into some form of gate (a Phaser-like structure), on which a decision about what strategy to use can be made deterministically. The drawback to this design is that the slowest trading strategy would hold back all the others.

Mark Price
  • 296
  • 1
  • 3
0

Think you need to make a choice about how much you want concurrently and independently, and how much you want in order and serial. I suggest you allow the strategies to place orders independently, however the reader of those order to process them in the original order by checking a sequence number such as the queue index in the first queue.

This way the reader of the orders will process them in the same order regardless of the order they are processed and written which appears to be your goal.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130