Skip to content

Commit cf54025

Browse files
romanpbmrok-povsic
authored andcommitted
Add description for on_balance_update handler
1 parent f0464c7 commit cf54025

1 file changed

Lines changed: 68 additions & 1 deletion

File tree

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,58 @@ def on_position_update(
538538
:param position_update: The dictionary representing the updated position with various key-value pairs.
539539
"""
540540
```
541-
With the add_on_position_update_handler method, you can easily manage and respond to any changes in your
541+
With the `add_on_position_update_handler` method, you can easily manage and respond to any changes in your
542542
positions within Bookmap.
543543

544+
#### add_on_balance_update_handler
545+
```python
546+
# Use this method to add a handler for balance update events. When a balance update occurs,
547+
# your custom `on_balance_update` function will be called to process the updated balance information.
548+
bm.add_on_balance_update_handler(addon, on_balance_update)
549+
```
550+
The `add_on_balance_update_handler` function is used to add a handler for balance update events.
551+
This function allows you to specify a custom function, `on_balance_update`, that will be called whenever
552+
there is a balance update event.
553+
554+
Example of the handler function:
555+
```python
556+
# addon - The entity received from the create_addon function.
557+
# event - A dictionary representing the balance
558+
def on_balance_update(
559+
addon: Any,
560+
event: Dict[str, Any]
561+
) -> None:
562+
"""
563+
This function is called each time there is a balance update event.
564+
565+
:param addon: The addon state object that you received when calling `create_addon`.
566+
:param event: The event dictionary representing a balance update event with the following keys:
567+
- 'balancesInCurrency': (list) a list of dictionaries, each representing a currency balance with the following keys:
568+
- 'balance': (float) floating-point balance value.
569+
- 'realizedPnl': (float) floating-point realized profit and loss.
570+
- 'unrealizedPnl': (float) floating-point unrealized profit and loss.
571+
- 'previousDayBalance': (float) floating-point balance from the previous day.
572+
- 'netLiquidityValue': (float) floating-point net liquidity value.
573+
- 'currency': (string) currency code.
574+
- 'rateToBase': (float) floating-point exchange rate to the base currency.
575+
"""
576+
```
577+
578+
Example of dictionary that represents the information about particular currency:
579+
580+
```
581+
'balance': 0.255,
582+
'realizedPnl': nan,
583+
'unrealizedPnl': nan,
584+
'previousDayBalance': nan,
585+
'netLiquidityValue': nan,
586+
'currency': 'DOGE',
587+
'rateToBase': 0.06203
588+
```
589+
590+
By adding an `on_balance_update` handler, you can customize how your addon responds to balance update events,
591+
making it more flexible and tailored to your specific needs.
592+
544593
### Subscribe data (TODO: Move this higher)
545594

546595
Below are examples of how to subscribe to market data. Note that you should always register your
@@ -650,6 +699,24 @@ which is set up using the `add_on_position_update_handler` method.
650699
By utilizing the `subscribe_to_position_updates` method, you can stay informed about changes in your positions,
651700
enabling you to make timely decisions and efficiently manage your trading portfolio.
652701

702+
#### subscribe_to_balance_updates
703+
```python
704+
# Use this method to subscribe to balance update events. The `alias` parameter represents the instrument alias you receive
705+
# in the `handle_subscribe_instrument` callback. The `req_id` is an identifier that you can set yourself to
706+
# uniquely identify this subscription.
707+
bm.subscribe_to_balance_updates(addon, alias, req_id)
708+
```
709+
The `subscribe_to_balance_updates` function is used to subscribe to balance update events.
710+
This function requires the addon, alias, and req_id parameters to subscribe to balance updates for a
711+
specific instrument. Balance update events provide information about changes in your account
712+
balances and are real-time events.
713+
714+
Once subscribed to balance updates, the system will automatically trigger the `on_balance_update`
715+
callback, which is set up using the `add_on_balance_update_handler` method.
716+
717+
By utilizing the `subscribe_to_balance_updates` method, you can stay informed about changes
718+
in your account balances, enabling you to make timely decisions and efficiently manage your trading portfolio.
719+
653720
### Trading
654721
The callbacks below will allow you to create custom trading strategies within Python API.
655722
Note that it is mandatory to check `Is trading strategy` checkbox to allow addon to trade.

0 commit comments

Comments
 (0)