예제 #1
0
    def test_getWalletState_recent(self):
        dataobject = DataObject()
        dataobject.matchTransactionsRecent()

        dataPath = data.get_data_path("akcje_2021-12-21_20-00.xls")
        dataobject.gpwCurrentSource.stockData.dao.storage = WorksheetStorageMock(
        )
        dataobject.gpwCurrentSource.stockData.dao.parseWorksheetFromFile(
            dataPath)

        ## CDP curr price: 360.0 (from recent_data_TKO.xls)
        dataobject.wallet.add("CDR", -1, 300.0,
                              datetime.datetime(2020, 10, 6, 15, 41, 33))
        dataobject.wallet.add("CDR", 1, 260.0,
                              datetime.datetime(2020, 10, 5, 15, 41, 33))
        dataobject.wallet.add("CDR", 1, 200.0,
                              datetime.datetime(2020, 10, 4, 15, 41, 33))

        walletVal, walletProfit, change, gain, overallProfit = dataobject.getWalletState(
            False)
        self.assertEqual(walletVal, 191.36)
        self.assertEqual(walletProfit, -8.64)
        self.assertEqual(change, '-0.87%')
        self.assertEqual(gain, 40.0)
        self.assertEqual(overallProfit, 31.36)
예제 #2
0
 def test_getWalletStock(self):
     dataobject = DataObject()
     dataPath = data.get_data_path("recent_data_TKO.xls")
     dataobject.gpwCurrentSource.stockData.dao.storage = WorksheetStorageMock(
     )
     dataobject.gpwCurrentSource.stockData.dao.parseWorksheetFromFile(
         dataPath)
     dataobject.wallet.add("CDR", 1, 300.0)
     stock = dataobject.getWalletStock()
     self.assertEqual(stock is not None, True)
예제 #3
0
    def test_addFav_duplicates(self):
        dataobject = DataObject()
        dataobject.addFavGroup("xxx")
        self.assertEqual(len(dataobject.favs.favsList), 1)

        dataobject.addFav("xxx", "aaa")
        self.assertEqual(dataobject.undoStack.count(), 2)

        dataobject.addFav("xxx", "aaa")
        self.assertEqual(dataobject.undoStack.count(), 2)
예제 #4
0
    def test_importWalletTransactions_sametime(self):
        transactionsPath = get_data_path("transactions_bad_separator.csv")

        with codecs.open(transactionsPath,
                         'r',
                         encoding='utf-8',
                         errors='replace') as srcFile:
            importedData = parse_mb_transactions_data(srcFile)

        dataObject = DataObject()
        dataObject.importWalletTransactions(importedData)

        wallet: WalletData = dataObject.wallet
        self.assertEqual(wallet.size(), 1)

        trans: TransHistory = wallet["ENT"]
        amount = trans.currentAmount()
        self.assertEqual(amount, 0)
예제 #5
0
    def test_addFav_duplicates_list(self):
        dataobject = DataObject()
        dataobject.addFav("xxx", "aaa")
        self.assertEqual(dataobject.undoStack.count(), 1)

        dataobject.addFav("xxx", ["aaa", "bbb"])
        self.assertEqual(dataobject.undoStack.count(), 2)
예제 #6
0
    def test_deleteFavGrp(self):
        dataobject = DataObject()
        dataobject.addFavGroup("xxx")
        self.assertEqual(len(dataobject.favs.favsList), 1)

        dataobject.deleteFavGroup("xxx")
        self.assertEqual(len(dataobject.favs.favsList), 0)
예제 #7
0
 def test_addFavGroup(self):
     dataobject = DataObject()
     self.assertEqual(dataobject.undoStack.count(), 0)
     dataobject.addFavGroup("xxx")
     self.assertEqual(dataobject.undoStack.count(), 1)
     dataobject.addFavGroup("xxx")
     self.assertEqual(dataobject.undoStack.count(), 1)
예제 #8
0
def prepare_dataobject():
    data = DataObject()
    dataAccess = GpwCurrentStockIntradayData("PLOPTTC00011")

    def data_path():
        return get_data_path("cdr.chart.04-09.txt")

    dataAccess.dao.getDataPath = data_path  # type: ignore
    dataAccess.dao.downloadData = lambda filePath: None  ## empty lambda function
    dataAccess.dao.storage = WorksheetStorageMock()

    #     data.gpwStockIntradayData.set( "PLOPTTC00011", dataAccess )
    #     data.gpwStockIntradayData.set( "CRD", dataAccess )
    return data
예제 #9
0
    def test_renameFavGrp(self):
        dataobject = DataObject()
        dataobject.addFavGroup("xxx")
        self.assertEqual(len(dataobject.favs.favsList), 1)

        dataobject.renameFavGroup("xxx", "yyy")
        self.assertEqual(len(dataobject.favs.favsList), 1)

        xxxFavs = dataobject.favs.getFavs("xxx")
        self.assertEqual(xxxFavs, None)

        yyyFavs = dataobject.favs.getFavs("yyy")
        self.assertNotEqual(yyyFavs, None)
예제 #10
0
    def test_importWalletTransactions(self):
        importedData = DataFrame({
            'trans_time': ['28.10.2020 09:10:07'],
            'name': ["CCC"],
            'k_s': ['S'],
            'amount': [10],
            'unit_price': ['10.2']
        })
        dataObject = DataObject()
        wallet: WalletData = dataObject.wallet
        self.assertEqual(wallet.size(), 0)

        dataObject.importWalletTransactions(importedData, True)
        self.assertEqual(wallet.size(), 1)

        trans: TransHistory = wallet["CCC"]
        self.assertEqual(len(trans), 1)
        self.assertEqual(trans[0][0], -10)

        dataObject.importWalletTransactions(importedData, True)

        self.assertEqual(wallet.size(), 1)
        self.assertEqual(len(trans), 1)
        self.assertEqual(trans[0][0], -10)
## ============================= main section ===================================

if __name__ != '__main__':
    sys.exit(0)

logFile = logger.get_logging_output_file()
logger.configure(logFile)

_LOGGER = logging.getLogger(__name__)

app = QApplication(sys.argv)
app.setApplicationName("StockMonitor")
app.setOrganizationName("arnet")

dataObject = DataObject()
dataObject.loadDownloadedStocks()
# dataObject.wallet.add( "ALR", 111, 11.1 )
# dataObject.wallet.add( "EAT", 222, 22.2 )
# dataObject.wallet.add( "CDR", 333, 33.3 )
# dataObject.wallet.add( "XXX", 444, 44.4 )

dataObject.markers.add("ABC", 11, 22, MarkerEntry.OperationType.BUY)
dataObject.markers.add("XYZ", 33, 44, MarkerEntry.OperationType.BUY)
dataObject.markers.add("AAA1", 20, 100, MarkerEntry.OperationType.BUY)
dataObject.markers.add("AAA2", 5, 100, MarkerEntry.OperationType.BUY)
dataObject.markers.add("AAA3", 20, 100, MarkerEntry.OperationType.SELL, "red")
dataObject.markers.add("AAA4", 5, 100, MarkerEntry.OperationType.SELL,
                       "yellow")

# csvPath = data.get_data_root_path() + "/akcje_2020-04-14_15-50.csv"
    return dataAccess


logFile = logger.get_logging_output_file()
logger.configure( logFile )

_LOGGER = logging.getLogger(__name__)


app = QApplication(sys.argv)
app.setApplicationName("StockMonitor")
app.setOrganizationName("arnet")

setup_interrupt_handling()

dataObject = DataObject()
dataObject.gpwIndexIntradayData.dataDict.factory_function = make_intraday

widget = create_window( dataObject, "PL9999999987" )        ## wig20
widget.resize( 1024, 768 )


def make_screen():
    _LOGGER.info("making screenshot")
    root_path = get_root_path()
    render_to_pixmap( widget, root_path + "/tmp/indexchartwindow-big.png" )


QtCore.QTimer.singleShot(3000, make_screen)

sys.exit( app.exec_() )