-
Notifications
You must be signed in to change notification settings - Fork 60
Instantiating and Input
Ash Booth edited this page Apr 1, 2016
·
3 revisions
A limit order book object is created very simply as follows:
from PyLOB import OrderBook
# create a LOB object
lob = OrderBook()
Notable functions and their use are shown below:
lob.processOrder(quote, verbose)
lob.cancelOrder(side, idNum)
lob.modifyOrder(idNum, order_update)
lob.getVolumeAtPrice(side, price)
lob.getBestBid()
lob.getBestAsk()
Usage guides for each of these functions are included later in the wiki. The state of the LOB can be checked visually at any time with a simple print command:
print lob
yielding...
------ Bids -------
5 @ 99.0000 t=5
5 @ 99.0000 t=7
5 @ 98.0000 t=6
5 @ 97.0000 t=8
------ Asks -------
3 @ 101.0000 t=1
5 @ 101.0000 t=3
5 @ 101.0000 t=4
5 @ 103.0000 t=2
------ Trades ------
2 @ 101.0 (9)
Orders are sent to the LOB in the form of dictionaries and using the processOrder()
function. The required structures for the order dictionaries are shown below:
# For a limit order
quote = {'type' : 'limit',
'side' : 'bid',
'qty' : 6,
'price' : 108.2,
'tid' : 001}
# and for a market order:
quote = {'type' : 'market',
'side' : 'ask',
'qty' : 6,
'tid' : 002}
"side" specifies whether we are placing a bid or an ask while "tid" is a unique trader identification number which you must specify for each simulated trader.
The process of submitting limit orders and market orders are the subjects of the next two wikis.