class TestEbest(unittest.TestCase): def setUp(self): self.ebest = EBest("DEMO") self.ebest.login() # def test_get_credit_trend_by_code(self): # print(inspect.stack()[0][3]) # result = self.ebest.get_credit_trend_by_code("005830", "20190222") # assert result is not None # print(result) # # def test_get_short_trend_by_code(self): # print(inspect.stack()[0][3]) # result = self.ebest.get_short_trend_by_code( # "005930", sdate="20181201", edate="20181231" # ) # assert result is not None # print(result) # # def test_get_agent_trend_by_code(self): # print(inspect.stack()[0][3]) # result = self.ebest.get_agent_trend_by_code( # "005930", fromdt="20181201", todt="20181231" # ) # assert result is not None # print(result) # # def test_get_code_list(self): # print(inspect.stack()[0][3]) # all_result = self.ebest.get_code_list("ALL") # assert all_result is not None # kospi_result = self.ebest.get_code_list("KOSPI") # assert kospi_result is not None # kosdaq_result = self.ebest.get_code_list("KOSDAQ") # assert kosdaq_result is not None # try: # error_result = self.ebest.get_code_list("KOS") # except: # error_result = None # assert error_result is None # print("result:", len(all_result), len(kosdaq_result), len(kospi_result)) # # def test_get_stock_price_list_by_code(self): # print(inspect.stack()[0][3]) # result = self.ebest.get_stock_price_by_code("005930", "2") # assert result is not None # print(result) # def test_get_account_info(self): # result = self.ebest.get_account_info() # assert result is not None # print(result) def test_get_account_stock_info(self): result = self.ebest.get_account_stock_info() assert result is not None print(result) def tearDown(self): self.ebest.logout()
def collect_stock_info(): ebest = EBest("DEMO") mongodb = MongoDBHandler() ebest.login() code_list = mongodb.find_items({}, "stocklab", "code_info") target_code = set([item["단축코드"] for item in code_list]) today = datetime.today().strftime("%Y%m%d") print(today) collect_list = mongodb.find_items({"날짜":today}, "stocklab", "price_info") \ .distinct("code") for col in collect_list: target_code.remove(col) for code in target_code: time.sleep(1) print("code:", code) result_price = ebest.get_stock_price_by_code(code, "1") if len(result_price) > 0: print(result_price) mongodb.insert_items(result_price, "stocklab", "price_info") result_credit = ebest.get_credit_trend_by_code(code, today) if len(result_credit) > 0: mongodb.insert_items(result_credit, "stocklab", "credit_info") result_short = ebest.get_short_trend_by_code(code, sdate=today, edate=today) if len(result_short) > 0: mongodb.insert_items(result_short, "stocklab", "short_info") result_agent = ebest.get_agent_trend_by_code(code, fromdt=today, todt=today) if len(result_agent) > 0: mongodb.insert_items(result_agent, "stocklab", "agent_info")
def collect_code_list(): ebest = EBest("DEMO") mongodb = MongoDBHandler() ebest.login() result = ebest.get_code_list("ALL") mongodb.delete_items({}, "stocklab", "code_info") mongodb.insert_items(result, "stocklab", "code_info")
class TestEBest(unittest.TestCase): def setUp(self): self.ebest = EBest("DEMO") self.ebest.login() def test_get_code_list(self): print(inspect.stack()[0][3]) all_result = self.ebest.get_code_list("ALL") assert all_result is not None kospi_result = self.ebest.get_code_list("KOSPI") assert kospi_result is not None kosdaq_result = self.ebest.get_code_list("KOSDAQ") assert kosdaq_result is not None try: error_result = self.ebest.get_code_list("KOS") except: error_result = None assert error_result is None print("result : ", len(all_result), len(kospi_result), len(kosdaq_result)) # def test_get_stock_price_by_code(self): # print(inspect.stack()[0][3]) # result = self.ebest.get_stock_price_by_code("005930", "30") # assert result is not None # print(result) def tearDown(self): self.ebest.logout()
class TestEBest(unittest.TestCase): # 하나의 테스트 케이스가 실행되기 전에는 setUp 메서드가 호출되고, # 테스트 케이스가 수행된 이후에는 tearDown 메서드가 호출. def setUp(self): # EBest 클래스의 인스턴스(self.ebest) 생성 self.ebest = EBest("DEMO") self.ebest.login() def tearDown(self): self.ebest.logout()
class TestEBest(unittest.TestCase): def setUp(self): print("setUp") self.ebest = EBest("DEMO") self.ebest.login() def tearDown(self): print("tearDown") self.ebest.logout() """ def test_get_code_list(self): print(inspect.stack()[0][3]) all_result = self.ebest.get_code_list("ALL") assert all_result is not None kosdaq_result = self.ebest.get_code_list("KOSDAQ") assert kosdaq_result is not None kospi_result = self.ebest.get_code_list("KOSPI") assert kospi_result is not None try : error_result = self.ebest.get_code_list("KOS") except : error_result = None assert error_result is None print("result:", len(all_result), len(kosdaq_result), len(kospi_result)) """ def test_get_stock_price_list_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_stock_price_by_code("005930", "2") assert result is not None print(result) def test_get_credit_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_credit_trend_by_code("005930", "20201001") assert result is not None print(result) def test_get_short_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_short_trend_by_code("005930", sdate="20200901", edate="20200930") assert result is not None print(result) def test_get_agent_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_agent_trend_by_code("005930", fromdt="20200901", todt="20200930") assert result is not None print(result)
class TestEBest(unittest.TestCase): def setUp(self): print("setUp") self.ebest = EBest("DEMO") self.ebest.login() def tearDown(self): self.ebest.logout() def test_get_price_n_min_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_price_n_min_by_code("20200303", "180640") assert result print(result) def test_get_price_n_min_by_code_tick(self): print(inspect.stack()[0][3]) result = self.ebest.get_price_n_min_by_code("20200303", "005930", 0) assert result print(result) """
import time from datetime import datetime, timedelta from apscheduler.schedulers.background import BackgroundScheduler from stocklab.agent.ebest import EBest from stocklab.db_handler.mongodb_handler import MongoDBHandler from multiprocessing import Process import pandas as pd ''' python -m stocklab.scheduler.trading_5m ''' ebest_trade = EBest("PROD") ebest_trade.login() mongo = MongoDBHandler() def run_process_trading_scenario(code_list): p = Process(target=trading_scenario, args=(code_list,)) p.start() p.join() print("run process join") def run_process_collect_stock_info(code_list): p = Process(target=collect_stock_m_info, args=(code_list,)) p.start() p.join() print(">>> run process run_process_collect_stock_info")
class TestEBest(unittest.TestCase): def setUp(self): self.ebest = EBest("DEMO") self.ebest.login() """ def test_get_code_list(self): print(inspect.stack()[0][3]) # 실행하는 메서드의 이름 출력 all_result = self.ebest.get_code_list("ALL") assert all_result is not None kosdaq_result = self.ebest.get_code_list("KOSDAQ") assert kosdaq_result is not None kospi_result = self.ebest.get_code_list("KOSPI") assert kospi_result is not None try: error_result = self.ebest.get_code_list("KOS") except: error_result = None assert error_result is None print("result : ", len(all_result), len(kosdaq_result), len(kospi_result)) def test_get_stock_price_list_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_stock_price_by_code("005930", "2") # 삼성전자(005930)의 최근 2일 치 데이터를 조회 assert result is not None print(result) def test_get_credit_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_credit_trend_by_code("005930", "20190304") assert result is not None print(result) def test_get_short_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_short_trend_by_code("005930", sdate="20190304", edate="20190304") assert result is not None print(result) def test_get_agent_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_agent_trend_by_code("005930", fromdt="20190304", todt="20190304") assert result is not None print(result) def test_get_account_info(self): print(inspect.stack()[0][3]) result = self.ebest.get_account_info() assert result print(result) def test_get_account_stock_info(self): result = self.ebest.get_account_stock_info() assert result is not None print(result) def test_order_stock(self): print(inspect.stack()[0][3]) result = self.ebest.order_stock("005930", "2", "46000", "2", "00") assert result print(result) def test_order_cancel(self): print(inspect.stack()[0][3]) result = self.ebest.order_cancel("29515", "A005930", "2") assert result print(result) def test_order_check(self): print(inspect.stack()[0][3]) result = self.ebest.order_check("29515") assert result print(result) def test_get_current_call_price_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_current_call_price_by_code("005930") assert result print(result) def test_get_price_n_min_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_price_n_min_by_code("20200501", "180640") assert result print(result) def test_get_price_n_min_by_code_tick(self): print(inspect.stack()[0][3]) result = self.ebest.get_price_n_min_by_code("20200501", "005930", 0) assert result print(result) """ def tearDown(self): self.ebest.logout()
class TestEBest(unittest.TestCase): def setUp(self): self.ebest = EBest("DEMO") self.ebest.login() def tearDown(self): self.ebest.logout() """ def test_get_code_list(self): print(inspect.stack()[0][3]) all_result = self.ebest.get_code_list("ALL") assert all_result is not None kosdaq_result = self.ebest.get_code_list("KOSDAQ") assert kosdaq_result is not None kospi_result = self.ebest.get_code_list("KOSPI") assert kospi_result is not None try: error_result = self.ebest.get_code_list("KOS") except: error_result = None assert error_result is None print("result:", len(all_result), len(kosdaq_result), len(kospi_result)) def test_get_stock_price_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_stock_price_by_code("005930","2") assert result is not None print(result) def test_agent_account_info(self): result = self.ebest.get_account_info() assert result is not None print(result) def test_agent_account_stock_info(self): result = self.ebest.get_accout_stock_info() assert result is not None print(result) def test_order_stock(self): print(inspect.stack() [0][3]) result = self.ebest.order_stock("005930", "2", "48000", "2", "00") assert result print(result) def test_order_cancel(self): print(inspect.stack()[0][3]) result = self.ebest.order_cancel("32957", "A005930", "1") assert result print(result) def test_order_check(self): print(inspect.stack()[0][3]) result = self.ebest.order_check("32957") assert result print(result) def test_get_current_call_price_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_current_call_price_by_code("005930") assert result print(result) def test_get_price_n_min_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_price_n_min_by_code("20190412", "180640") assert result print(result) """ """
from stocklab.agent.ebest import EBest from stocklab.agent.data import Data import chardet from pyspark.sql import SparkSession from pyspark.sql.functions import col, lit # 2021-05-02 별도 DB 연결은 제거 하고 parquet 파일 기반으로 변경 #from stocklab.db_handler.mongodb_handler import MongoDBHandler #from stocklab.db_handler.cosmosdb_handler import CosmosDBHandler' ''' python -m stocklab.scheduler.data_collector_1m ''' ebest = EBest("PROD") ebest.login() #mongodb = MongoDBHandler() spark = SparkSession.builder.appName("create data").getOrCreate() def collect_stock_min(sdate): # >> 날짜별로 조회 ''' code_list = mongodb.find_items({}, "stocklab", "code_prod") target_code = set([item["shcode"] for item in code_list]) today = datetime.today().strftime("%Y%m%d") # delete data collect_list = mongodb.find_items({"date":today}, "stocklab", "price_min").distinct("code") ''' #spark.read.csv("s3a://mfas-artifact-seoul/glue/tmp/" + file_name2, header = True, inferSchema='false', multiLine=True, quote='"', escape='\\', sep=',',ignoreLeadingWhiteSpace='true',ignoreTrailingWhiteSpace='true',mode='FAILFAST', encoding="UTF-8")
def get(self, id=None): if id: print("get method id :" + str(id)) # 종목코드 가져오기 if id == 1: ebest = EBest("DEMO") ebest.login() result_cod = ebest.get_code_list("ALL") print("get_code_list", len(result_cod)) result_ext_all = [] i = 0 if len(result_cod) > 0: print("t8407 주식현재가 시작") str_codes = "" for code in result_cod: str_codes = str_codes + code["단축코드"] i = i + 1 if len(str_codes) >= 300 or len(result_cod) == i: result_ext = ebest.get_current_price_by_shcodes( str_codes) result_ext_all.extend(result_ext) print("result_ext_all 건수", len(result_ext_all)) str_codes = "" # 코드정보와 주식현재가 병합 for code in result_cod: for extend in result_ext_all: if code["단축코드"] == extend["종목코드"]: code.update(extend) print("result_cod 건수", len(result_cod)) mongodb = MongoDBHandler() mongodb.delete_items({}, "stocklab", "code_info") mongodb.insert_items(result_cod, "stocklab", "code_info") # collect_code_list() # collect_stock_info() return { "errcode": 0, "errmsg": str(len(result_cod)) + " 건이 정상처리 되었습니다." } # 종목가격정보 가져오기 elif id == 2: ebest = EBest("DEMO") ebest.login() code_list = mongodb.find_items({}, "stocklab", "code_info") target_code = set([item["단축코드"] for item in code_list]) today = datetime.today().strftime("%Y%m%d") collect_list = mongodb.find_items({ "날짜": today }, "stocklab", "price_info").distinct("code") for col in collect_list: target_code.remove(col) for code in target_code: result_price = ebest.get_stock_price_by_code(code, "1") time.sleep(1) if len(result_price) > 0: mongodb.insert_items(result_price, "stocklab", "price_info") return { "errcode": 0, "errmsg": str(len(result)) + " 건이 정상처리 되었습니다." } # 모든 종목정보 가져오기 elif id == 3: ebest = EBest("DEMO") mongodb = MongoDBHandler() ebest.login() code_list = mongodb.find_items({}, "stocklab", "code_info") target_code = set([item["단축코드"] for item in code_list]) today = datetime.today().strftime("%Y%m%d") print(today) collect_list = mongodb.find_items({ "날짜": today }, "stocklab", "price_info").distinct("code") for col in collect_list: target_code.remove(col) for code in target_code: time.sleep(1) print("code:", code) result_price = ebest.get_stock_price_by_code(code, "1") if len(result_price) > 0: print(result_price) mongodb.insert_items(result_price, "stocklab", "price_info") result_credit = ebest.get_credit_trend_by_code(code, today) if len(result_credit) > 0: mongodb.insert_items(result_credit, "stocklab", "credit_info") result_short = ebest.get_short_trend_by_code(code, sdate=today, edate=today) if len(result_short) > 0: mongodb.insert_items(result_short, "stocklab", "short_info") result_agent = ebest.get_agent_trend_by_code(code, fromdt=today, todt=today) if len(result_agent) > 0: mongodb.insert_items(result_agent, "stocklab", "agent_info") # 일자별 주가정보에서 평균 거래량 가져오기(거래량 증가 종목 찾기) elif id == 4: ebest = EBest("DEMO") ebest.login() mongodb = MongoDBHandler() code_list = list( mongodb.find_items({}, "stocklab", "code_info")) target_code = set([item["단축코드"] for item in code_list]) # print(target_code) today = datetime.today().strftime("%Y%m%d") fromday = (datetime.today() - timedelta(days=30)).strftime("%Y%m%d") print(len(code_list)) inc_codes = [] vol_codes = [] loop_cnt = 0 for code in code_list: if int(code["누적거래량"]) < 10000: continue loop_cnt = loop_cnt + 1 if loop_cnt % 100 == 0 and len(inc_codes) > 0: print(str(loop_cnt % 100) + "//" + str(len(inc_codes))) print(code["단축코드"] + "진행율 : " + str((loop_cnt / len(code_list) * 100))) mongodb.insert_items(inc_codes, "stocklab", "check_volume") inc_codes.clear() results = ebest.get_stock_chart_by_code( code["단축코드"], "2", fromday, today) time.sleep(1) if len(results) > 0: # 평균 거래량 계산 tot_volume = 0 i_count = 0 for result in results: if int(result['거래량']) != 0: tot_volume = tot_volume + int(result['거래량']) i_count = i_count + 1 if i_count == 0 or tot_volume == 0: continue avg_volume = tot_volume / i_count inc_rate = int(result['거래량']) / avg_volume inc_code = { "code": code["단축코드"], "종목명": code["종목명"], "sdate": today, "avg_volume": int(avg_volume), "volume": int(result['거래량']) } vol_codes.append(inc_code) print("체크 종목 :" + code["종목명"] + " 거래량 [" + result['거래량'] + "] 평균 [" + str(avg_volume) + "] 비율[" + str(inc_rate) + "]") # 거래량이 5배 이상이면 종목 추가 if inc_rate > 5: inc_codes.append(inc_code) print("추가된 종목 :" + code["종목명"] + " 건수 : " + str(len(inc_codes))) if len(inc_codes) > 0: mongodb.insert_items(inc_codes, "stocklab", "check_volume") mongodb.insert_items(vol_codes, "stocklab", "volume") return { "errcode": 0, "errmsg": str(len(vol_codes)) + " 건이 정상처리 되었습니다." } elif id == 5: print("Error Id : " + str(id)) else: print("Error Id : " + str(id)) else: print("list of users") # collect_code_list() # collect_stock_info() return "list of users"
class TestEbest(unittest.TestCase): def setUp(self): self.ebest = EBest("DEMO") self.ebest.login() def test_get_current_call_price_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_current_call_price_by_code("005930") assert result print(result) # def test_get_code_list(self): # print(inspect.stack()[0][3]) # all_result = self.ebest.get_code_list("ALL") # assert all_result is not None # kosdaq_result = self.ebest.get_code_list("KOSDAQ") # assert kosdaq_result is not None # kospi_result = self.ebest.get_code_list("KOSPI") # assert kospi_result is not None # try: # error_result = self.ebest.get_code_list("KOS") # except: # error_result = None # assert error_result is None # print("result:",len(all_result),len(kosdaq_result),len(kospi_result)) def test_get_stock_price_list_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_stock_price_by_code("005930","2") assert result is not None print(result) def test_get_credit_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_credit_trend_by_code("005930","20190719") assert result is not None print(result) def test_get_agent_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_agent_trend_by_code("005930", fromdt="20200630",todt="20200719") assert result is not None print(result) def test_get_short_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_short_trend_by_code("005930", sdate="20200630",edate="20200719") assert result is not None print(result) def test_get_account_info(self): result = self.ebest.get_account_info() assert result is not None print(result) def test_get_account_stock_info(self): print(inspect.stack()[0][3]) result = self.ebest.get_account_stock_info() assert result print(result) def test_order_stock(self): print(inspect.stack()[0][3]) result = self.ebest.order_stock("005930", "2", "46000", "2", "00") assert result print(result) #code = result[0]["ShtnIsuNo"] #order_no = result[0]["OrdNo"] #print(code, order_no) #time.sleep(1) #result1 = self.ebest.get_order_check("005930", order_no) #print(result1) def test_order_cancel(self): print(inspect.stack()[0][3]) result = self.ebest.order_cancel("22250", "A005930", "2") assert result print(result) def test_order_check(self): print(inspect.stack()[0][3]) result = self.ebest.order_check("22187") assert result print(result) def test_order_check2(self): print(inspect.stack()[0][3]) result = self.ebest.order_check2("20200721","A033530","22187") assert result print(result) def tearDown(self): self.ebest.logout()
import time from datetime import datetime, timedelta from apscheduler.schedulers.background import BackgroundScheduler from stocklab.agent.ebest import EBest from stocklab.db_handler.mongodb_handler import MongoDBHandler from multiprocessing import Process ebest_demo = EBest("DEMO") ebest_demo.login() mongo = MongoDBHandler() def run_process_trading_scenario(code_list): p = Process(target=trading_scenario, args=(code_list,)) p.start() p.join() print("run process join") def check_buy_completed_order(code): """매수완료된 주문은 매도 주문 """ buy_completed_order_list = list(mongo.find_items({"$and":[ {"code": code}, {"status": "buy_completed"} ]}, "stocklab_demo", "order")) """매도 주문 """ for buy_completed_order in buy_completed_order_list: buy_price = buy_completed_order["매수완료"]["주문가격"] buy_order_no = buy_completed_order["매수완료"]["주문번호"] tick_size = ebest_demo.get_tick_size(int(buy_price))
class TestEbest(unittest.TestCase): def setUp(self): self.ebest = EBest("DEMO") self.ebest.login() def test_get_current_call_price_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_current_call_price_by_code("005930") assert result print(result) """ def test_get_stock_price_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_stock_price_by_code("005930", "30") assert result is not None print(result) def testLogin(self): print(inspect.stack()[0][3]) self.ebest.login() assert self.ebest.xa_session_client.login_state == 1 def test_get_code_list(self): print(inspect.stack()[0][3]) result = self.ebest.get_code_list("ALL") assert result is not None print(len(result)) def test_get_stock_price_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_stock_price_by_code("005930", "2") assert result is not None print(result) def test_get_credit_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_credit_trend_by_code("005930", "20190304") assert result is not None print(result) def test_get_short_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_short_trend_by_code("005930", sdate="20190304", edate="20190304") assert result is not None print(result) def test_get_agent_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_agent_trend_by_code("005930", fromdt="20190304", todt="20190304") assert result is not None print(result) def test_order_stock(self): print(inspect.stack()[0][3]) result = self.ebest.order_stock("005930", "2", "46000", "2", "00") assert result print(result) #code = result[0]["ShtnIsuNo"] #order_no = result[0]["OrdNo"] #print(code, order_no) #time.sleep(1) #result1 = self.ebest.get_order_check("005930", order_no) #print(result1) def test_order_cancel(self): print(inspect.stack()[0][3]) result = self.ebest.order_cancel("29515", "A005930", "2") assert result print(result) def test_get_price_n_min_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_price_n_min_by_code("20190412", "180640") assert result print(result) def test_get_price_n_min_by_code_tick(self): print(inspect.stack()[0][3]) result = self.ebest.get_price_n_min_by_code("20190412", "005930", 0) assert result print(result) def test_get_account_stock_info(self): print(inspect.stack()[0][3]) result = self.ebest.get_account_stock_info() assert result print(result) def test_get_account_info(self): print(inspect.stack()[0][3]) result = self.ebest.get_account_info() assert result print(result) def test_real_code(self): print(inspect.stack()[0][3]) result = self.ebest._execute_real("005930") print(result) def test_order_check(self): print(inspect.stack()[0][3]) result = self.ebest.order_check("29515") assert result print(result) def test_get_theme_by_code(self): time.sleep(1) print(inspect.stack()[0][3]) result = self.ebest.get_theme_by_code("078020") assert result is not None print(len(result)) def test_get_theme_list(self): time.sleep(1) print(inspect.stack()[0][3]) result = self.ebest.get_theme_list() assert result is not None print(result) def test_get_category_list(self): time.sleep(1) print(inspect.stack()[0][3]) result = self.ebest.get_category_list() assert result is not None print(len(result)) def test_price_by_category(self): result = self.ebest.get_price_by_category("101") assert result is not None print(len(result)) def test_price_by_theme(self): result = self.ebest.get_price_by_theme("0403") assert result is not None print(len(result)) def test_short_trend_by_code(self): result = self.ebest.get_short_trend_by_code("0403", sdate="20181201", edate="20181203") assert result is not None print(len(result)) def test_get_event_by_code(self): result = self.ebest.get_event_by_code("0403", date="20181201") assert result is not None print(len(result)) def test_get_trade_history(self): result = self.ebest.get_trade_history("10") assert result is not None print(result) def test_get_account_info(self): result = self.ebest.get_account_info() assert result is not None print(result) def test_get_account_stock_info(self): result = self.ebest.get_account_stock_info() assert result is not None print(result) """ def tearDown(self): self.ebest.logout()
from stocklab.agent.ebest import EBest from stocklab.agent.data import Data from stocklab.db_handler.mongodb_handler import MongoDBHandler ''' python -m unittest stocklab.scheduler.backtesting python -m stocklab.scheduler.backtesting ''' ebest_ace = EBest("ACE") ebest_ace.login() mongo = MongoDBHandler() def run_process_trading_scenario(code_list, date): p = Process(target=run_trading_scenario, args=(code_list, date)) p.start() p.join() print("run porcess join") def run_trading_scenario(code_list, date): tick = 0 print(code_list, date, tick) while tick < 20: ''' tick 20 09:20 까지
class TestEBest(unittest.TestCase): def setUp(self): self.ebest = EBest("DEMO") self.ebest.login() def tearDown(self): self.ebest.logout() def test_get_code_list(self): print(inspect.stack()[0][3]) all_result = self.ebest.get_code_list("ALL") assert all_result is not None kosdaq_result = self.ebest.get_code_list("KOSDAQ") assert kosdaq_result is not None kospi_result= self.ebest.get_code_list("KOSPI") assert kospi_result is not None try: error_result = self.ebest.get_code_list("KOS") except: error_result =None assert error_result is None print(len(all_result), len(kosdaq_result), len(kospi_result)) def test_get_stock_price_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_stock_price_by_code("005930", "2") assert result is not None print(result) def test_get_credit_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_credit_trend_by_code("005930", "20190304") assert result is not None print(result) def test_get_short_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_short_trend_by_code("005930", sdate="20190304", edate="20190304") assert result is not None print(result) def test_get_agent_trend_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_agent_trend_by_code("005930", fromdt="20190304", todt="20190304") assert result is not None print(result) def test_get_account_info(self): print(inspect.stack()[0][3]) result = self.ebest.get_account_info() assert result print(result) def test_order_stock(self): print(inspect.stack()[0][3]) result = self.ebest.order_stock("005930", "2", "46000", "2", "00") assert result print(result) #code = result[0]["ShtnIsuNo"] #order_no = result[0]["OrdNo"] #print(code, order_no) #time.sleep(1) #result1 = self.ebest.get_order_check("005930", order_no) #print(result1) def test_get_current_call_price_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_current_call_price_by_code("005930") assert result print(result) def test_order_cancel(self): print(inspect.stack()[0][3]) result = self.ebest.order_cancel("15853", "A005930", "2") assert result print(result) def test_order_check(self): print(inspect.stack()[0][3]) result = self.ebest.order_check("15853") assert result print(result) def test_get_price_n_min_by_code(self): print(inspect.stack()[0][3]) result = self.ebest.get_price_n_min_by_code("20190412", "180640") assert result print(result) def test_get_price_n_min_by_code_tick(self): print(inspect.stack()[0][3]) result = self.ebest.get_price_n_min_by_code("20190412", "005930", 0) assert result print(result)