Skip to content

[feature] config credentials, order_cancel_all(side) #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 32 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 Expand Up @@ -174,3 +194,15 @@ event_loop.run_until_complete( ticker(sock, payload) )
<br/>
<img alt="uJhin's ETH" src="https://img.shields.io/badge/ETH-0x60dd373f59862d9df776596889b997e24bee42eb-blue?style=flat-square&logo=ethereum">
</div>

### Contributor
```shell
deactivate

rm -rf venv

python3 -m venv venv
source venv/bin/activate

pip3 install -r client/python/requirements.txt
```
3 changes: 2 additions & 1 deletion client/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
requests==2.30.0
arrow==1.2.3
attrs==23.1.0
bravado==11.0.3
Expand All @@ -17,7 +18,6 @@ pyrsistent==0.19.3
python-dateutil==2.8.2
pytz==2023.3
PyYAML==6.0
requests==2.30.0
rfc3339-validator==0.1.4
rfc3987==1.3.8
simplejson==3.19.1
Expand All @@ -29,3 +29,4 @@ uri-template==1.2.0
urllib3==2.0.2
webcolors==1.13
websockets==11.0.3
seunggabi_core_python
41 changes: 19 additions & 22 deletions client/python/setup.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@

from setuptools import setup
from setuptools import find_packages

from upbit import pkginfo


with open('README.rst') as readme:
long_description = readme.read()


setup(
name = pkginfo.PACKAGE_NAME,
version = pkginfo.CURRENT_VERSION,
packages = find_packages(),
install_requires = [
'bravado>=11.0.2'
name=pkginfo.PACKAGE_NAME,
version=pkginfo.CURRENT_VERSION,
packages=find_packages(),
install_requires=[
'bravado>=11.0.2'
, 'PyJWT>=2.4.0'
, 'websockets>=10.3'
],
extras_require = {
extras_require={
'fido': [
'fido>=4.2.1'
]
},
python_requires = '>=3.8',
classifiers = [
'Programming Language :: Python :: 3.8'
python_requires='>=3.8',
classifiers=[
'Programming Language :: Python :: 3.8'
, 'Programming Language :: Python :: 3.9'
, 'Programming Language :: Python :: 3.10'
, 'Programming Language :: Python :: 3.11'
, 'Programming Language :: Python :: 3.12'
],
keywords = [
'Upbit'
keywords=[
'Upbit'
, 'upbit'
, 'upbit-client'
, 'Upbit-Client'
Expand All @@ -42,12 +39,12 @@
, 'Upbit_api_connector'
, 'upbit_api_connector'
],
url = 'https://github.com/uJhin/upbit-client',
download_url = 'https://github.com/uJhin/upbit-client/releases',
license = 'MIT License',
author = 'ujhin',
author_email = 'ujhin942@gmail.com',
description = 'Upbit OPEN API Client',
long_description_content_type = 'text/x-rst',
long_description = long_description
url='https://github.com/uJhin/upbit-client',
download_url='https://github.com/uJhin/upbit-client/releases',
license='MIT License',
author='ujhin',
author_email='ujhin942@gmail.com',
description='Upbit OPEN API Client',
long_description_content_type='text/x-rst',
long_description=long_description
)
10 changes: 10 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 seunggabi_core_python.util import config_util


class Upbit:
Expand All @@ -22,8 +23,17 @@ 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 = config_util.get(
group="upbit",
context="credentials",
profile=profile
)
access_key = credentials["access_key"]
secret_key = credentials["secret_key"]

self.__client = models.ClientModel(
access_key=access_key,
Expand Down
42 changes: 41 additions & 1 deletion client/python/upbit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


HOST = "https://api.upbit.com"
SPEC_URI = "https://raw.githubusercontent.com/uJhin/upbit-client/main/mapper/swg_mapper.json"
SPEC_URI = "https://raw.githubusercontent.com/seunggabi/upbit-client/main/mapper/swg_mapper.json"


class ClientModel:
Expand Down Expand Up @@ -530,6 +530,46 @@ def Order_cancel(self, **kwargs) -> dict:
future = self.__client.Order.Order_cancel(**kwargs)
return HTTPFutureExtractor.future_extraction(future)

def Order_cancel_all(
self,
side: str = None,
market: str = None,
) -> dict:
args = {
"state": "wait"
}

if market:
args["market"] = market

result = []
while True:
waits = HTTPFutureExtractor.future_extraction(
self.__client.Order.Order_info_all(**args)
)["result"]

if len(waits) == 0:
break

for w in waits:
if w == "error":
return {
"result": result
}

if side and w["side"] != side:
continue

HTTPFutureExtractor.future_extraction(
self.__client.Order.Order_cancel(uuid=w["uuid"])
)

result.append(w)

return {
"result": result
}


class Trade:
"""
Expand Down
30 changes: 2 additions & 28 deletions client/python/upbit/pkginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,7 @@
- Official Support Email: open-api@upbit.com
"""

import logging
import requests

from distutils.version import LooseVersion


def _get_versions(package_name):
url = f"https://pypi.org/pypi/{package_name}/json"
resp = requests.get(url)
data = resp.json()
versions = data["releases"].keys()
return sorted(versions, key=LooseVersion, reverse=True)


PACKAGE_NAME = "upbit-client"
PACKAGE_NAME = "upbit-client"

OPEN_API_VERSION = "1.3.4"
CURRENT_VERSION = OPEN_API_VERSION+".1"

RELEASED_VERSION = _get_versions(PACKAGE_NAME)
LATEST_VERSION = RELEASED_VERSION[0]


if LATEST_VERSION != CURRENT_VERSION:
logging.basicConfig(format="[%(levelname)s] %(message)s")
logging.warning(
f"{PACKAGE_NAME} is currently a newer version: {LATEST_VERSION}\n"
f"Please update to the latest version using the pip command:"
f"`pip install --upgrade {PACKAGE_NAME}`"
)
CURRENT_VERSION = OPEN_API_VERSION + ".1"
1 change: 1 addition & 0 deletions swg_generated/python/swagger_client/api/withdraw_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def withdraw_coin(self, currency, amount, address, **kwargs): # noqa: E501

:param async_req bool
:param str currency: Currency 코드 (required)
:param str net_type: 출금 네트워크 (required)
:param str amount: 출금 수량 (required)
:param str address: 출금 가능 주소에 등록된 출금 주소 (required)
:param str secondary_address: 2차 출금 주소 (필요한 코인에 한해서)
Expand Down