Skip to content

Commit a96338f

Browse files
committed
fix: api key
1 parent ce14e98 commit a96338f

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DELTADEFI_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

src/deltadefi/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ def __init__(self, base_url=None, api_key=None, timeout=None, **kwargs):
1515
self.session.headers.update(
1616
{
1717
"Content-Type": "application/json;charset=utf-8",
18+
"X-API-KEY": api_key if api_key is not None else "",
1819
}
1920
)
2021

2122
def send_request(self, http_method, url_path, payload=None):
2223
if payload is None:
2324
payload = {}
24-
payload["X-API-KEY"] = self.api_key
2525
url = self.base_url + url_path
2626
params = clean_none_value(
2727
{
@@ -70,6 +70,7 @@ def _handle_exception(self, response):
7070
error_data = None
7171
if "data" in err:
7272
error_data = err["data"]
73+
print("Error?", err)
7374
raise ClientError(
7475
status_code, err["code"], err["msg"], response.headers, error_data
7576
)

src/deltadefi/clients/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
# flake8: noqa
2-
from .accounts import *
3-
from .app import *
42
from .clients import *
5-
from .markets import *
6-
from .orders import *

src/deltadefi/clients/markets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from typing import Literal
44

5+
from deltadefi.api import API
56
from deltadefi.lib.utils import check_required_parameter, check_required_parameters
67
from deltadefi.responses import (
78
GetAggregatedPriceResponse,
@@ -10,7 +11,7 @@
1011
)
1112

1213

13-
class Markets:
14+
class Markets(API):
1415
"""
1516
Markets client for interacting with the DeltaDeFi API.
1617
"""

tests/clients/test_accounts.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
# flake8: noqa
2+
# get api_key from env
3+
import os
24
import unittest
35

4-
from deltadefi.clients.accounts import Accounts
5-
from deltadefi.clients.clients import ApiClient
6-
from deltadefi.requests import SignInRequest
7-
from deltadefi.responses import SignInResponse
6+
from deltadefi.clients import ApiClient
7+
from deltadefi.responses import GetAccountBalanceResponse
8+
9+
api_key = os.getenv("DELTADEFI_API_KEY")
810

911

1012
class TestAccounts(unittest.TestCase):
1113

12-
def test_sign_in(self):
14+
def test_get_account_balance(self):
15+
if not api_key:
16+
self.skipTest("DELTADEFI_API_KEY not set in environment variables")
17+
1318
# Arrange
14-
api = ApiClient()
15-
sign_in_data: SignInRequest = {
16-
"wallet_address": "addr_test1qqzgg5pcaeyea69uptl9da5g7fajm4m0yvxndx9f4lxpkehqgezy0s04rtdwlc0tlvxafpdrfxnsg7ww68ge3j7l0lnszsw2wt",
17-
"auth_key": "test",
18-
}
19+
api = ApiClient(api_key=api_key)
1920

2021
# Act
21-
response: SignInResponse = api.accounts.sign_in(sign_in_data)
22+
response: GetAccountBalanceResponse = api.accounts.get_account_balance()
2223
print(f"response: {response}")
2324

24-
# Assert
25-
print(f"response: {response}")
26-
self.assertIn("token", response)
27-
self.assertIn("is_first_time", response)
25+
# # Assert
26+
# print(f"response: {response}")
27+
# self.assertIn("token", response)
28+
# self.assertIn("is_first_time", response)
2829

2930

3031
if __name__ == "__main__":

0 commit comments

Comments
 (0)