Algorithm scripting
Concepts
The simulation algorithms are written in JavaScript, using a number of predefined objects to represent those things of concern
when executing orders: the limit order book, the original discretionary order and so on. Order handling is often a
combination of situational rules and process, a combination which favours a programming paradigm. In this simulation
the scripts are written as a single function. A more substantial implementation would relax this constraint.
Predefined variables
Variable name | | Property or method | | Description
|
---|
log
|
| info(string)
|
| Display the string on the web page.
|
order
|
| direction
|
| The direction, +1 for buying, -1 for selling.
|
|
| limit
|
| The limit price.
|
|
| reference
|
| The order reference.
|
|
| open()
|
| Returns the current open (unfilled) quantity.
|
state
|
| (none)
|
| JavaScript allows scripts to add and reference properties dynamically, so this state
object allows a script to persist information between calls.
|
symbol
|
| ticksize
|
| The size of the price tick.
|
|
| orderbook
|
| The OrderBook object.
|
Objects
Object name | | Property or method | | Description
|
---|
Level
|
| orders
|
| The number of orders at this price level.
|
|
| price
|
| The price level.
|
|
| quantity
|
| The total quantity of limit orders at this price level.
|
LimitOrder
|
| direction
|
| The direction, +1 for a bid, -1 for an ask.
|
|
| price
|
| The price.
|
|
| quantity
|
| The quantity.
|
|
| add()
|
| Adds this limit order to the limit order book.
|
|
| amend()
|
| Amends this limit order on the limit order book.
|
|
| cancel()
|
| Cancels and removes this limit order from the limit order book.
|
MarketOrder
|
| direction
|
| The direction, +1 for buying, -1 for selling.
|
|
| quantity
|
| The quantity.
|
|
| add()
|
| Adds this limit order to the limit order book.
|
OrderBook
|
| askLevels() .
|
| Returns an array of Level objects, one for each ask price level in the book.
|
|
| asks()
|
| Returns an array of LimitOrder objects, one for each ask on the book.
|
|
| bestAsk()
|
| Returns the LimitOrder object for the best ask.
|
|
| bestBid()
|
| Returns the LimitOrder object for the best bid.
|
|
| bidLevels()
|
| Returns an array of Level objects, one for each ask price level in the book.
|
|
| bids()
|
| Returns an array of LimitOrder objects, one for each bid on the book.
|
|
| ownAsks()
|
| Returns an array of LimitOrder objects, one for each ask submitted by the algorithm.
|
|
| ownBids()
|
| Returns an array of LimitOrder objects, one for each bid submitted by the algorithm.
|
|
| volume()
|
| Returns the cumulative traded volume on the book.
|
|
| vwap()
|
| Returns the volume weighted average price of all trades on the book.
|