Exemple #1
0
    def test_merge_fails_no_trade_list(self):
        l1 = self.li[:7]
        l2 = self.li[7:]
        tl1 = BudaMarketTradeList()
        tl1.append_and_resample(l1)

        self.assertRaises(TypeError, tl1.merge, l2)
Exemple #2
0
    def persist(self, market_list: BudaMarketTradeList) -> None:
        """
        Makes sure the trades are merged with the stored ohcl data before calling the persistor
        """
        if self.market is None:
            raise AttributeError(
                'market attribute of the instance should not be None')

        path = os.path.join(self.path, 'Buda_' + self.market + '.csv')
        if not market_list.is_resampled():
            market_list.resample_ohlcv()

        if os.path.isfile(path):
            stored = pd.read_csv(path,
                                 sep=',',
                                 encoding='utf-8',
                                 parse_dates=True,
                                 index_col='date')

            stored_market_list = BudaMarketTradeList()
            stored_market_list.trade_list = stored

            market_list.merge(stored_market_list)

        market_list.trade_list.to_csv(path, encoding='utf-8')
Exemple #3
0
    def test_merge_fails_cause_no_resampled_argument(self):
        l1 = self.li[:7]
        l2 = self.li[7:]

        tl1 = BudaMarketTradeList()
        tl1.append_and_resample(l1)
        tl2 = BudaMarketTradeList()
        tl2.append_raw(l2)

        self.assertRaises(ValueError, tl1.merge, tl2)
Exemple #4
0
    def test_calculate_volume_df(self):
        trade_list = BudaMarketTradeList()
        trade_list.append_raw(self.li)
        trade_list.resample_ohlcv()
        vol_series = np.asarray(self.volumes).astype(float)
        vol_pd = trade_list.trade_list['volume'].to_numpy()

        self.assertTrue(np.array_equal(vol_series, vol_pd))
Exemple #5
0
    def test_merge_self_not_resampled_should_work_too(self):
        l1 = self.li[:7]
        l2 = self.li[7:]
        tl1 = BudaMarketTradeList()
        tl1.append_and_resample(self.li)

        tl_copy1 = BudaMarketTradeList()
        tl_copy2 = BudaMarketTradeList()

        tl_copy1.append_raw(l1)
        tl_copy2.append_raw(l2)
        tl_copy2.resample_ohlcv()
        tl_copy1.merge(tl_copy2)

        self.assertTrue(tl1.trade_list.equals(tl_copy1.trade_list))
Exemple #6
0
    def test_merge(self):
        l1 = self.li[:
                     7]  # split the list right at 9 am, so that timestamp is present in the 2 df when merged
        l2 = self.li[7:]
        tl1 = BudaMarketTradeList()
        tl1.append_and_resample(self.li)

        tl_copy1 = BudaMarketTradeList()
        tl_copy2 = BudaMarketTradeList()

        tl_copy1.append_raw(l1)
        tl_copy2.append_raw(l2)
        tl_copy1.resample_ohlcv()
        tl_copy2.resample_ohlcv()
        tl_copy1.merge(tl_copy2)

        self.assertTrue(tl1.trade_list.equals(tl_copy1.trade_list))
Exemple #7
0
    def _persist_new_entries(self, resp_json: dict,
                             market_config: MarketConfig) -> None:
        buda_list = BudaMarketTradeList()
        buda_list.append_raw(resp_json['trades']['entries'])

        self.persistor.persist(buda_list)