Пример #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
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}'
        )
Пример #3
0
        def combo_signal_type_changed(self, condition, signal_type_index):
            logger.info(
                f'combo_signal_type_changed. {condition}: {signal_type_index}')
            condition.signal_type = SignalType(signal_type_index)

        def btn_query_condition_clicked(self, condition):
            logger.info(
                f'btn_query_condition_clicked. {condition.index} {condition.name}'
            )

        def btn_register_condition_list_clicked(self):
            logger.info("btn_register_condition_list_clicked")

        def btn_test_clicked(self):
            logger.info("btn_test_clicked")

    app = QApplication(sys.argv)
    mainWindow = MainWindow(data_manager)
    listener = TempListener()
    mainWindow.set_listener(listener)
    data_manager.set_account_list(['123', '678'])
    stock0001 = data_manager.get_stock('0001')
    stock0001.name = '테스트종목'
    stock0002 = data_manager.get_stock('0002')
    stock0002.name = 'temp종목'
    data_manager.set_updated(DataType.TABLE_BALANCE)
    data_manager.set_updated(DataType.TABLE_CONDITION)
    mainWindow.show()
    sys.exit(app.exec_())
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)