balance_utils
Balance utils can be used to retrieve balance and position data.
load_autotrading_balance(bm_engine, start_time_lb_utc, stop_time_lb_utc)
Load the balances for the given time range from the BalanceManagement database.
The column types of the resulting dataframe are normalized to the following: - start_time_lb_utc: datetime64[ns, UTC] - stop_time_lb_utc: datetime64[ns, UTC] - variable_id: str - balance_kw: int64
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bm_engine
|
Engine
|
A SQLAlchemy database Engine instance for the BalanceManagement database. |
required |
start_time_lb_utc
|
datetime
|
The start time of the query in UTC, i.e. the first start_time_lb_utc of the result. |
required |
stop_time_lb_utc
|
datetime
|
The stop time of the query in UTC, i.e. the last start_time_lb_utc after the result. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: A pandas DataFrame containing the query result. |
Raises:
| Type | Description |
|---|---|
OperationalError
|
There is an error in the SQL statement. |
Example
from sqlalchemy import create_engine
bm_engine = create_engine("sqlite:///:memory:")
start_time_lb_utc = datetime(2021, 1, 1, 0, 0, 0)
stop_time_lb_utc = datetime(2021, 1, 1, 1, 0, 0)
resolution_seconds = 900
df = load_autotrading_balance(bm_engine, start_time_lb_utc, stop_time_lb_utc, resolution_seconds)
print(df.head())
Source code in physical_operations_utils/balance_utils.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
load_autotrading_positions(bm_engine, start_time_lb_utc, stop_time_lb_utc, resolution_seconds)
Load current autotrading postitions based on the balance management database and the net traded volumes filtered by resolution.
The column types of the resulting dataframe are normalized to the following: - start_time_lb_utc: datetime64[ns, UTC] - stop_time_lb_utc: datetime64[ns, UTC] - price_area: str - balance_kw: int64 - resolution_seconds: int64 - id_net_traded: int64 - position_kw: int64
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bm_engine
|
Engine
|
A SQLAlchemy database Engine instance for the BalanceManagement database. |
required |
start_time_lb_utc
|
datetime
|
The start time of the query in UTC, i.e. the first start_time_lb_utc of the result. |
required |
stop_time_lb_utc
|
datetime
|
The stop time of the query in UTC, i.e. the last start_time_lb_utc after the result. |
required |
resolution_seconds
|
int
|
The resolution of the query in seconds. |
required |
Returns: pd.DataFrame: A pandas DataFrame containing the query result.
Raises:
| Type | Description |
|---|---|
OperationalError
|
There is an error in the SQL statement. |
Example
from sqlalchemy import create_engine
bm_engine = create_engine("sqlite:///:memory:")
feed_engine = create_engine("sqlite:///:memory:")
start_time_lb_utc = datetime(2021, 1, 1, 0, 0, 0)
stop_time_lb_utc = datetime(2021, 1, 1, 1, 0, 0)
resolution_seconds = 900
df = load_autotrading_balance_positions(bm_engine, feed_engine, start_time_lb_utc, stop_time_lb_utc, resolution_seconds)
print(df.head())
Source code in physical_operations_utils/balance_utils.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |