コード例 #1
0
class TestStock(unittest.TestCase):
    def setUp(self):
        self.data_manager = DataManager()

    def test_add_strategy(self):
        stock = self.data_manager.get_stock('000001')
        stock.name = 'temp_stock'
        stock.add_buy_strategy('buy_just_buy', {})
        stock.on_buy_signal('buy_just_buy', 10)

    def test_update_earning_rate(self):
        # code: 033230, name: 인성정보, qty: 100, buy_price: 2915, cur_price: 2020, earning_rate: -30.9005
        stock = self.data_manager.get_stock('000001')
        stock.buy_price = 2915
        stock.cur_price = 2020
        stock.qty = 100

        stock.update_earning_rate()
        logger.info(f'earning_rate:{stock.earning_rate:0.2f} %')

        self.assertAlmostEqual(-30.9005, stock.earning_rate, delta=0.1)

        # code:096530, name:씨젠, qty:1, buy_price:37650, cur_price:67200, earning_rate:78.0133
        stock = self.data_manager.get_stock('000001')
        stock.buy_price = 37650
        stock.cur_price = 67200
        stock.qty = 1

        stock.update_earning_rate()
        logger.info(f'earning_rate: {stock.earning_rate:0.2f} %')

        self.assertAlmostEqual(78.0133, stock.earning_rate, delta=0.1)
コード例 #2
0
ファイル: test_kiwoom.py プロジェクト: mechurak/SnsTradeBot
 def setUp(self):
     logger.info('setup')
     self.app = QApplication(sys.argv)
     self.tempWindow = QMainWindow()
     self.tempModelListener = TempModelListener()
     self.data_manager = DataManager()
     self.data_manager.add_listener(self.tempModelListener)
     self.kiwoom_manager = Kiwoom(self.data_manager)
コード例 #3
0
ファイル: test_kiwoom.py プロジェクト: mechurak/SnsTradeBot
class TestKiwoom(unittest.TestCase):
    def setUp(self):
        logger.info('setup')
        self.app = QApplication(sys.argv)
        self.tempWindow = QMainWindow()
        self.tempModelListener = TempModelListener()
        self.data_manager = DataManager()
        self.data_manager.add_listener(self.tempModelListener)
        self.kiwoom_manager = Kiwoom(self.data_manager)

    def tearDown(self):
        logger.info('tearDown')
        self.app.exit()

    def test_job_queue(self):
        logger.info('test for job_queue()')

        def temp_send_order(rq_name: str, screen_no: str, acc_no: str,
                            order_type: int, code: str, qty: int, price: int,
                            hoga_gb: str, org_order_no: str):
            logger.info(
                f'send_order(). order_type:{order_type}, code:{code}, qty:{qty}'
            )
            return 1

        self.kiwoom_manager.ocx.send_order = Mock(side_effects=temp_send_order)
        self.kiwoom_manager.ocx.send_order.__name__ = 'temp_send_order'
        self.kiwoom_manager.ocx.get_master_code_name = Mock(
            return_value='Temp종목')

        stock0001 = self.data_manager.get_stock('0001')
        stock0001.name = '테스트종목'
        stock0002 = self.data_manager.get_stock('0002')
        stock0002.name = 'temp종목'

        # when
        self.kiwoom_manager.tr_buy_order('0001', 3)
        self.kiwoom_manager.tr_sell_order('0002', 2)

        # when
        time.sleep(3)

        # then
        self.kiwoom_manager.ocx.send_order.assert_called()
        logger.info(
            f'buy_order call_count: {self.kiwoom_manager.ocx.send_order.call_count}'
        )
コード例 #4
0
 def setUp(self):
     self.data_manager = DataManager()
コード例 #5
0
ファイル: main_window.py プロジェクト: mechurak/SnsTradeBot
                                              QTableWidgetItem(stock.name))
        else:
            logger.error(f"unexpected data_type: {data_type}")


if __name__ == "__main__":
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)
    stream_handler = logging.StreamHandler(sys.stdout)
    f = logging.Formatter(
        '%(asctime)s[%(levelname)8s](%(filename)20s:%(lineno)-4s %(funcName)-35s) %(message)s'
    )
    stream_handler.setFormatter(f)
    logger.addHandler(stream_handler)

    data_manager = DataManager()

    class TempListener(UiListener):
        def account_changed(self, the_account):
            logger.info("account_changed. the_account: %s", the_account)

        def btn_balance_clicked(self):
            logger.info('btn_balance_clicked')

        def btn_interest_balance_clicked(self):
            logger.info('btn_interest_balance_clicked')

        def btn_real_clicked(self):
            logger.info('btn_real_clicked')

        def btn_code_add_clicked(self, code):
コード例 #6
0
    def on_buy_signal(self, code: str, qty: int):
        logger.info(f'on_buy_signal!! code:{code}, qty:{qty}')
        self.kiwoom_manager.tr_buy_order(code, qty)

    def on_sell_signal(self, code: str, qty: int):
        logger.info(f'on_sell_signal!! code:{code}, qty:{qty}')
        self.kiwoom_manager.tr_sell_order(code, qty)


if __name__ == "__main__":
    logger.info("===== Start SnsTradeBot ======")

    # Run slackbot
    sys.path.append(os.getcwd() + "\\slack")
    t = threading.Thread(target=sns_trade_bot.slack.run.start)
    t.start()

    app = QApplication(sys.argv)
    data_manager = DataManager()
    main_window = MainWindow(data_manager)
    kiwoom_manager = Kiwoom(data_manager)

    manager = Manager(data_manager, main_window, kiwoom_manager)
    data_manager.add_listener(manager)
    main_window.set_listener(manager)
    kiwoom_manager.tr_connect()

    main_window.show()
    sys.exit(app.exec_())
コード例 #7
0
ファイル: manager.py プロジェクト: mechurak/SnsTradeBot
    class TempModelListener(ModelListener):
        def on_data_updated(self, data_type: DataType):
            logger.info(f"on_data_updated. {data_type}")
            event_loop.exit()

        def on_buy_signal(self, code: str, qty: int):
            logger.info(f'on_buy_signal. code:{code}, qty:{qty}')

        def on_sell_signal(self, code: str, qty: int):
            logger.info(f'on_sell_signal. code:{code}, qty:{qty}')


    app = QApplication(sys.argv)
    tempWindow = QMainWindow()
    tempModelListener = TempModelListener()
    data_manager = DataManager()
    data_manager.add_listener(tempModelListener)
    kiwoom_manager = Kiwoom(data_manager)

    from PyQt5.QtCore import QEventLoop

    event_loop = QEventLoop()

    kiwoom_manager.tr_connect()
    event_loop.exec_()

    kiwoom_manager.load_cond_list()
    event_loop.exec_()

    target_condition = data_manager.cond_dic[3]
    kiwoom_manager.check_cond(target_condition)
コード例 #8
0
class TestKiwoom(unittest.TestCase):
    def setUp(self):
        logger.info('setup')
        self.app = QApplication(sys.argv)
        self.tempWindow = QMainWindow()
        self.tempModelListener = TempModelListener()
        self.data_manager = DataManager()
        self.data_manager.add_listener(self.tempModelListener)
        self.kiwoom_manager = Kiwoom(self.data_manager)

    def tearDown(self):
        logger.info('tearDown')
        self.app.exit()

    def test_on_receive_chejan_data(self):
        logger.info('test for test_on_receive_chejan_data()')

        def temp_get_chejan_data(fid):
            mock_dic = {
                9201: '5323492810',
                9001: 'A123420',
                917: '00',
                916: '00000000',
                302: '선데이토즈',
                10: '+12450',
                930: '24',
                931: '12448',
                932: '298750',
                933: '24',
                945: '24',
                946: '2',
                950: '0',
                951: '0',
                27: '+12450',
                28: '+12300',
                307: '11800',
                8019: '0.00',
                957: '0',
                958: '0',
                918: '00000000',
                990: '0',
                991: '0.00',
                992: '0',
                993: '0.00',
                959: '0',
                924: '0',
                10010: '-11750',
                25: '2',
                11: '+650',
                12: '5.51',
                306: '-8300',
                305: '+15300',
                970: '10',
            }
            return mock_dic[fid] if fid in mock_dic.keys() else ''

        self.kiwoom_manager.ocx.get_chejan_data = Mock(
            side_effect=temp_get_chejan_data)
        stock = self.data_manager.get_stock('123420')
        stock.name = '선데이토즈'
        stock.qty = 0

        # when
        self.kiwoom_manager.handler.on_receive_chejan_data(
            '1', 34,
            '9201;9001;917;916;302;10;930;931;932;933;945;946;950;951;27;28;307;8019;957;958;918;990;991;992;993;959;924;10010;25;11;12;306;305;970'
        )

        # then
        self.assertAlmostEqual(24, stock.qty)