예제 #1
0
 def get_order(self,
               ticker,
               state='wait',
               kind='normal',
               contain_req=False):
     """
     주문 리스트 조회
     :param ticker: market
     :param state: 주문 상태(wait, done, cancel)
     :param kind: 주문 유형(normal, watch)
     :param contain_req: Remaining-Req 포함여부
     :return:
     """
     # TODO : states, uuids, identifiers 관련 기능 추가 필요
     try:
         url = "https://api.upbit.com/v1/orders"
         data = {
             'market': ticker,
             'state': state,
             'kind': kind,
             'order_by': 'desc'
         }
         headers = self._request_headers(data)
         result = _send_get_request(url, headers=headers, data=data)
         if contain_req:
             return result
         else:
             return result[0]
     except Exception as x:
         print(x.__class__.__name__)
         return None
예제 #2
0
 def get_deposit_withdraw_status(self, contain_req=False):
     url = "https://api.upbit.com/v1/status/wallet"
     headers = self._request_headers()
     result = _send_get_request(url, headers=headers)
     if contain_req:
         return result
     else:
         return result[0]
예제 #3
0
 def get_api_key_list(self, contain_req=False):
     url = "https://api.upbit.com/v1/api_keys"
     headers = self._request_headers()
     result = _send_get_request(url, headers=headers)
     if contain_req:
         return result
     else:
         return result[0]
예제 #4
0
    def get_order(self,
                  ticker_or_uuid,
                  state='wait',
                  kind='normal',
                  contain_req=False):
        """
        주문 리스트 조회
        :param ticker: market
        :param state: 주문 상태(wait, done, cancel)
        :param kind: 주문 유형(normal, watch)
        :param contain_req: Remaining-Req 포함여부
        :return:
        """
        # TODO : states, identifiers 관련 기능 추가 필요
        try:
            p = re.compile(r"^\w+-\w+-\w+-\w+-\w+$")
            # 정확히는 입력을 대문자로 변환 후 다음 정규식을 적용해야 함
            # - r"^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$"
            is_uuid = len(p.findall(ticker_or_uuid)) > 0
            if is_uuid:
                url = "https://api.upbit.com/v1/order"
                data = {'uuid': ticker_or_uuid}
                headers = self._request_headers(data)
                result = _send_get_request(url, headers=headers, data=data)
            else:

                url = "https://api.upbit.com/v1/orders"
                data = {
                    'market': ticker_or_uuid,
                    'state': state,
                    'kind': kind,
                    'order_by': 'desc'
                }
                headers = self._request_headers(data)
                result = _send_get_request(url, headers=headers, data=data)

            if contain_req:
                return result
            else:
                return result[0]
        except Exception as x:
            print(x.__class__.__name__)
            return None
예제 #5
0
파일: coinpot2.py 프로젝트: leekw1st/python
 def get_balance(self):
     try:
         url = "https://api.upbit.com/v1/accounts"
         headers = self._request_headers()
         result = _send_get_request(url, headers=headers)
         return result[0]
     except Exception as x:
         print(x.__class__.__name__)
         print(traceback.format_exc())
         return None
예제 #6
0
파일: coinpot2.py 프로젝트: leekw1st/python
    def get_order_state(self, ticker, uuid):
        # TODO : states, uuids, identifiers 관련 기능 추가 필요
        try:
            url = "https://api.upbit.com/v1/orders"
            data = {
                'market': ticker,
                'state': 'wait',
                'uuid': uuid,
                'order_by': 'desc'
            }
            headers = self._request_headers(data)
            result = _send_get_request(url, headers=headers, data=data)

            if result[0]:
                tmp_time = result[0][0]['created_at'][0:10] + ' ' + result[0][
                    0]['created_at'][11:19]
                time_term = datetime.datetime.now(
                ) - datetime.datetime.strptime(tmp_time, '%Y-%m-%d %H:%M:%S')
                time_term_sec = time_term.seconds % 60
                if time_term_sec > 3:
                    return 'cancel'
                else:
                    return 'wait'

            elif not result[0]:
                data = {
                    'market': ticker,
                    'state': 'done',
                    'uuid': uuid,
                    'order_by': 'desc'
                }
                headers = self._request_headers(data)
                result = _send_get_request(url, headers=headers, data=data)

            return result[0][0]['state']

        except Exception as x:
            print(x.__class__.__name__)
            print(traceback.format_exc())
            return None
예제 #7
0
 def get_balances(self, contain_req=False):
     """
     전체 계좌 조회
     :param contain_req: Remaining-Req 포함여부
     :return: 내가 보유한 자산 리스트
     [contain_req == True 일 경우 Remaining-Req가 포함]
     """
     url = "https://api.upbit.com/v1/accounts"
     headers = self._request_headers()
     result = _send_get_request(url, headers=headers)
     if contain_req:
         return result
     else:
         return result[0]
예제 #8
0
    def get_holding_coin_cnt(self):
        try:
            holding_coin_cnt = 0
            url = "https://api.upbit.com/v1/accounts"
            headers = self._request_headers()
            result = _send_get_request(url, headers=headers)
            asset_list = result[0]
            holding_coin_cnt = len(asset_list) - 1

            _LOG_("get_holding_coin_cnt()", f"보유코인갯수:{holding_coin_cnt}")

            return holding_coin_cnt

        except Exception as x:
            print(x.__class__.__name__)
            print(traceback.format_exc())
            return None
예제 #9
0
 def get_balances(self, contain_req=False):
     """
     전체 계좌 조회
     :param contain_req: Remaining-Req 포함여부
     :return: 내가 보유한 자산 리스트
     [contain_req == True 일 경우 Remaining-Req가 포함]
     """
     try:
         url = "https://api.upbit.com/v1/accounts"
         headers = self._request_headers()
         result = _send_get_request(url, headers=headers)
         if contain_req:
             return result
         else:
             return result[0]
     except Exception as x:
         print(x.__class__.__name__)
         return None
예제 #10
0
파일: coinpot2.py 프로젝트: leekw1st/python
    def get_coin_count(self, ticker):
        try:
            url = "https://api.upbit.com/v1/accounts"
            headers = self._request_headers()
            result = _send_get_request(url, headers=headers)
            asset_list = result[0]
            asset_list_length = len(asset_list)

            for i in range(asset_list_length):
                currency = asset_list[i]['currency']

                if 'KRW-' + currency == ticker:
                    balance = float(asset_list[i]['balance'])
                    return balance

        except Exception as x:
            print(x.__class__.__name__)
            print(traceback.format_exc())
            return None
예제 #11
0
파일: coinpot2.py 프로젝트: leekw1st/python
    def get_account_status(self):
        try:
            url = "https://api.upbit.com/v1/accounts"
            headers = self._request_headers()
            result = _send_get_request(url, headers=headers)
            asset_list = result[0]
            asset_list_length = len(asset_list)
            total_asset = 0
            total_buy_price = 0
            total_coin_price = 0

            for i in range(asset_list_length):
                currency = asset_list[i]['currency']
                balance = float(asset_list[i]['balance'])
                avg_buy_price = float(asset_list[i]['avg_buy_price'])

                if currency == 'KRW':
                    print("보유원화:", currency, ", 평가금액 : ", balance)
                    total_asset = total_asset + balance
                else:
                    price = pyupbit.get_current_price('KRW-' + currency)
                    print(
                        "보유코인:", currency, ", 보유수량 : ", balance, ", 평가금액 : ",
                        price * balance, ", 매수평균가 : ", avg_buy_price,
                        ", 매수금액 : ", balance * avg_buy_price, ", 평가손익 : ",
                        price * balance - balance * avg_buy_price, "[",
                        round((price * balance - avg_buy_price * balance) /
                              (avg_buy_price * balance) * 100, 2), "]")
                    total_asset = total_asset + price * balance
                    total_buy_price = total_buy_price + (avg_buy_price *
                                                         balance)
                    total_coin_price = total_coin_price + (price * balance)

            print(
                "총 보유자산 : ", total_asset, ", 총 매수금액 : ", total_buy_price,
                ", 총 평가금액 : ", total_coin_price, ", 총 평가손익 : ",
                total_coin_price - total_buy_price, "[",
                round((total_coin_price - total_buy_price) / total_buy_price *
                      100, 2), "]")
        except Exception as x:
            print(x.__class__.__name__)
            print(traceback.format_exc())
            return None
예제 #12
0
    def get_deposit_list(self, currency: str, contain_req=False):
        """
        입금 리스트 조회
        :currency: Currency 코드
        :param contain_req: Remaining-Req 포함여부
        :return:
        """
        try:
            url = "https://api.upbit.com//v1/deposits"
            data = {"currency": currency}
            headers = self._request_headers(data)

            result = _send_get_request(url, headers=headers, data=data)
            if contain_req:
                return result
            else:
                return result[0]
        except Exception as x:
            print(x.__class__.__name__)
            return None
예제 #13
0
 def get_wallet_address(self, currency, contain_req=False):
     """
     마켓별 주문 가능 정보를 확인.
     :param ticker:
     :param contain_req: Remaining-Req 포함여부
     :return: 마켓별 주문 가능 정보를 확인
     [contain_req == True 일 경우 Remaining-Req가 포함]
     """
     try:
         url = "https://api.upbit.com/v1/deposits/coin_address"
         data = {"currency": currency}
         headers = self._request_headers(data)
         result = _send_get_request(url, headers=headers, data=data)
         if contain_req:
             return result
         else:
             return result[0]
     except Exception as x:
         print(x.__class__.__name__)
         return None
예제 #14
0
 def get_individual_order(self, uuid, contain_req=False):
     """
     주문 리스트 조회
     :param uuid: 주문 id
     :param contain_req: Remaining-Req 포함여부
     :return:
     """
     # TODO : states, uuids, identifiers 관련 기능 추가 필요
     try:
         url = "https://api.upbit.com/v1/order"
         data = {'uuid': uuid}
         headers = self._request_headers(data)
         result = _send_get_request(url, headers=headers, data=data)
         if contain_req:
             return result
         else:
             return result[0]
     except Exception as x:
         print(x.__class__.__name__)
         return None
예제 #15
0
 def get_chance(self, ticker, contain_req=False):
     """
     마켓별 주문 가능 정보를 확인.
     :param ticker:
     :param contain_req: Remaining-Req 포함여부
     :return: 마켓별 주문 가능 정보를 확인
     [contain_req == True 일 경우 Remaining-Req가 포함]
     """
     try:
         url = "https://api.upbit.com/v1/orders/chance"
         data = {"market": ticker}
         headers = self._request_headers(data)
         result = _send_get_request(url, headers=headers, data=data)
         if contain_req:
             return result
         else:
             return result[0]
     except Exception as x:
         print(x.__class__.__name__)
         return None
예제 #16
0
 def get_individual_withdraw_order(self, uuid: str, currency: str, contain_req=False):
     """
     개별 출금 조회
     :param uuid: 출금 UUID
     :param currency: Currency 코드
     :param contain_req: Remaining-Req 포함여부
     :return:
     """
     try:
         url = "https://api.upbit.com/v1/withdraw"
         data = {"uuid": uuid, "currency": currency}
         headers = self._request_headers(data)
         result = _send_get_request(url, headers=headers, data=data)
         if contain_req:
             return result
         else:
             return result[0]
     except Exception as x:
         print(x.__class__.__name__)
         return None
예제 #17
0
파일: coinpot2.py 프로젝트: leekw1st/python
    def status_check(self, ticker):
        try:
            url = "https://api.upbit.com/v1/accounts"
            headers = self._request_headers()
            result = _send_get_request(url, headers=headers)
            asset_list = result[0]
            asset_list_length = len(asset_list)

            if asset_list_length > 0:
                for x in asset_list:
                    currency = x['currency']
                    coin = 'KRW-' + x['currency']
                    balance = float(x['balance'])
                    avg_buy_price = float(x['avg_buy_price'])

                    if coin == ticker and ticker != 'KRW':
                        price = pyupbit.get_current_price('KRW-' + currency)
                        rate = round(
                            (price * balance - avg_buy_price * balance) /
                            (avg_buy_price * balance) * 100, 2)

                        if rate > 3:
                            signal = 'upsell'
                        elif rate < -2:
                            signal = 'downsell'
                        else:
                            signal = 'hold'

                        _LOG_("status_check()",
                              f"코인:{coin}, 수익률:{rate}, 주문신호:{signal}")

                        return signal

            return 'Not Exist'

        except Exception as x:
            print(x.__class__.__name__)
            print(traceback.format_exc())
            return None