Manual
Manual
Ivan E. Perez
March 8, 2021
v1.0.2
Contents
1 Introduction 2
2 crobat Features 3
2.1 Orderbook updating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
5 Usage 9
6 Modules 11
6.1 recorder full . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
6.1.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
6.1.2 class L2 Update . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
6.2 LOB funcs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6.2.1 Description: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6.2.2 class history() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6.3 history funcs.py . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
7 Credits 39
7.1 Development Lead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
7.2 Contributors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
8 License 40
9 Appendix 41
10 To do list 41
1
1 INTRODUCTION 2
1 Introduction
This project is an extension of my thesis, A Study of CUSUM Statistics on Bitcoin Transactions, where
I was tasked with implementing CUSUM statistic processes to identify price actions periods in bitcoin
markets. After developing a tool for market orders, the natural extension was to find relationships from
activities in the limit order book. I started developing this tool to record instances of the limit order
book in order to record Limit Order insertions (LO), cancellations (CO), and Market Orders (MO).
As the project grew I wanted to make a tool that could be used by academics looking to apply and
develop market microstructure models in live markets. As a result, the styles in which the limit order
book and order book events are recorded are being developed in accordance to the conventions presented
in recent market microstructure papers correspond to the following papers:
1. Huang W., Lehalle C.A. and Rosenbaum M. - Simulating and analyzing order book data:The
queue-reactive model[1]
2. Cont R., Stoikov S. and Talreja R. - A stochastic model for order book dynamics[5]
3. Cont R., Kukanov A. and Stoikov S. - The price impact of order book events[4]
4. Cartea. A, Jaimungal S. and Wang Y. - Spoofing and Price Manipulation in Order Driven
Markets[2]
5. Silyantev, E. - Order flow analysis of cryptocurrency markets[6]1
1 This paper shows a working model implementing Order Flow Imbalance (OFI) and Trade Flow Imbalance(TFI) to
BTC-USD trades was done by Ed Silyantev. He developed a tool to assess OFI and TFI of XBT-USD pair.
2 CROBAT FEATURES 3
2 crobat Features
2.1 Orderbook updating
Order book recording module that maintains a time-series of:
3. When you are ready, you can start the build. When it finishes you should get a message Connection
Closed from CoPrA. And the files for the limit order book for each side should be created with a
timestamp in the form YYYY-MM-DDTHH:MM:SS.ffffff. Currently it will output everything given in
the table below, but I will update the function to only output select things for people.
Filename side Time Series Description
L2 orderbook events ask+timestamp ask Order book events on the ask side
L2 orderbook events bid+timestamp bid Order book events on the bid side
L2 orderbook events signed+timestamp both Order book events on both sides,
- sign for bid, +sign for ask
L2 orderbook ask volm+timestamp ask Volume snapshots of order book on the ask side
L2 orderbook bid volm+timestamp bid Volume snapshots of order book on the bid side
L2 orderbook signed volm+timestamp both Volume snapshots of the signed order book,
- sign for bid, + sign for ask
L2 orderbook ask volm+timestamp ask Price snapshots of order book on the ask side
L2 orderbook bid volm+timestamp bid Price snapshots of order book on the bid side
L2 orderbook signed volm+timestamp both Price snapshots of the signed order book,
- sign for bid, +sign for ask
Event recording are a time series of MO, LO, CO’s as afforded from the l2 update messages which
are used to update the price, volume pair size at each price level. The format of the Event recorder is as
follows:
Item Description/Format
Timestamp YYYY-MM-DDTHH:MM:SS.ffffff
−n price quote at the nth best bid (i.e., worst bid)
−n + 1 aggregate XTC limit buys at the second to worst bid
... ...
−2 aggregate XTC being bid for at the 2nd best bid
−1 aggregate XTC limit being bid for at the best bed bid
1 aggregate XTC offered at the best ask
2 aggregate XTC offered at the 2nd best ask
... ...
n−1 aggregate XTC offered at the second worst ask
n aggregate XTC offered at the worst ask
Similar to the single side implementation, there is an associated price quote (e.g., USD per XTC)
snapshot generated at each timepoint. The default format is given below:
Item Description/Format
Timestamp YYYY-MM-DDTHH:MM:SS.ffffff
−n price quote at the nth best bid (i.e., worst bid)
−n + 1 price quote at the second to worst bid
... ...
−2 price quote at the 2nd best bid
−1 price quote at the best bed bid
1 price quote at the best ask
2 price quote at the 2nd best ask
... ...
n−1 price quote at the second worst ask
n price quote at the worst ask
Start
5 USAGE 9
5 Usage
Preface: crobat is used with an open websocket connection to the Coinbase exchange. It uses CoPrA
to parse JSON objects, and it records time series arrays of order book snapshots and events.
If we were to execute the code, we would run methods in the instance of the class Client based
on the arrival of messages on the heartbeat channel for the pair BTC-USD. crobat primarily inherits
methods from this class and adds logic for managing incoming messages. Below we introduce our own
version of this loop found in CSV out.py.
1 import recorder_full as rec
2 import asyncio , time
3 from datetime import datetime
4 import copra . rest
5 from copra . websocket import Channel , Client
6
7 class input_args ( object ) :
8 def __init__ ( self , currency_pair = ’ETH - USD ’ , positi on_rang e =5 , r e c o r d i n g _ d u r a t i o n =5) :
9 self . currency_pair = currency_pair
10 self . pos ition_r ange = p osition _range
11 self . r e c o r d i n g _ d u r a t i o n = r e c o r d i n g _ d u r a t i o n
12
13 def main () :
14 settings_1 = input_args ()
15
16 loop = asyncio . get_e vent_lo op ()
17
18 channel1 = Channel ( ’ level2 ’ , settings_1 . currency_pair )
19 channel2 = Channel ( ’ ticker ’ , settings_1 . currency_pair )
20
21 ws_1 = rec . L2_Update ( loop , channel1 , settings_1 )
22 ws_1 . subscribe ( channel2 )
23
24 timestart = datetime . utcnow ()
25
26 try :
27 loop . run_forever ()
28 except K e y b o a r d I n t e r r u p t :
29 loop . r u n _ u n t i l _ c o m p l e t e ( ws_1 . close () )
30 loop . close ()
31
32 if __name__ == ’ __main__ ’:
33 main ()
In this modified event loop we have the context where the bulk of crobat sits, the class l2 update.
we can the loop object that is passed to ws 1, the instance of the class L2 Update, receives msg objects
through the async methods inherited from Client. Here we give an example of what l2 Update looks
like:
5 USAGE 10
Here we can see that we can create an instance of this class, and on its initialization we create arrays
that can hold our changes and order book states. The logic tree for when each type of message arrives
can dictate what kinds of records, and changes to the snapshot are made the arrival of a message. In
this current version, the history module contains methods to both update the order book and record
changes, but in future versions the processes should be separated as other may have better ideas as to
what to do with order book changes. In the following section we will introduce the modules and their
associated functions and classes.
6 MODULES 11
6 Modules
Introduction: corbat has one main module, recorder full typically imported as rec. Its dependencies
are:
1. asyncio, time for asynchronous methods,
2. datetime, to work with datetime objects,
3. copra.websocket, to connect to coinbase,
4. pandas, to store out time series arrays,
5. LOB funcs.py, to manage messages and create time series arrays,
6. history funcs.py, for some helper functions, and
7. gc and numpy.
The modules, and their dependencies are listed in the tree diagram below.
and gc.collect() to clear memory after storing .xlsx files of the processed data.
restated from CoPrA:
on close is called whenever the connection between the client and server is closed. was clean is a
boolean indicating whether or not the connection was cleanly closed. code, an integer, and reason, a
string, are sent by the end that initiated closing the connection.
If the client did not initiate this closure and client.auto reconnect is set to True, the client will attempt
to reconnect to the server and resubscribe to the channels it was subscribed to when the connection was
closed. This method also logs the closure.
If your subclass overrides this method, it is important that the subclass method calls the parent
method if you want to preserve the auto reconnect functionality. This can be done by including
super().on close(was clean, code, reason) in your subclass method.
parameters: was clean: bool
code: int or None
reason: str or None
returns: None: None
52 # Needs an Example
Listing 1: Python example
6 MODULES 16
hf.min dec
parameters: msg: dict
time datetime object
returns: None: None
Example:
53 # let the instance of our L2_Update class be defined as follows :
54 channel1 = Channel ( ’ level2 ’ , ’BTC - USD ’)
55 ws_1 = L2_Update ( loop , channel1 , settings_1 )
56
57 # from our __init__ method , we initialized the arrays in history :
58 >> print ( vars ( ws_1 . hist ) )
59 > >{ bid_history :[] , ask_history :[] , s igned_h istory :[] , snpashot_bid :[] , snapshot_ask :[] ,
s na ps ho t _s ig ne d :[] , bid_events :[] , ask_events :[] , signed_events :[] , order_type : None ,
token : False , position :0 , event_size :0}
60
61 # after receiving the snapshot from our event loop we will run i n i t i a l i z e _ s n a p _ e v e n t s
62 # to populate the variables created in __init__ .
63
64 # Let our message be
65 ws_1 . time_now = " 2019 -08 -14 T20 :42:27.265 Z "
66 msg = {
67 " type " : " snapshot " ,
68 " product_id " : " BTC - USD " ,
69 " bids " : [[ " 10101.10 " , " 0.450541 " ] ,[ " 10101.20 " , " 0.44100 " ] , [ " 10101.55 " , " 0.013400 " ]] ,
70 " asks " : [[ " 10102.55 " , " 0.577535 " ] ,[ " 10102.58 " , " 0.63219 " ] , [ " 10102.60 " , " 0.803200 " ]]
71 }
72
73 # note there is not a timestamp for the snapshot that we receive from coinbase so it is
passed from the datetime . utcnow () from the init method of the L2_Update class .
74
75 ws_1 . hist . i n i t i a l i z e _ s n a p e v e n t s ( msg , ws_1 . time_now )
76
77 >> print ( vars ( ws_1 . hist ) )
78 > >{ bid_history :[[2019 -08 -14 T20 :42:27.265 Z , [[10101.10 , 0.450541] , [10101.20 , 0.44100] ,
[10101.55 , 0.013400]]]] ,
79 ask_history :[[2019 -08 -14 T20 :42:27.265 Z , [[10102.55 , 0.577535] , [10102.58 , 0.63219] ,
[10102.60 , 0.803200]]]] ,
80 sign ed_histo ry :[2019 -08 -14 T20 :42:27.265 Z , [[[10101.10 , -0.450541] , [10101.20 ,
-0.44100] , [10101.55 , -0.013400] , [10102.55 , 0.577535] , [10102.58 , 0.63219] ,
[10102.60 , 0.803200]]]] ,
81 snapshot_bid :[[10101.10 , 0.450541] ,[10101.20 , 0.44100] , [10101.55 , 0.013400]] ,
82 snapshot_ask :[[10102.55 , 0.577535] ,[10102.58 , 0.63219] , [10102.60 , 0.803200]] ,
83 s na ps ho t _s ig ne d :[[10101.10 , -0.450541] ,[10101.20 , -0.44100] , [10101.55 , -0.013400] ,
[10102.55 , 0.577535] ,[10102.58 , 0.63219] , [10102.60 , 0.803200]] ,
84 bid_events :[] , ask_events :[] , signed_events :[] , order_type : None , token : False , position
:0 , event_size :0}
3 For example if BTC-USD = 10101 USD/BTC, then min dec would return the number of BTC needed for 0.01 USD in
BTC and np.round truncates the volume returns to the decimal places returned by hf.min dec. Doing so resolves the issue
with artifacts from floating point arithmetic.
6 MODULES 18
6.2.2.4 function remove price level(snap array, level depth, match index)
Description: Checks the level depth of an l2 update message, removes the existing price level from
the snapshot array if the level depth is 0. Counts as a change to the limit order book therefore self.token
is set to True.
parameters: snap array array
level depth float64
match index int
returns: snap array: array
Example:
1 # let our snapshot_bid be :
2 snapshot_bid = [[10101.80 , 0.013400] ,[10101.20 , 0.44100] , [10101.10 , 0.450541]]
3
4 # we receive a ’ l2update ’ message from our event loop
5
6 msg = {
7 " type " : " l2update " ,
8 " product_id " : " BTC - USD " ,
9 " time " : " 2019 -08 -14 T20 :42:27.265 Z " ,
10 " changes " : [
11 [
12 " buy " ,
13 " 10 101.8000 0000 " ,
14 " 0.0 "
15 ]
16 ]
17 }
18
19 # on_message () conventiently parses the message to create relevant local variables
20 # time , changes , side , price_level , level_depth , pre_level_depth , hist . token
21 >> print ( time , side , price_level , level_depth , prelevel_depth , hist . token )
22 > >2019 -08 -14 T20 :42:27.265 Z " buy " 10101. 80000000 0.0 0 False
23
24 # in on_message () , the variable p r i c e _ m a t c h _ i n d e x is assigned by finding the index
25 # with the matching price , in the snapshot . In this case :
26 p r i c e _ m a t c h _ i n d e x = [0]
27
28 snapshot_bid = r e m o v e _ p r i c e _ l e v e l ( snapshot_bid , level_depth , p r i c e _ m a t c h _ i n d e x )
29
30 >> print ( snapshot_bid , hist . token )
31 > >[[10101.20 , 0.44100] , [10101.10 , 0.450541]] True
6 MODULES 21
6.2.2.5 function update level depth(snap array, level depth, match index, pre level depth)
Descirption: updates the existing price level to a new size. Sets self.order type to insertion if
the new size is larger than the old size, or cancellation if the new size is smaller than the old size. sets
the position to the self.position variable to the index where the event occurred.
parameters: snap array: list
The snapshot array that will be modified.
level depth: float64
The new level depth that will be checked against the old level
depth in the snapshot array.
match index: list
single item list that contains the index where the price in the
snapshot array matches that of the l2update message.
returns: snap array : list
The modified snapshot array.
pre level depth: float64
An updated pre level depth4
Example:
1 # let our snapshot_bid be :
2 snapshot_bid = [[10101.80 , 0.013400] ,[10101.20 , 0.44100] , [10101.10 , 0.450541]]
3
4 # we receive a ’ l2update ’ message from our event loop
5
6 msg = {
7 " type " : " l2update " ,
8 " product_id " : " BTC - USD " ,
9 " time " : " 2019 -08 -14 T20 :42:27.265 Z " ,
10 " changes " : [
11 [
12 " buy " ,
13 " 10 101.8000 0000 " ,
14 " 0.500000 "
15 ]
16 ]
17 }
18
19 # on_message () conventiently parses the message to create relevant local variables
20 # time , changes , side , price_level , level_depth , pre_level_depth , hist . token
21 >> print ( time , side , price_level , level_depth , prelevel_depth , hist . token )
22 > >2019 -08 -14 T20 :42:27.265 Z " buy " 10101. 80000000 0.500000 0 False
23
24 # in on_message () , the variable p r i c e _ m a t c h _ i n d e x is assigned by finding the index
25 # with the matching price , in the snapshot . In this case :
26 p r i c e _ m a t c h _ i n d e x = [0]
27
28 snapshot_bid , pr e _l ev el _ de pt h = u p d a t e d a t e _ p r i c e _ l e v e l ( snapshot_bid , level_depth ,
price_match_index , pr e _l ev el _ de pt h )
29
30 >> print ( price )
31
32 >> print ( snapshot_bid , hist . token )
33 > >[[10101.20 , 0.44100] , [10101.10 , 0.450541]] True
6 MODULES 22
6.2.2.6 function update price index buy(self, level depth, price level, pre level depth)
Description: If there is a new price level introduced, this function determines its location and appropriately
inserts it into the snapshot bid array. It will also set the position, and token depending on where the
change occurs.
parameters: level depth: float64
level depth received from the l2update message
price level: float64
The price level being introduced
pre level depth: float64
some pre level depth that is reset to 0, idk this feature
returns: snapshot bid list
The modified snapshot bid.
bid range: list
The modified range of bids available in the snapshot.
pre level depth float64
again the pre level depth that idk why i still have this.
latent changes: token boolean
bool that informs whether a significant change has occurred in the order book.
order type
Example: None
1 # let our snapshot_bid be :
2 snapshot_bid = [[10101.80 , 0.013400] ,[10101.20 , 0.44100] , [10101.10 , 0.450541]]
3
4 # we receive a ’ l2update ’ message from our event loop
5
6 msg = {
7 " type " : " l2update " ,
8 " product_id " : " BTC - USD " ,
9 " time " : " 2019 -08 -14 T20 :42:27.265 Z " ,
10 " changes " : [
11 [
12 " buy " ,
13 " 10 101.9000 0000 " ,
14 " 0.500000 "
15 ]
16 ]
17 }
18
19 # on_message () conventiently parses the message to create relevant local variables
20 # time , changes , side , price_level , level_depth , pre_level_depth , hist . token
21 >> print ( time , side , price_level , level_depth , prelevel_depth , hist . token )
22 > >2019 -08 -14 T20 :42:27.265 Z " buy " 10101. 90000000 0.500000 0 False
23
24 # in on_message () , the variable p r i c e _ m a t c h _ i n d e x is assigned by finding the index
25 # with the matching price , in the snapshot . In this case :
26 p r i c e _ m a t c h _ i n d e x = []
27
28 snapshot_bid , pr e _l ev el _ de pt h = u p d a t e _ p r i c e _ i n d e x _ b u y ( level_depth , price_level ,
p re _l ev e l_ de pt h )
29
30 >> print ( snapshot_bid , hist . token )
31 >[[10101.90 , 0.500000] , [10101.80 , 0.013400] ,[10101.20 , 0.44100] , [10101.10 ,
0.450541]] True
6 MODULES 23
6.2.2.7 function update price index sell(self, level depth, price level, pre level depth)
Description: If there is a new price level introduced, this function determines its location and appropriately
inserts it into the snapshot ask array. It will also set the position, and token depending on where the
change occurs.
parameters: level depth: float64
level depth received from the l2update message
price level: float64
The price level being introduced
pre level depth: float64
some pre level depth that is reset to 0, idk this feature
returns: snapshot ask: list
The modified snapshot ask.
bid range: list
The modified range of bids available in the snapshot.
pre level depth float64
again the pre level depth that idk why i still have this.
latent changes: token: boolean
bool that informs whether a significant change has occurred in the order book.
order type: string
type of order in [‘market’, ‘insertion’, ‘cancelation’]
Example:
1 # let our snapshot_bid be :
2 snapshot_ask = [[10101.90 , 0.013400] ,[10102.00 , 0.52100] , [10102.11 , 0.89041]]
3
4 # we receive a ’ l2update ’ message from our event loop
5
6 msg = {
7 " type " : " l2update " ,
8 " product_id " : " BTC - USD " ,
9 " time " : " 2019 -08 -14 T20 :42:27.265 Z " ,
10 " changes " : [
11 [
12 " sell " ,
13 " 10 101.9500 0000 " ,
14 " 0.500000 "
15 ]
16 ]
17 }
18
19 # on_message () conventiently parses the message to create relevant local variables
20 # time , changes , side , price_level , level_depth , pre_level_depth , hist . token
21 >> print ( time , side , price_level , level_depth , prelevel_depth , hist . token )
22 > >2019 -08 -14 T20 :42:27.265 Z " buy " 10101. 90000000 0.500000 0 False
23
24 # in on_message () , the variable p r i c e _ m a t c h _ i n d e x is assigned by finding the index
25 # with the matching price , in the snapshot . In this case :
26 p r i c e _ m a t c h _ i n d e x = []
27
28 snapshot_ask , pr e _l ev el _ de pt h = u p d a t e _ p r i c e _ i n d e x _ s e l l ( level_depth , price_level ,
p re _l ev e l_ de pt h )
29
30 >> print ( snapshot_bid , hist . token )
31 > [[10101.90 , 0.013400] ,[10101.95 , 0.500000] ,[10102.00 , 0.52100] , [10102.11 , 0.89041]]
True
6 MODULES 24
Accessors: The following functions, prefaced with last are the currently named accessors. They cover
the last order of a named type, the last state of the order book, and the market depth for a the last
given state of the order book. If I come up with other relevant accessors or refine how each function
works their changes will likely be noted in the versions, or at least a git entry.
Description:Helper functions that operate in recorder full.py and LOBfuncs.py. It contains simple
methods that are agnostic to side (e.g., bid/ask/signed) for the most part.
6.3.0.3 function conver array to list dict sob(history, events, pos limt=5)
Description: converts the time-series of order book states into a list of dictionaries for the signed order
book. This has some nuance because the signed book format has negative volumes, and the ordinal scale
is prefaced by a negative sign. Works similarly to conver array to list dict but uses the mid-price
from events to find where to separate the bid and ask sides.
parameters: history: list
time series of order book states
events: list
The events list where the function will extract the mid price from.
pos limit: int, default := 5
Ordinal distance from the best bid/ask that is worth saving.
returns: volm list: list
list of dictionaries for volume sizes and their respective position.
price list: list
list of dictionaries for prices and their respective position.
latent changes: None: None
Example: None
1 # let our snapshot_bid be :
2 bid_history = [
3 [2019 -08 -14 T20 :42:27.265 Z ,[[10101.80 , 0.013400] ,[10101.20 , 0.44100] , [10101.10 ,
0.450541] , [10100.55 , 5.24501] , [10099.00 , 10.24511] , [10090.11 , 24.21395]]] ,
4 [2019 -08 -14 T20 :42:27.500 Z ,[[10101.20 , 0.44100] , [10101.10 , 0.450541] , [10100.55 ,
5.24501] , [10099.00 , 10.24511] , [10090.11 , 24.21395] ,[10090.05]] ] ,
5 [2019 -08 -14 T20 :42:27.963 Z ,[[10101.20 , 0.55200] , [10101.10 , 0.450541] , [10100.55 ,
5.24501] , [10099.00 , 10.24511] , [10090.11 , 24.21395]]]
6 ]
7
8 ordinal_volumes , o rdinal_p rices = c o n v e r t _ a r r a y _ l i s t _ t o _ d i c t ( snapshot )
9
10 >> print ( o r di na l_ v ol um es )
11 > >[{ " time " :2019 -08 -14 T20 :42:27.265 Z , " 1 " :0.013400 , " 2 " :0.44100 , " 3 " :0.450541 , " 4 "
:5.24501 , " 5 " :10.24511} ,
12 { " time " :2019 -08 -14 T20 :42:27.500 Z , " 1 " :0.44100 , " 2 " :0.450541 , " 3 " :5.24501 , " 4 "
:10.24511 , " 5 " :24.21395} ,
13 { " time " :2019 -08 -14 T20 :42:27.963 Z , " 1 " :0.52200 , " 2 " :0.450541 , " 3 " :5.24501 , " 4 "
:10.24511 , " 5 " :2421395}]
14
15 >> print ( ordin al_pric es )
16 > >[{ " time " :2019 -08 -14 T20 :42:27.265 Z , " 1 " :10101.80 , " 2 " :10101.20 , " 3 " :10101.10 , " 4 "
:10100.55 , " 5 " :10099.00} ,
17 { " time " :2019 -08 -14 T20 :42:27.500 Z , " 1 " :10101.20 , " 2 " :10101.10 , " 3 " :10100.55 , " 4 "
:10099.00 , " 5 " :10090.11} ,
18 { " time " :2019 -08 -14 T20 :42:27.963 Z , " 1 " :10101.20 , " 2 " :10101.10 , " 3 " :10100.55 , " 4 "
:10099.00 , " 5 " :10090.11}]
6 MODULES 35
time 1 2 3 4 5
2019-08-14T20:42:27.265 0.013400 0.44100 0.450541 5.24501 10.24511
2019-08-14T20:42:27.500 0.44100 0.450541 5.24501 10.24511 24.21395
2019-08-14T20:42:27.963 0.52200 0.450541 5.24501 10.24511 24.21395
6 MODULES 36
6.3.0.7 function get min dec(min currency denom, min asset value)
Description: determines the decimal place for the smallest amount of base currency needed for the
minimal denomination of the float currency.
Example: Suppose you have an exchange rate of 10010.99U SD/BT C, (i.e., you need 10010.99U SD
to buy 1BT C) then the amount of BTC in 1 cent or 0.01 USD which is the smallest denomination
of the USD is 0.000000999BT C. We see that this is 10−7 , get min dec would return 7, to pass onto
numpy.around.
parameters: min currency denom : float64
the minimum currency denomination (e.g., 0.01 USD)
min asset value: float646
the smallest current valuation of the asset.
returns: min dec out int
The number of decimal places out for the smallest movement of the asset for a minimal d
latent changes: None: None
Example: None
1 ??????
7 CREDITS 39
7 Credits
7.1 Development Lead
Ivan E. Perez - perez.ivan.e@gmail.com
7.2 Contributors
BTC-DAVE - jewmansown69@gmail.com
8 LICENSE 40
8 License
GNU GPLv3 License
Copyright (c) 2020, Ivan E. Perez
This program is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version. This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not,
see https://www.gnu.org/licenses/.
9 APPENDIX 41
9 Appendix
10 To do list
1. daily goals
References
[1] Weibing Huang, Charles-Albert Lehalle, and Mathieu Rosenbaum. Simulating and analyzing order
book data: The queue-reactive model. Journal of the American Statistical Association, 110(509):107–
122, 2015.
[2] Álvaro Cartea, Sebastian Jaimungal, and Yixuan Wang. Spoofing and price manipulation in order-
driven markets. Applied Mathematical Finance, 27(1-2):67–98, 2020.
[3] Maureen O’Hara. Market Microstructure Theory. John Wiley & Sons Inc., 1998.
[4] Arseniy Kukanov Rama Cont and Sasha Stoikov. The price impact of order book events. SSRN,
pages 1–32, 2012.
[5] Sasha Stoikov Rama Cont and Rishi Talreja. A stochasic model for order book dynamics. SSRN,
pages 1–33, 2009.
[6] Edward Silyantev. Order flow analysis of crpytocurrency markets. Digital Finance, pages 191–218,
2019.