def get(self, request, *args, **kwargs): try: datalist = StockSubs.objects.values('stocks_id__stock_name').all().order_by('stocks_id__stock_name') datalist = [p['stocks_id__stock_name'] for p in datalist] return JsonResponse({ 'content': '\n'.join(datalist) }, status = 200) except Exception: print_exception() return JsonResponse({ 'content': '띠용? 에러 발생' }, status = 400)
def get(self, request, *args, **kwargs): try: StockSubs.objects.subscribe(kwargs.get('stock_name')) return JsonResponse({ 'content': 'success' }, status = 201) except Stocks.DoesNotExist: return JsonResponse({ 'content': '주식명을 확인해주세요.' }, status = 400) except Exception: print_exception() return JsonResponse({ 'content': '띠용? 에러 발생' }, status = 400)
def get(self, request, *args, **kwargs): try: naver_news = RequestNaverNews() news_content = naver_news.parse_string_news(kwargs.get('stock_name')) return JsonResponse({ 'content': news_content }) except Exception: print_exception() return JsonResponse({ 'content': '띠용? 에러 발생' }, status = 400)
def post(self, request, *args, **kwargs): try: scrap = Scrap_Demand() scrap_data = scrap.scrap('https://finance.daum.net/quotes/A{stock_code}#influential_investors/home'.format(stock_code = self.kwargs['stock_code'])) demand_info_register(self.kwargs['stock_code'], demand_data = scrap_data) except Exception as e: print_exception() return JsonResponse({ 'code': '1111', 'msg': 'failure' }) return JsonResponse({ 'code': '0000', 'msg': 'success' })
def post(self, request, *args, **kwargs): try: scrap = Scrap_Consensus() scrap_data = scrap.scrap('https://wisefn.finance.daum.net/company/c1010001.aspx?cmp_cd={stock_code}'.format(stock_code = self.kwargs['stock_code'])) financial_info_register(self.kwargs['stock_code'], financial_data = scrap_data) except Exception as e: print_exception() return JsonResponse({ 'code': '1111', 'msg': 'failure' }) return JsonResponse({ 'code': '0000', 'msg': 'success' })
def get(self, request, *args, **kwargs): try: stock_price = StockPrice.objects.values('close_price', 'high_price', 'low_price').get( stocks_id = Stocks.objects.get(stock_name = kwargs.get('stock_name')).id, date = today_dateformat('%Y-%m-%d') ) return JsonResponse({ 'content': '[오늘 주가]\n시가 : {}\n고가 : {}\n저가 : {}'.format(stock_price['close_price'], stock_price['high_price'], stock_price['low_price']) }, status = 200) except Stocks.DoesNotExist: return JsonResponse({ 'content': '주식명을 확인해주세요.' }, status = 400) except StockPrice.DoesNotExist: return JsonResponse({ 'content': '해당 주식은 현재 주가를 추적중이지 않습니다.' }, status = 400) except Exception: print_exception() return JsonResponse({ 'content': '띠용? 에러 발생' }, status = 400)
def post(self, request, *args, **kwargs): """ 포트폴리오 종목 매입 """ portfolio_id = int(kwargs.get('portfolio_id')) stock_code = request.POST.get('stock_code') stock_name = request.POST.get('stock_name') purchase_count = int(request.POST.get('purchase_count')) purchase_date = request.POST.get('purchase_date') try: # 주식 가격정보가 없다면 생성 validate_portfolio_stock_price(stock_code, stock_name) transaction_purchase_stock(portfolio_id, purchase_count, purchase_date, stock_code) except Exception as e: print_exception() return alert(e.__str__()) return HttpResponseRedirect('/portfolios/{}'.format(portfolio_id))
def delete(self, request, *args, **kwargs): """ 포트폴리오 종목 매도 """ portfolio_id = int(kwargs.get('portfolio_id')) request_body = json.loads(request.body) purchase_date = request_body['purchase_date'] sell_count = int(request_body['sell_count']) sell_date = request_body['sell_date'] stock_code = request_body['stock_code'] try: transaction_sell_stock(portfolio_id, sell_count, sell_date, purchase_date, stock_code) except Exception as e: print_exception() # return JsonResponse({ 'code': '1000', 'msg': e.__str__() }, status = 400) return JsonResponse({'code': '1000', 'msg': e.__str__()}) return JsonResponse({'code': '0000', 'msg': 'success'})