From 6c5ac1ba8ab9a4c3f9e6f5a492ac9d01b7d97221 Mon Sep 17 00:00:00 2001 From: Ryan Walder Date: Thu, 13 Jan 2022 18:35:29 +0000 Subject: [PATCH] Fix sandbox mode Actually use the sandbox api if `-sandbox` is specified --- gemini_api.py | 7 ++++++- gemini_bot.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gemini_api.py b/gemini_api.py index 366190b..2a8ffe1 100644 --- a/gemini_api.py +++ b/gemini_api.py @@ -19,13 +19,16 @@ def __init__(self, status_code, response_json): class GeminiApiConnection(object): - def __init__(self, client_key: str, client_secret: str): + def __init__(self, client_key: str, client_secret: str, sandbox: bool): self.client_key = client_key self.client_secret = client_secret.encode() + self.sandbox = sandbox def _make_public_request(self, endpoint: str): base_url = "https://api.gemini.com/v1" + if self.sandbox: + base_url = "https://api.sandbox.gemini.com/v1" url = base_url + endpoint r = requests.get(url) @@ -38,6 +41,8 @@ def _make_public_request(self, endpoint: str): def _make_authenticated_request(self, verb: str, endpoint: str, payload: dict = {}): base_url = "https://api.gemini.com/v1" + if self.sandbox: + base_url = "https://api.sandbox.gemini.com/v1" url = base_url + endpoint t = datetime.datetime.now() diff --git a/gemini_bot.py b/gemini_bot.py index 534151a..363e4dc 100644 --- a/gemini_bot.py +++ b/gemini_bot.py @@ -112,7 +112,7 @@ def get_timestamp(): aws_secret_access_key = config.get(config_section, 'AWS_SECRET_ACCESS_KEY') aws_region = config.get(config_section, 'AWS_REGION') - gemini_api_conn = GeminiApiConnection(client_key=client_key, client_secret=secret_key) + gemini_api_conn = GeminiApiConnection(client_key=client_key, client_secret=secret_key, sandbox=sandbox_mode) # Configure the market details symbol_details = gemini_api_conn.symbol_details(market_name)