Skip to content

Commit

Permalink
(#52) feat: add credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
seunggabi committed May 13, 2023
1 parent 4ae6cd9 commit 10d4604
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,6 @@ dmypy.json

# vscode settings
.vscode/

# jetbrains settings
.idea
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ git clone https://github.com/uJhin/upbit-client.git


### Quick Start
#### Credentials
```shell
mkdir -p ~/.upbit
```
```
# vi ~/.upbit/credentials
[default]
access_key = a
secret_key = b
[a]
access_key = c
secret_key = d
```
```python
client = Upbit() # default
client = Upbit(profile="a")
```

#### REST Client
- Check Your API Keys
```python
Expand Down
6 changes: 6 additions & 0 deletions client/python/upbit/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

from . import models
from .credentials import Credentials


class Upbit:
Expand All @@ -22,8 +23,13 @@ def __init__(
self,
access_key: str = None,
secret_key: str = None,
profile: str = None,
**kwargs
):
if access_key is None and secret_key is None:
credentials = Credentials.get(profile)
access_key = credentials["access_key"]
secret_key = credentials["secret_key"]

self.__client = models.ClientModel(
access_key=access_key,
Expand Down
27 changes: 27 additions & 0 deletions client/python/upbit/credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
from configparser import ConfigParser

PATH = ".upbit/credentials"


class Credentials:
"""
Credentials
"""

@staticmethod
def home():
return os.path.expanduser("~")

@staticmethod
def get(profile: str = None) -> dict:
profile = profile or "default"

config = ConfigParser()
config.read(f"{Credentials.home()}/{PATH}")

return config._sections[profile]


if __name__ == '__main__':
print(Credentials.get())

0 comments on commit 10d4604

Please sign in to comment.