bw-essentials-core 0.1.7__py3-none-any.whl → 0.1.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of bw-essentials-core might be problematic. Click here for more details.
- bw_essentials/services/payment.py +39 -0
- bw_essentials/services/portfolio_catalogue.py +55 -1
- bw_essentials/services/user_portfolio.py +165 -1
- {bw_essentials_core-0.1.7.dist-info → bw_essentials_core-0.1.9.dist-info}/METADATA +1 -1
- {bw_essentials_core-0.1.7.dist-info → bw_essentials_core-0.1.9.dist-info}/RECORD +7 -6
- {bw_essentials_core-0.1.7.dist-info → bw_essentials_core-0.1.9.dist-info}/WHEEL +0 -0
- {bw_essentials_core-0.1.7.dist-info → bw_essentials_core-0.1.9.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from bw_essentials.services.api_client import ApiClient
|
|
3
|
+
from bw_essentials.constants.services import Services
|
|
4
|
+
|
|
5
|
+
logger = logging.getLogger(__name__)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Payment(ApiClient):
|
|
9
|
+
|
|
10
|
+
def __init__(self, service_user: str):
|
|
11
|
+
super().__init__(service_user)
|
|
12
|
+
self.urls = {
|
|
13
|
+
"get_subscription": "user-subscription",
|
|
14
|
+
}
|
|
15
|
+
self.name = Services.PAYMENT.value
|
|
16
|
+
self.base_url = self.get_base_url(Services.PAYMENT.value)
|
|
17
|
+
|
|
18
|
+
def get_subscription(self, user_id):
|
|
19
|
+
"""
|
|
20
|
+
Fetch subscription details for a given user.
|
|
21
|
+
|
|
22
|
+
This method constructs the request URL using the configured base URL
|
|
23
|
+
and the `get_subscription` endpoint. It sends a GET request with
|
|
24
|
+
the provided `user_id` as a query parameter, logs the process,
|
|
25
|
+
and returns the subscription data payload.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
user_id (str | int): Unique identifier of the user whose
|
|
29
|
+
subscription details need to be fetched.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
dict | None: A dictionary containing the subscription data if
|
|
33
|
+
available, otherwise `None`.
|
|
34
|
+
"""
|
|
35
|
+
logger.info(f"Received request to get subscription with {user_id =}")
|
|
36
|
+
url = f"{self.base_url}/{self.urls.get('get_subscription')}"
|
|
37
|
+
subscription = self._get(url, params={'userId': user_id})
|
|
38
|
+
logger.info(f"Successfully fetched subscription data. {subscription =}")
|
|
39
|
+
return subscription.get('data')
|
|
@@ -78,7 +78,9 @@ class PortfolioCatalogue(ApiClient):
|
|
|
78
78
|
self.name = Services.PORTFOLIO_CATALOGUE.value
|
|
79
79
|
self.urls = {
|
|
80
80
|
"rebalance": "rebalance",
|
|
81
|
-
"get_rebalance": "rebalance"
|
|
81
|
+
"get_rebalance": "rebalance",
|
|
82
|
+
"subscriptions_by_ids": "subscription-plan/list",
|
|
83
|
+
"otp_subscriptions_by_ids": "one-time-plans/list"
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
def create_rebalance(self, json: Dict[str, Any]) -> Optional[Dict[str, Any]]:
|
|
@@ -157,3 +159,55 @@ class PortfolioCatalogue(ApiClient):
|
|
|
157
159
|
return next_rebalance_date
|
|
158
160
|
logger.info("get_rebalance_due_date not applicable for status=%s", status)
|
|
159
161
|
return None
|
|
162
|
+
|
|
163
|
+
def get_subscriptions_by_ids(self, plans_ids: list):
|
|
164
|
+
"""
|
|
165
|
+
Fetch multiple subscriptions by their plan IDs.
|
|
166
|
+
|
|
167
|
+
This method constructs the request URL using the configured base URL
|
|
168
|
+
and the `subscriptions_by_ids` endpoint. It sends a POST request with
|
|
169
|
+
the given list of `plans_ids` in the request body, logs the process,
|
|
170
|
+
and returns the subscription data.
|
|
171
|
+
|
|
172
|
+
Args:
|
|
173
|
+
plans_ids (list[str] | list[int]): A list of subscription plan IDs
|
|
174
|
+
to fetch details for.
|
|
175
|
+
|
|
176
|
+
Returns:
|
|
177
|
+
list[dict]: A list of subscription data dictionaries if available,
|
|
178
|
+
otherwise an empty list.
|
|
179
|
+
"""
|
|
180
|
+
logger.info(f"In get_subscriptions_by_ids {plans_ids =}")
|
|
181
|
+
url = f"{self.base_url}/{self.urls.get('subscriptions_by_ids')}"
|
|
182
|
+
data = {
|
|
183
|
+
'planId': plans_ids
|
|
184
|
+
}
|
|
185
|
+
response = self._post(url, self.headers, data)
|
|
186
|
+
logger.info(f"Successfully fetched subscriptions by ids data. {response =}")
|
|
187
|
+
return response.get('data', [])
|
|
188
|
+
|
|
189
|
+
def get_otp_subscriptions_by_ids(self, plans_ids: list):
|
|
190
|
+
"""
|
|
191
|
+
Fetch OTP subscription details for multiple plan IDs.
|
|
192
|
+
|
|
193
|
+
This method sends a POST request to the `otp_subscriptions_by_ids`
|
|
194
|
+
endpoint with the given list of plan IDs in the request body.
|
|
195
|
+
It logs the request and response flow and returns the extracted
|
|
196
|
+
subscription data.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
plans_ids (list[str] | list[int]): A list of OTP subscription plan IDs
|
|
200
|
+
to retrieve details for.
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
list[dict]: A list of OTP subscription data dictionaries if available,
|
|
204
|
+
otherwise an empty list.
|
|
205
|
+
"""
|
|
206
|
+
logger.info(f"In get_otp_subscriptions_by_ids {plans_ids =}")
|
|
207
|
+
url = f"{self.base_url}/{self.urls.get('otp_subscriptions_by_ids')}"
|
|
208
|
+
data = {
|
|
209
|
+
'id': plans_ids
|
|
210
|
+
}
|
|
211
|
+
response = self._post(url, self.headers, data)
|
|
212
|
+
logger.info(f"Successfully fetched otp subscriptions by ids data. {response =}")
|
|
213
|
+
return response.get('data', [])
|
|
@@ -43,7 +43,9 @@ class UserPortfolio(ApiClient):
|
|
|
43
43
|
"skip": "userportfolio/order/skip/basket",
|
|
44
44
|
"create_order_instructions": "userportfolio/order/order-instruction",
|
|
45
45
|
"basket_details": "userportfolio/basket",
|
|
46
|
-
"broker_users_holdings": "holding/{}/users"
|
|
46
|
+
"broker_users_holdings": "holding/{}/users",
|
|
47
|
+
"user_portfolio_thresholds": "alerts/portfolio/thresholds",
|
|
48
|
+
"holding_thresholds": "alerts/holding/thresholds"
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
def create_holding_transaction(self, payload):
|
|
@@ -404,3 +406,165 @@ class UserPortfolio(ApiClient):
|
|
|
404
406
|
endpoint = self.urls.get('broker_users_holdings').format(broker)
|
|
405
407
|
response = self._get(url=self.base_url, endpoint=endpoint)
|
|
406
408
|
return response.get('data')
|
|
409
|
+
|
|
410
|
+
def create_user_portfolio_threshold(self, payload):
|
|
411
|
+
"""Create a *User Portfolio* threshold.
|
|
412
|
+
|
|
413
|
+
Parameters
|
|
414
|
+
----------
|
|
415
|
+
payload : dict | str
|
|
416
|
+
JSON-serialisable dictionary (or raw JSON string) containing the
|
|
417
|
+
following **required** keys.
|
|
418
|
+
|
|
419
|
+
* **portfolio_type** (str) – One of the portfolio types accepted by
|
|
420
|
+
the User-Portfolio service (e.g. ``USER_PORTFOLIO`` or ``BASKET``).
|
|
421
|
+
* **portfolio_id** (str) – Unique identifier of the portfolio
|
|
422
|
+
entity.
|
|
423
|
+
* **side** (str) – Either ``LONG`` or ``SHORT``.
|
|
424
|
+
* **threshold_type** (str) – Threshold category, e.g. ``PT`` or
|
|
425
|
+
``SL``.
|
|
426
|
+
* **status** (str) – Initial status, typically ``ACTIVE``.
|
|
427
|
+
|
|
428
|
+
**Optional** keys:
|
|
429
|
+
|
|
430
|
+
* **target_pct** (Decimal | float) – Percent based trigger level.
|
|
431
|
+
* **target_value** (Decimal | float) – Absolute money value trigger.
|
|
432
|
+
* **source** (str) – Origin of the instruction (``user``, ``admin`` …).
|
|
433
|
+
|
|
434
|
+
Returns
|
|
435
|
+
-------
|
|
436
|
+
dict
|
|
437
|
+
A dictionary representing the newly-created threshold (same shape
|
|
438
|
+
as the backend response ``data`` field).
|
|
439
|
+
"""
|
|
440
|
+
logger.info(f"In create_user_portfolio_threshold {payload =}")
|
|
441
|
+
data = self._post(url=self.base_url,
|
|
442
|
+
endpoint=self.urls.get("user_portfolio_thresholds"),
|
|
443
|
+
data=payload)
|
|
444
|
+
logger.info(f"{data =}")
|
|
445
|
+
return data.get("data")
|
|
446
|
+
|
|
447
|
+
def get_user_portfolio_thresholds(self, params=None):
|
|
448
|
+
"""Retrieve *User Portfolio* thresholds.
|
|
449
|
+
|
|
450
|
+
Parameters
|
|
451
|
+
----------
|
|
452
|
+
params : dict | None, optional
|
|
453
|
+
Query-string parameters used as filters; accepted keys mirror the
|
|
454
|
+
columns of ``UserPortfolioThreshold`` (e.g. ``portfolio_type``,
|
|
455
|
+
``portfolio_id``, ``status`` …). Passing ``None`` performs an
|
|
456
|
+
unfiltered list retrieval.
|
|
457
|
+
|
|
458
|
+
Returns
|
|
459
|
+
-------
|
|
460
|
+
list[dict]
|
|
461
|
+
List of serialised thresholds ordered by ``-effective_from``.
|
|
462
|
+
"""
|
|
463
|
+
logger.info(f"In get_user_portfolio_thresholds {params =}")
|
|
464
|
+
data = self._get(url=self.base_url,
|
|
465
|
+
endpoint=self.urls.get("user_portfolio_thresholds"),
|
|
466
|
+
params=params)
|
|
467
|
+
logger.info(f"{data =}")
|
|
468
|
+
return data.get("data")
|
|
469
|
+
|
|
470
|
+
def update_user_portfolio_threshold(self, payload):
|
|
471
|
+
"""Update an existing *User Portfolio* threshold.
|
|
472
|
+
|
|
473
|
+
The request is forwarded verbatim to ``PUT /portfolio/thresholds``.
|
|
474
|
+
|
|
475
|
+
Parameters
|
|
476
|
+
----------
|
|
477
|
+
payload : dict | str
|
|
478
|
+
Dictionary (or JSON string) that **must** include:
|
|
479
|
+
|
|
480
|
+
* **id** (int) – Primary key of the threshold to update.
|
|
481
|
+
|
|
482
|
+
Any of the following *optional* fields may also be supplied; only
|
|
483
|
+
those present will be updated:
|
|
484
|
+
|
|
485
|
+
* **target_pct** (Decimal | float)
|
|
486
|
+
* **status** (str)
|
|
487
|
+
* **source** (str)
|
|
488
|
+
|
|
489
|
+
Returns
|
|
490
|
+
-------
|
|
491
|
+
dict
|
|
492
|
+
The updated threshold as returned by the backend (``data`` field).
|
|
493
|
+
"""
|
|
494
|
+
logger.info(f"In update_user_portfolio_threshold {payload =}")
|
|
495
|
+
data = self._put(url=self.base_url,
|
|
496
|
+
endpoint=self.urls.get("user_portfolio_thresholds"),
|
|
497
|
+
json=payload)
|
|
498
|
+
logger.info(f"{data =}")
|
|
499
|
+
return data.get("data")
|
|
500
|
+
|
|
501
|
+
def create_holding_threshold(self, payload):
|
|
502
|
+
"""Create a *Holding* threshold.
|
|
503
|
+
|
|
504
|
+
Parameters
|
|
505
|
+
----------
|
|
506
|
+
payload : dict | str
|
|
507
|
+
Data required by ``POST /holding/thresholds``. Mandatory keys:
|
|
508
|
+
|
|
509
|
+
* **holding_type** (str)
|
|
510
|
+
* **holding_id** (str)
|
|
511
|
+
* **side** (str)
|
|
512
|
+
* **threshold** (Decimal | float)
|
|
513
|
+
* **effective_from** (datetime-iso-str)
|
|
514
|
+
|
|
515
|
+
Optional: **source** (str)
|
|
516
|
+
|
|
517
|
+
Returns
|
|
518
|
+
-------
|
|
519
|
+
dict
|
|
520
|
+
Newly created Holding-threshold representation.
|
|
521
|
+
"""
|
|
522
|
+
logger.info(f"In create_holding_threshold {payload =}")
|
|
523
|
+
data = self._post(url=self.base_url,
|
|
524
|
+
endpoint=self.urls.get("holding_thresholds"),
|
|
525
|
+
data=payload)
|
|
526
|
+
logger.info(f"{data =}")
|
|
527
|
+
return data.get("data")
|
|
528
|
+
|
|
529
|
+
def get_holding_thresholds(self, params=None):
|
|
530
|
+
"""Retrieve *Holding* thresholds with optional filters.
|
|
531
|
+
|
|
532
|
+
Parameters
|
|
533
|
+
----------
|
|
534
|
+
params : dict | None, optional
|
|
535
|
+
Filter parameters (``holding_type``, ``holding_id`` …). ``None``
|
|
536
|
+
results in an unfiltered list.
|
|
537
|
+
|
|
538
|
+
Returns
|
|
539
|
+
-------
|
|
540
|
+
list[dict]
|
|
541
|
+
Serialised Holding-thresholds ordered by ``-effective_from``.
|
|
542
|
+
"""
|
|
543
|
+
logger.info(f"In get_holding_thresholds {params =}")
|
|
544
|
+
data = self._get(url=self.base_url,
|
|
545
|
+
endpoint=self.urls.get("holding_thresholds"),
|
|
546
|
+
params=params)
|
|
547
|
+
logger.info(f"{data =}")
|
|
548
|
+
return data.get("data")
|
|
549
|
+
|
|
550
|
+
def update_holding_threshold(self, payload):
|
|
551
|
+
"""Update an existing *Holding* threshold.
|
|
552
|
+
|
|
553
|
+
Parameters
|
|
554
|
+
----------
|
|
555
|
+
payload : dict | str
|
|
556
|
+
Must include the primary key ``id`` and any fields to be changed
|
|
557
|
+
(e.g. ``threshold``, ``status`` or ``effective_to``).
|
|
558
|
+
|
|
559
|
+
Returns
|
|
560
|
+
-------
|
|
561
|
+
dict
|
|
562
|
+
Updated Holding-threshold object as returned by the backend.
|
|
563
|
+
"""
|
|
564
|
+
logger.info(f"In update_holding_threshold {payload =}")
|
|
565
|
+
data = self._put(url=self.base_url,
|
|
566
|
+
endpoint=self.urls.get("holding_thresholds"),
|
|
567
|
+
json=payload)
|
|
568
|
+
logger.info(f"{data =}")
|
|
569
|
+
return data.get("data")
|
|
570
|
+
|
|
@@ -17,13 +17,14 @@ bw_essentials/services/market_pricer.py,sha256=Qc9lxzAjhefAvjyEKsBPDu60bF6_61cnS
|
|
|
17
17
|
bw_essentials/services/master_data.py,sha256=2o_r2gdhIKBeTFgn5IIY-becgCEpYBymO4BKmixdV1g,11987
|
|
18
18
|
bw_essentials/services/model_portfolio_reporting.py,sha256=iOtm4gyfU8P7C0R1gp6gUJI4ZRxJD5K2GLOalI_gToM,3249
|
|
19
19
|
bw_essentials/services/notification.py,sha256=q4jIZzIWIHvn-XaIIbkEjjhkYUV8ZGQWUXaY4NNRFgI,5078
|
|
20
|
-
bw_essentials/services/
|
|
20
|
+
bw_essentials/services/payment.py,sha256=3uZUPfRTkk0dzX17npv2LQhwkVXdrbOSIQ_Qh8jsVjU,1467
|
|
21
|
+
bw_essentials/services/portfolio_catalogue.py,sha256=EK0OMvOqnKjfASwBKbfqawiKmKN-FkGR4g17Hxlj8ws,7183
|
|
21
22
|
bw_essentials/services/portfolio_content.py,sha256=rdFTTsUUIt-AgFfA1SAItqg2njakVOm4dUKU0FHZQ2E,2148
|
|
22
23
|
bw_essentials/services/trade_placement.py,sha256=PrzeU2XXC9HF1IQ1dMDM_ZHxmC491sOl-JbA6GWPwII,20772
|
|
23
24
|
bw_essentials/services/user_app.py,sha256=_Y2NgDq6kEoco7ZRJ3-MMYJ-K2HGStJoFoeGOH_HotQ,11107
|
|
24
|
-
bw_essentials/services/user_portfolio.py,sha256=
|
|
25
|
+
bw_essentials/services/user_portfolio.py,sha256=G3PrMOryqEXSERodP4hwbrxV2JHiXUVwxdFri_E1v3k,22179
|
|
25
26
|
bw_essentials/services/user_portfolio_reporting.py,sha256=pwqfW95LTiGOGufcTphljFxPlOd-G4Q263UtoQURPxM,6772
|
|
26
|
-
bw_essentials_core-0.1.
|
|
27
|
-
bw_essentials_core-0.1.
|
|
28
|
-
bw_essentials_core-0.1.
|
|
29
|
-
bw_essentials_core-0.1.
|
|
27
|
+
bw_essentials_core-0.1.9.dist-info/METADATA,sha256=a4w6bUqQFf9vbnz7mFg5w126-WmFRaL37-rdAsbLcus,7501
|
|
28
|
+
bw_essentials_core-0.1.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
29
|
+
bw_essentials_core-0.1.9.dist-info/top_level.txt,sha256=gDc5T_y5snwKGXDQUusEus-FEt0RFwG644Yn_58wQOQ,14
|
|
30
|
+
bw_essentials_core-0.1.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|