Skip to content

Commit dc75272

Browse files
committed
Consistently use callback names 'handle_(un)subscribe_instruments'
1 parent ead5c24 commit dc75272

4 files changed

Lines changed: 19 additions & 19 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ The returned addon state object is used in many other functions below.
5555
#### start_addon
5656
```python
5757
# Call this to start the communication between your addon and Bookmap.
58-
bm.start_addon(addon, add_instrument_handler, detach_instrument_handler)
58+
bm.start_addon(addon, handle_subscribe_instrument, handle_unsubscribe_instrument)
5959
```
6060
It starts the communication between Bookmap and your Python script. Call it once you have added all
6161
your [Event handlers](#Event-handlers).
6262

63-
`add_instrument_handler` is a function that you should define. It will be called each time you
63+
`handle_subscribe_instrument` is a function that you should define. It will be called each time you
6464
enable the addon in Bookmap for a certain instrument. All handlers, including this one, must have
6565
a proper signature (a list of parameters), as defined below.
6666

67-
`detach_instrument_handler` is similar to above, except is called when the user disables the addon
67+
`handle_unsubscribe_instrument` is similar to above, except is called when the user disables the addon
6868
for a certain instrument.
6969

7070
Example:
7171
```python
7272
import pyl1api as bm
7373

74-
def add_instrument_handler(
74+
def handle_subscribe_instrument(
7575
addon: Any,
7676
alias: str,
7777
full_name: str,
@@ -93,7 +93,7 @@ def add_instrument_handler(
9393
"""
9494
print("Subscribing to the instrument " + alias, flush=True)
9595

96-
def detach_instrument_handler(
96+
def handle_unsubscribe_instrument(
9797
addon: Any,
9898
alias: str
9999
) -> None:
@@ -110,7 +110,7 @@ if __name__ == "__main__":
110110
addon = bm.create_addon()
111111
# start addon, requires 3 arguments - addon itself, handler for subscribe event
112112
# and handler for unsubscribe event
113-
bm.start_addon(addon, add_instrument_handler, detach_instrument_handler)
113+
bm.start_addon(addon, handle_subscribe_instrument, handle_unsubscribe_instrument)
114114
bm.wait_until_addon_is_turned_off(addon)
115115
```
116116

@@ -142,7 +142,7 @@ How to convert these levels to a real price or size? The rule are simple:
142142
> moment.
143143
144144
How to know what the instrument's `pips` and `size_multiplier` values are? You receive them via the
145-
[add_instrument_handler](#start_addon) callback when the user subscribes to an instrument.
145+
[handle_subscribe_instrument](#start_addon) callback when the user subscribes to an instrument.
146146

147147
### Event handlers
148148

examples/cvd_addon.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414

1515
# mandatory callback used to register instrument info inside the python
16-
def handle_instrument_info(addon, alias: str, full_name: str, is_crypto: bool, pips: float, size_granularity: float,
17-
instrument_multiplier: float):
16+
def handle_subscribe_instrument(addon, alias: str, full_name: str, is_crypto: bool, pips: float, size_granularity: float,
17+
instrument_multiplier: float):
1818
global cvd_accumulator
1919
global alias_to_size_granularity
2020
global req_id
@@ -80,7 +80,7 @@ def handle_trades(addon, alias: str, price: float, size: int, is_otc: bool, is_b
8080

8181

8282
# callback notifying that unsubscription appeared
83-
def handle_detach_instrument(addon, alias):
83+
def handle_unsubscribe_instrument(addon, alias):
8484
global cvd_accumulator
8585
del cvd_accumulator[alias]
8686
print("Detached " + alias, flush=True)
@@ -91,7 +91,7 @@ def handle_detach_instrument(addon, alias):
9191
bm.add_trades_handler(addon, handle_trades) # register callback for trades
9292
# register indicator response callback
9393
bm.add_indicator_response_handler(addon, handle_indicator_response)
94-
bm.start_addon(addon, handle_instrument_info,
95-
handle_detach_instrument) # starting an addon
94+
bm.start_addon(addon, handle_subscribe_instrument,
95+
handle_unsubscribe_instrument) # starting an addon
9696
# give control over python scrip to Bookmap, so it won't be finished until it is turned off from Bookmap
9797
bm.wait_until_addon_is_turned_off(addon)

examples/liquidity_tracker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
DEFAULT_LIQUIDITY_SIZE = 10
1111

1212

13-
def handle_instrument_info(addon, alias, full_name, is_crypto, pips, size_multiplier, instrument_multiplier):
13+
def handle_subscribe_instrument(addon, alias, full_name, is_crypto, pips, size_multiplier, instrument_multiplier):
1414
global req_id
1515

1616
instrument = {
@@ -39,7 +39,7 @@ def handle_instrument_info(addon, alias, full_name, is_crypto, pips, size_multip
3939
print("Registered...", flush=True)
4040

4141

42-
def handle_instrument_detached(addon, alias):
42+
def handle_unsubscribe_instrument(addon, alias):
4343
del alias_to_order_book[alias]
4444
del alias_to_instrument[alias]
4545

@@ -92,5 +92,5 @@ def on_settings_change_handler(addon, alias: str, setting_name: str, field_type:
9292
bm.add_indicator_response_handler(
9393
addon, handle_register_indicator_response)
9494
bm.add_on_setting_change_handler(addon, on_settings_change_handler)
95-
bm.start_addon(addon, handle_instrument_info, handle_instrument_detached)
95+
bm.start_addon(addon, handle_subscribe_instrument, handle_unsubscribe_instrument)
9696
bm.wait_until_addon_is_turned_off(addon)

examples/order_book_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
alias_to_order_book = {}
44

55

6-
def handle_instrument_info(addon, alias, full_name, is_crypto, pips, size_multiplier, instrument_multiplier):
6+
def handle_subscribe_instrument(addon, alias, full_name, is_crypto, pips, size_multiplier, instrument_multiplier):
77
print("Instrument received " + alias, flush=True)
88
# create order book for each subscribed instrument
99
alias_to_order_book[alias] = bm.create_order_book()
@@ -13,8 +13,8 @@ def handle_instrument_info(addon, alias, full_name, is_crypto, pips, size_multip
1313
print("Data subscribed", flush=True)
1414

1515

16-
def handle_detach(addon, alias):
17-
print("Detached " + alias, flush=True)
16+
def handle_unsubscribe_instrument(addon, alias):
17+
print("The instrument " + alias + " has been removed", flush=True)
1818

1919

2020
# handler for depth. it receives information about side, price and size.
@@ -33,5 +33,5 @@ def handle_depth_info(addon, alias, is_bid, price, size):
3333
addon = bm.create_addon()
3434
print("Addon created", flush=True)
3535
bm.add_depth_handler(addon, handle_depth_info)
36-
bm.start_addon(addon, handle_instrument_info, handle_detach)
36+
bm.start_addon(addon, handle_subscribe_instrument, handle_unsubscribe_instrument)
3737
bm.wait_until_addon_is_turned_off(addon)

0 commit comments

Comments
 (0)