Skip to content

Commit

Permalink
(uJhin#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 d0b1106
Show file tree
Hide file tree
Showing 10 changed files with 93 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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/upbit-client.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
25 changes: 25 additions & 0 deletions client/python/upbit/credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
from configparser import ConfigParser

PATH = ".upbit/credentials"


class Credentials:
"""
Credentials
"""

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

@staticmethod
def get(profile: str = "default") -> dict:
config = ConfigParser()
config.read(f"{Credentials.home()}/{PATH}")

return config._sections[profile]


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

0 comments on commit d0b1106

Please sign in to comment.