Develop Your System

This section is to discuss the key components in Cyan Spring framework and how to develop your system based on those components

Introduction

Skill requirements

Adaptor framework

Strategy framework

Tutorial

PriceInstruction Object

When you look at the single/multi instrument strategy framework. You will find no orders required to send to downstream/exchange. Because this is all wrapped in the PriceInstruction object.

PriceInstruction object contains one or multiple PriceAllocation objects

public PriceAllocation(String symbol, OrderSide side, double price,
		double qty, ExchangeOrderType orderType, String parentId)
	

Instead of making individual child order decision, In Cyan Spring ATS your strategy issues 'order instruction' at high level. A PriceInstruction with one PriceAllocation of {symbol=0005.HK, side=OrderSide.Buy, price=65.5, qty=2000, orderType=LIMIT} simply tells the framework "I want order(s) with total quantity of 2000 at exchange" rather than "I want to send an order with quantity of 2000"

This may not make a huge differenc when you are sending marketable orders. However, it makes your life a lot easier when you are dealing with non-marketable orders or passive orders. In the following example, we will see why is that.

Say initailly, your strategy sent an order of {symbol=0005.HK, side=OrderSide.Buy, price=65.5, qty=400, orderType=LIMIT} to the market, it is currently queued at order book(non-marketable order).

After that, the market moves up and your strategy decides to follow the market by moving up your order price to 65.6. What you would do traditionally is to involve in three steps

1)Cancel order:  {symbol=0005.HK, side=OrderSide.Buy, price=65.5, qty=400, orderType=LIMIT}
	
2)Wait for the cancellation is confirmed
	(important! you must wait for cancellation confirmed before sending out new order. 
	Otherwise you may result in over-execute your  order in some extreme market condition)
	
3)New order:  {symbol=0005.HK, side=OrderSide.Buy, price=65.6, qty=400, orderType=LIMIT}
	

As you can see, Your actions depends on what you have already in market and what you want to be in market. And this involves in quite a bit of mechanical calculations especially when you have lots of strategies running and you have many orders in markets.

Obviously, you do NOT want to include those mechanical calculations in your business logic every time you make a change in your strategy decision. In Cyan Spring strategy framework, you do NOT have to do this.

In the above scenario, You simply issue a new PriceInstruction which contains one PriceAllocation of {symbol=0005.HK, side=OrderSide.Buy, price=65.6, qty=500, orderType=LIMIT}, the strategy framework will take care of what's need to be canceled and what's need to be sent.

To summarise it, this is what you typically do when you are writing strategy logic in Cyan Spring ATS. Instead of thinking about what you want to send to market, you should think about you want to be TOTAL in the market, because Cyan Spring ATS will check what are already in the market and work out the individual order actions.