def getOrder(self): if( self.wait_order_uuids == ''): return query = { 'uuid': self.wait_order_uuids } query_string = urlencode(query).encode() m = hashlib.sha512() m.update(query_string) query_hash = m.hexdigest() payload = { 'access_key': self.access_key, 'nonce': str(uuid.uuid4()), 'query_hash': query_hash, 'query_hash_alg': 'SHA512', } jwt_token = jwt.encode(payload, self.secret_key) authorize_token = 'Bearer {}'.format(jwt_token) headers = {"Authorization": authorize_token} url = self.server_url + "/v1/order" try: response = requests.get( url, params=query, headers=headers) pass except requests.exceptions.SSLError: print("ssl error") return None except: print("except") return None else: if( response.status_code != 200): result = response.json() printLog = '{} return: {} \n{} \n{}\n'.format( util.whoami(), response.status_code , query, json.dumps( result, indent=2, sort_keys=True) ) # util.save_log(printLog, subject= ( "에러응답" ) ) print(printLog) return None else: result = response.json() if( result['state'] == 'done' or result['state'] == 'cancel' ): self.wait_order_uuids = '' printLog = '{} return: {} \n{} \n{}\n'.format( util.whoami(), response.status_code , query, json.dumps( result, indent=2, sort_keys=True) ) print( printLog ) pass
def getDayCandle(self, last_date_time_to ): url = self.server_url + "/v1/candles/days" query = {"market": self.market_code, "count": 200, "to": last_date_time_to } try: response = requests.get( url, params= query) except requests.exceptions.SSLError: print("ssl error") return None except: print("except") return None else: if( response.status_code != 200): printLog = '{} {} {} {} {}'.format( util.whoami(), response.status_code , "error return: ", query, response.text ) print(printLog) return None else: result = [] output_list = response.json() del_key = ['timestamp', 'candle_acc_trade_price', 'candle_acc_trade_volume', 'prev_closing_price', 'change_price', 'change_rate', 'candle_date_time_utc'] for item in output_list: list( map(item.pop, del_key) ) result.append( item ) return result
def standbyStateEntered(self): print(util.whoami()) self.timerRequestAccountInfo.start() self.sigStyleSheetChanged.emit( " QMainWindow {" " background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #007f00, stop: 1 #aaffaa); " "}")
def initStateEntered(self): print(util.whoami()) self.timerRequestOrderbook.start() self.timerRequestAccountInfo.stop() self.sigStyleSheetChanged.emit( " QMainWindow {" " background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #ff0000, stop: 1 #ffff00); " "}")
def getAccountInfo(self): # 전체 계좌 조회 ''' [ { "avg_buy_price": "0", "avg_buy_price_modified": true, "balance": "2.27593723", "currency": "KRW", "locked": "0.0", "unit_currency": "KRW" }, { "avg_buy_price": "217.4", "avg_buy_price_modified": false, "balance": "1.13438041", "currency": "XRP", "locked": "0.0", "unit_currency": "KRW" } ] ''' payload = { 'access_key': self.access_key, 'nonce': str(uuid.uuid4()), } jwt_token = jwt.encode(payload, self.secret_key) authorize_token = 'Bearer {}'.format(jwt_token) headers = {"Authorization": authorize_token} url = self.server_url + "/v1/accounts" try: response = requests.get(url, headers=headers) except requests.exceptions.SSLError: print("ssl error") return None except: print("except") return None else: if( response.status_code != 200): printLog = '{} {} {} {}'.format( util.whoami(), response.status_code , "error return: ", response.text ) util.save_log(printLog) print(printLog) return None else: output_list = response.json() return output_list
def makeJangoInfoFile(self): print(util.whoami()) remove_keys = [ '매도호가1', '매도호가2', '매도호가수량1', '매도호가수량2', '매도호가총잔량', '매수호가1', '매수호가2', '매수호가수량1', '매수호가수량2', '매수호가수량3', '매수호가수량4', '매수호가총잔량', '현재가', '호가시간', '세금', '전일종가', '현재가', '종목번호', '수익율', '수익', '잔고', '매도중', '시가', '고가', '저가', '장구분', '거래량', '등락율', '전일대비', '기준가', '상한가', '하한가', '5분봉타임컷기준' ] temp = copy.deepcopy(self.jangoInfo) # 불필요 필드 제거 for jongmok_code, contents in temp.items(): for key in remove_keys: if (key in contents): del contents[key] with open(JANGO_INFO_FILE_PATH, 'a', encoding='utf8') as f: f.write( json.dumps(temp, ensure_ascii=False, indent=2, sort_keys=True)) pass
def getOrderbook(self): # 시세 조회, 호가 조회 url = self.server_url + "/v1/orderbook" query = {"markets": self.market_code } try: response = requests.get( url, params= query) except requests.exceptions.SSLError: print("ssl error") return None except: print("except") return None else: if( response.status_code != 200): printLog = '{} {} {} {} {}'.format( util.whoami(), response.status_code , "error return:\n\n", query, response.text ) util.save_log(printLog) print(printLog) return None else: output_list = response.json() self.current_order_book = output_list # print(json.dumps( output_list, indent=2, sort_keys=True) ) return output_list
def makeOrder(self, order_type, order_price, order_balance, test = True): query = '' volume = 0 # for test if( order_type == 'none' or order_price == 0 or order_balance == 0): return None # 시장가 주문 # 시장가 주문은 ord_type 필드를 price or market 으로 설정해야됩니다. # 매수 주문의 경우 ord_type을 price로 설정하고 volume을 null 혹은 제외해야됩니다. # 매도 주문의 경우 ord_type을 market로 설정하고 price을 null 혹은 제외해야됩니다. # price 주문 가격. (지정가, 시장가 매수 시 필수) # ex) KRW-BTC 마켓에서 1BTC당 1,000 KRW로 거래할 경우, 값은 1000 이 된다. # ex) KRW-BTC 마켓에서 1BTC당 매도 1호가가 500 KRW 인 경우, 시장가 매수 시 값을 1000으로 세팅하면 2BTC가 매수된다. # (수수료가 존재하거나 매도 1호가의 수량에 따라 상이할 수 있음) if( order_type == 'bid' ): # 암호화폐 시장가 매수 # 주의: 시장가 매수시 volume 정보 없이 매수하고자 하는 총 금액을 입력 한다 # volume = round(order_balance / order_price, 2) query = { 'market': self.market_code, 'side': order_type, # 'volume': volume, 'price': str(int( order_balance) ), 'ord_type': 'price', } else: # 암호화폐 시장가 매도 volume = round(order_balance / order_price, 2) query = { 'market': self.market_code, 'side': order_type, 'volume': volume, # 'price': str(order_price), 'ord_type': 'market', } query_string = urlencode(query).encode() m = hashlib.sha512() m.update(query_string) query_hash = m.hexdigest() payload = { 'access_key': self.access_key, 'nonce': str(uuid.uuid4()), 'query_hash': query_hash, 'query_hash_alg': 'SHA512', } jwt_token = jwt.encode(payload, self.secret_key) authorize_token = 'Bearer {}'.format(jwt_token) headers = {"Authorization": authorize_token} url = self.server_url + "/v1/orders" try: if( test == True ): query = '' response = requests.post( url, params=query, headers=headers) pass except requests.exceptions.SSLError: print("ssl error") return None except: print("except") return None else: if( response.status_code != 201): result = response.json() printLog = '{} return: {} \n{} \n{}\n'.format( util.whoami(), response.status_code , query, json.dumps( result, indent=2, sort_keys=True) ) util.save_log(printLog, subject= ( "에러응답" ) ) return None else: result = response.json() self.wait_order_uuids = result['uuid'] printLog = '{} return: {} \n{} \n{}\n'.format( util.whoami(), response.status_code , query, json.dumps( result, indent=2, sort_keys=True) ) # print( printLog ) # util.save_log(printLog, subject= ( "요청" ) ) pass
def refresh(self): leftTopIndex = self.index(0, 0) print("%s row count %s col count %s" % (util.whoami(), self.rowCount(), self.columnCount())) rightBottomIndex = self.index(self.rowCount(), self.columnCount()) self.dataChanged.emit(leftTopIndex, rightBottomIndex)
def refresh(self): leftTopIndex = self.index(0, 0) print("%s row count %s col count %s" % ( util.whoami(), self.rowCount(), self.columnCount() )) rightBottomIndex = self.index(self.rowCount(), self.columnCount()) self.dataChanged.emit(leftTopIndex, rightBottomIndex)
def finalStateEntered(self): print(util.whoami())