def handle_stockstatus(): c = Creon() c.avoid_reqlimitwarning() stockcode = request.args.get('code') if not stockcode: return '', 400 status = c.get_stockstatus(stockcode) return jsonify(status)
def handle_short(): c = Creon() c.avoid_reqlimitwarning() stockcode = request.args.get('code') n = request.args.get('n') if not stockcode: return '', 400 stockfeatures = c.get_shortstockselling(stockcode, n=n) return jsonify(stockfeatures)
def handle_stockcandles(): c = Creon() c.avoid_reqlimitwarning() stockcode = request.args.get('code') n = request.args.get('n') date_from = request.args.get('date_from') date_to = request.args.get('date_to') if not (n or date_from): return 'Need to provide "n" or "date_from" argument.', 400 stockcandles = c.get_chart(stockcode, target='A', unit='D', n=n, date_from=date_from, date_to=date_to) return jsonify(stockcandles)
def handle_stockcodes(): c = Creon() c.avoid_reqlimitwarning() market = request.args.get('market') if market == 'kospi': return jsonify(c.get_stockcodes(constants.MARKET_CODE_KOSPI)) elif market == 'kosdaq': return jsonify(c.get_stockcodes(constants.MARKET_CODE_KOSDAQ)) else: return '"market" should be one of "kospi" and "kosdaq".', 400
def handle_connect(): c = Creon() if request.method == 'GET': # check connection status return jsonify(c.connected()) elif request.method == 'POST': # make connection data = request.get_json() _id = data['id'] _pwd = data['pwd'] _pwdcert = data['pwdcert'] return jsonify(c.connect(_id, _pwd, _pwdcert)) elif request.method == 'DELETE': # disconnect res = c.disconnect() c.kill_client() return jsonify(res)
from flask import Flask, request, jsonify from creon import Creon import constants app = Flask(__name__) c = Creon() @app.route('/connection', methods=['GET', 'POST', 'PUT', 'DELETE']) def handle_connect(): if request.method == 'GET': # check connection status return jsonify(c.connected()) elif request.method == 'POST': # make connection data = request.get_json() _id = data['id'] _pwd = data['pwd'] _pwdcert = data['pwdcert'] return jsonify(c.connect(_id, _pwd, _pwdcert)) elif request.method == 'DELETE': # disconnect return jsonify(c.disconnect()) @app.route('/stockcodes', methods=['GET']) def handle_stockcodes(): c.wait() market = request.args.get('market') if market == 'kospi': return jsonify(c.get_stockcodes(constants.MARKET_CODE_KOSPI))