Skip to content

Commit 136f054

Browse files
committed
[Community] handle production db functions
1 parent d9d2c27 commit 136f054

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

octobot/community/supabase_backend/community_supabase_client.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -424,14 +424,15 @@ async def upsert_portfolio_history(self, portfolio_histories) -> list:
424424
).execute()).data
425425

426426
async def fetch_candles_history_range(
427-
self, exchange: str, symbol: str, time_frame: commons_enums.TimeFrames
427+
self, exchange: str, symbol: str, time_frame: commons_enums.TimeFrames, use_production_db: bool
428428
) -> (typing.Union[float, None], typing.Union[float, None]):
429429
params = {
430430
"exchange_internal_name": exchange,
431431
"symbol": symbol,
432432
"time_frame": time_frame.value,
433433
}
434-
range_return = (await self.postgres_functions().invoke(
434+
db_functions = self.production_anon_postgres_functions() if use_production_db else self.postgres_functions()
435+
range_return = (await db_functions.invoke(
435436
"get_ohlcv_range",
436437
{"body": params}
437438
))["data"]
@@ -511,6 +512,14 @@ async def get_production_anon_client(self):
511512
)
512513
return self.production_anon_client
513514

515+
def _get_production_anon_auth_headers(self):
516+
return self._get_anon_auth_headers(constants.COMMUNITY_PRODUCTION_BACKEND_KEY)
517+
518+
def production_anon_postgres_functions(self):
519+
return self.postgres_functions(
520+
url=constants.COMMUNITY_PRODUCTION_BACKEND_URL, auth_headers=self._get_production_anon_auth_headers()
521+
)
522+
514523
async def _paginated_fetch_historical_data(
515524
self, client, table_name: str, select: str, matcher: dict,
516525
first_open_time: float, last_open_time: float

octobot/community/supabase_backend/supabase_client.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ async def close(self):
136136
pass
137137
await self.realtime.close()
138138

139-
def postgres_functions(self):
140-
return postgres_functions.PostgresFunctions(self.supabase_url, self._get_auth_headers())
139+
def postgres_functions(self, url=None, auth_headers=None):
140+
return postgres_functions.PostgresFunctions(url or self.supabase_url, auth_headers or self._get_auth_headers())
141141

142142
def remove_session_details(self):
143143
self.auth._remove_session()
@@ -158,9 +158,12 @@ def _use_auth_session(self, event: gotrue.AuthChangeEvent, _):
158158
# await self.storage.aclose()
159159
# self._init_storage_client(self.storage_url, self._get_auth_headers())
160160

161+
def _get_anon_auth_headers(self, supabase_key):
162+
"""Helper method to get anon auth headers."""
163+
return self._format_auth_headers(supabase_key, supabase_key)
164+
161165
def _get_auth_headers(self):
162166
"""Helper method to get auth headers."""
163-
# What's the corresponding method to get the token
164167
return self._format_auth_headers(self.supabase_key, self._get_auth_key())
165168

166169
def _format_auth_headers(self, supabase_key, auth_token):

0 commit comments

Comments
 (0)