Skip to content

Commit

Permalink
add DOGE, XRP for upbit
Browse files Browse the repository at this point in the history
  • Loading branch information
johnverkim committed Apr 27, 2022
1 parent dbc3478 commit 6f68ea3
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 21 deletions.
48 changes: 48 additions & 0 deletions integration_tests/upbit_data_provider_ITG_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,51 @@ def test_ITG_get_info_return_correct_data(self):
self.assertEqual("closing_price" in info, True)
self.assertEqual("acc_price" in info, True)
self.assertEqual("acc_volume" in info, True)

def test_ITG_get_info_return_correct_data_when_currency_is_BTC(self):
dp = UpbitDataProvider("BTC")
info = dp.get_info()
self.assertEqual(info["market"], "BTC")
self.assertEqual("date_time" in info, True)
self.assertEqual("opening_price" in info, True)
self.assertEqual("high_price" in info, True)
self.assertEqual("low_price" in info, True)
self.assertEqual("closing_price" in info, True)
self.assertEqual("acc_price" in info, True)
self.assertEqual("acc_volume" in info, True)

def test_ITG_get_info_return_correct_data_when_currency_is_ETH(self):
dp = UpbitDataProvider("ETH")
info = dp.get_info()
self.assertEqual(info["market"], "ETH")
self.assertEqual("date_time" in info, True)
self.assertEqual("opening_price" in info, True)
self.assertEqual("high_price" in info, True)
self.assertEqual("low_price" in info, True)
self.assertEqual("closing_price" in info, True)
self.assertEqual("acc_price" in info, True)
self.assertEqual("acc_volume" in info, True)

def test_ITG_get_info_return_correct_data_when_currency_is_DOGE(self):
dp = UpbitDataProvider("DOGE")
info = dp.get_info()
self.assertEqual(info["market"], "DOGE")
self.assertEqual("date_time" in info, True)
self.assertEqual("opening_price" in info, True)
self.assertEqual("high_price" in info, True)
self.assertEqual("low_price" in info, True)
self.assertEqual("closing_price" in info, True)
self.assertEqual("acc_price" in info, True)
self.assertEqual("acc_volume" in info, True)

def test_ITG_get_info_return_correct_data_when_currency_is_XRP(self):
dp = UpbitDataProvider("XRP")
info = dp.get_info()
self.assertEqual(info["market"], "XRP")
self.assertEqual("date_time" in info, True)
self.assertEqual("opening_price" in info, True)
self.assertEqual("high_price" in info, True)
self.assertEqual("low_price" in info, True)
self.assertEqual("closing_price" in info, True)
self.assertEqual("acc_price" in info, True)
self.assertEqual("acc_volume" in info, True)
2 changes: 1 addition & 1 deletion smtm/simulation_data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class SimulationDataProvider(DataProvider):
"""거래소로부터 과거 데이터를 수집해서 순차적으로 제공하는 클래스"""

AVAILABLE_CURRENCY = {"BTC": "KRW-BTC", "ETH": "KRW-ETH"}
AVAILABLE_CURRENCY = {"BTC": "KRW-BTC", "ETH": "KRW-ETH", "DOGE": "KRW-DOGE", "XRP": "KRW-XRP"}

def __init__(self, currency="BTC"):
if currency not in self.AVAILABLE_CURRENCY:
Expand Down
2 changes: 1 addition & 1 deletion smtm/simulation_trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SimulationTrader(Trader):
amount: 거래 수량
"""

AVAILABLE_CURRENCY = {"BTC": "KRW-BTC", "ETH": "KRW-ETH"}
AVAILABLE_CURRENCY = {"BTC": "KRW-BTC", "ETH": "KRW-ETH", "DOGE": "KRW-DOGE", "XRP": "KRW-XRP"}
NAME = "Simulation"

def __init__(self, currency="BTC"):
Expand Down
6 changes: 3 additions & 3 deletions smtm/strategy_sma_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ def __update_process(self, info):
self.cross_info[1] = {"price": 0, "index": current_idx}
self.logger.debug(f"[SMA] SKIP BUY !!! === Stand deviation:{std_ratio:.6f}")
is_skip = True
if is_skip is not True:
self.__add_drawing_spot(info["date_time"], self.process_unit[0])

self.__add_drawing_spot(info["date_time"], current_price)
elif sma_short < sma_mid < sma_long and self.current_process != "sell":
self.current_process = "sell"
self.process_unit = (0, self.asset_amount / self.STEP)
self.logger.debug(
f"[SMA] Try to sell {sma_short} {sma_mid} {sma_long}, amout: {self.process_unit[1]}"
)
self.__add_drawing_spot(info["date_time"], info["closing_price"])
self.__add_drawing_spot(info["date_time"], current_price)
else:
return
self.cross_info[0] = self.cross_info[1]
Expand Down
39 changes: 25 additions & 14 deletions smtm/telegram_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class TelegramController:
INTERVAL = 60
GUIDE_READY = "자동 거래 시작 전입니다.\n명령어를 입력해주세요.\n\n"
GUIDE_RUNNING = "자동 거래 운영 중입니다.\n명령어를 입력해주세요.\n\n"
AVAILABLE_CURRENCY = ["BTC", "ETH", "DOGE", "XRP"]
UPBIT_CURRENCY = ["BTC", "ETH", "DOGE", "XRP"]
BITHUMB_CURRENCY = ["BTC", "ETH"]

def __init__(self):
LogManager.set_stream_level(30)
Expand Down Expand Up @@ -97,7 +100,7 @@ def _create_command(self):
self.main_keyboard = parse.quote(main_keyboard)
self.setup_list = [
{"guide": "운영 예산을 정해주세요", "keyboard": ["50000", "100000", "500000", "1000000"]},
{"guide": "거래할 화폐를 정해주세요", "keyboard": ["BTC", "ETH"]},
{"guide": "거래할 화폐를 정해주세요", "keyboard": self.AVAILABLE_CURRENCY},
{"guide": "거래소를 선택해 주세요", "keyboard": ["1. Upbit", "2. Bithumb"]},
{"guide": "전략을 선택해 주세요", "keyboard": ["1. Buy and Hold", "2. Simple Moving Average"]},
{"guide": "자동 거래를 시작할까요?", "keyboard": ["1. Yes", "2. No"]},
Expand Down Expand Up @@ -241,6 +244,24 @@ def _send_http(self, url, is_post=False, file=None):

return result

def _on_start_step3(self, command):
not_ok = True
if command.upper() in ["1. UPBIT", "1", "UPBIT"]:
if self.currency in self.UPBIT_CURRENCY:
self.data_provider = UpbitDataProvider(currency=self.currency)
self.trader = UpbitTrader(budget=self.budget, currency=self.currency)
not_ok = False
else:
self._send_text_message("현재 지원하지 않는 코인입니다.")
elif command.upper() in ["2. BITHUMB", "2", "BITHUMB"]:
if self.currency in self.BITHUMB_CURRENCY:
self.data_provider = BithumbDataProvider(currency=self.currency)
self.trader = BithumbTrader(budget=self.budget, currency=self.currency)
not_ok = False
else:
self._send_text_message("현재 지원하지 않는 코인입니다.")
return not_ok

def _start_trading(self, command):
"""초기화 후 자동 거래 시작"""
not_ok = True
Expand All @@ -254,21 +275,11 @@ def _start_trading(self, command):
except ValueError:
self.logger.info(f"invalid budget {command}")
elif self.in_progress_step == 2:
if command.upper() == "BTC":
self.currency = "BTC"
not_ok = False
elif command.upper() == "ETH":
self.currency = "ETH"
if command.upper() in self.AVAILABLE_CURRENCY:
self.currency = command.upper()
not_ok = False
elif self.in_progress_step == 3:
if command.upper() in ["1. UPBIT", "1", "UPBIT"]:
self.data_provider = UpbitDataProvider(currency=self.currency)
self.trader = UpbitTrader(budget=self.budget, currency=self.currency)
not_ok = False
elif command.upper() in ["2. BITHUMB", "2", "BITHUMB"]:
self.data_provider = BithumbDataProvider(currency=self.currency)
self.trader = BithumbTrader(budget=self.budget, currency=self.currency)
not_ok = False
not_ok = self._on_start_step3(command)
elif self.in_progress_step == 4:
if command.upper() in ["1. BUY AND HOLD", "1", "BUY AND HOLD", "BNH"]:
self.strategy = StrategyBuyAndHold()
Expand Down
2 changes: 1 addition & 1 deletion smtm/upbit_data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class UpbitDataProvider(DataProvider):
"""

URL = "https://api.upbit.com/v1/candles/minutes/1"
AVAILABLE_CURRENCY = {"BTC": "KRW-BTC", "ETH": "KRW-ETH"}
AVAILABLE_CURRENCY = {"BTC": "KRW-BTC", "ETH": "KRW-ETH", "DOGE": "KRW-DOGE", "XRP": "KRW-XRP"}

def __init__(self, currency="BTC"):
if currency not in self.AVAILABLE_CURRENCY:
Expand Down
2 changes: 1 addition & 1 deletion smtm/upbit_trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class UpbitTrader(Trader):

RESULT_CHECKING_INTERVAL = 5
ISO_DATEFORMAT = "%Y-%m-%dT%H:%M:%S"
AVAILABLE_CURRENCY = {"BTC": ("KRW-BTC", "BTC"), "ETH": ("KRW-ETH", "ETH")}
AVAILABLE_CURRENCY = {"BTC": ("KRW-BTC", "BTC"), "ETH": ("KRW-ETH", "ETH"), "DOGE": ("KRW-DOGE", "DOGE"), "XRP": ("KRW-XRP", "XRP")}
NAME = "Upbit"

def __init__(self, budget=50000, currency="BTC", commission_ratio=0.0005, opt_mode=True):
Expand Down
1 change: 1 addition & 0 deletions tests/strategy_sma_0_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class DummyMean:
mock_series.return_value = series_return

dummy_info = {
"date_time": "dummy_datetime",
"closing_price": 500,
}
mock_np.return_value = False
Expand Down

0 comments on commit 6f68ea3

Please sign in to comment.