def main():
    # Define the data cache path.
    hummingsim.set_data_path(os.path.join(os.environ["PWD"], "data"))

    # Define the parameters for the backtest.
    start = pd.Timestamp("2019-01-01", tz="UTC")
    end = pd.Timestamp("2019-01-02", tz="UTC")
    binance_trading_pair = ("ETHUSDT", "ETH", "USDT")
    # ddex_trading_pair = ("WETH-DAI", "WETH", "DAI")

    binance_market = BacktestMarket()
    ddex_market = BacktestMarket()
    binance_market.config = MarketConfig(AssetType.BASE_CURRENCY, 0.001,
                                         AssetType.QUOTE_CURRENCY, 0.001, {})
    ddex_market.config = MarketConfig(AssetType.BASE_CURRENCY, 0.001,
                                      AssetType.QUOTE_CURRENCY, 0.001, {})
    binance_loader = BinanceOrderBookLoaderV2(*binance_trading_pair)
    #ddex_loader = DDEXOrderBookLoader(*ddex_trading_pair)

    binance_market.add_data(binance_loader)
    #ddex_market.add_data(ddex_loader)

    binance_market.set_quantization_param(
        QuantizationParams("ETHUSDT", 5, 3, 5, 3))
    #ddex_market.set_quantization_param(QuantizationParams("WETH-DAI", 5, 3, 5, 3))

    market_pair = PureMarketPair(*([binance_market] +
                                   list(binance_trading_pair)))
    strategy = PureMarketMakingStrategy(
        [market_pair],
        order_size=50000,
        bid_place_threshold=0.003,
        ask_place_threshold=0.003,
        logging_options=PureMarketMakingStrategy.OPTION_LOG_ALL)

    clock = Clock(ClockMode.BACKTEST,
                  tick_size=60,
                  start_time=start.timestamp(),
                  end_time=end.timestamp())
    clock.add_iterator(binance_market)
    #clock.add_iterator(ddex_market)
    clock.add_iterator(strategy)

    binance_market.set_balance("ETH", 100000.0)
    binance_market.set_balance("USDT", 100000000.0)
    ddex_market.set_balance("WETH", 100000.0)
    ddex_market.set_balance("DAI", 1000.0)

    current = start.timestamp()
    step = 60

    while current <= end.timestamp():

        current += step
        clock.backtest_til(current)
        print("clock ticked")

    binance_loader.close()
Beispiel #2
0
def main():
    # Define the data cache path.
    hummingsim.set_data_path(os.path.join(os.environ["PWD"], "data"))

    # Define the parameters for the backtest.
    start = pd.Timestamp("2018-12-12", tz="UTC")
    end = pd.Timestamp("2019-01-12", tz="UTC")
    binance_symbol = ("ETHUSDT", "ETH", "USDT")
    ddex_symbol = ("WETH-DAI", "WETH", "DAI")

    binance_market = BacktestMarket()
    ddex_market = BacktestMarket()
    binance_market.config = MarketConfig(AssetType.BASE_CURRENCY, 0.001,
                                         AssetType.QUOTE_CURRENCY, 0.001, {})
    ddex_market.config = MarketConfig(AssetType.BASE_CURRENCY, 0.001,
                                      AssetType.QUOTE_CURRENCY, 0.001, {})
    binance_loader = BinanceOrderBookLoaderV2(*binance_symbol)
    ddex_loader = DDEXOrderBookLoader(*ddex_symbol)

    binance_market.add_data(binance_loader)
    ddex_market.add_data(ddex_loader)

    binance_market.set_quantization_param(
        QuantizationParams("ETHUSDT", 5, 3, 5, 3))
    ddex_market.set_quantization_param(
        QuantizationParams("WETH-DAI", 5, 3, 5, 3))

    market_pair = CrossExchangeMarketPair(*([ddex_market] + list(ddex_symbol) +
                                            [binance_market] +
                                            list(binance_symbol)))
    strategy = CrossExchangeMarketMakingStrategy(
        [market_pair],
        0.003,
        logging_options=CrossExchangeMarketMakingStrategy.
        OPTION_LOG_MAKER_ORDER_FILLED)

    clock = Clock(ClockMode.BACKTEST,
                  start_time=start.timestamp(),
                  end_time=end.timestamp())
    clock.add_iterator(binance_market)
    clock.add_iterator(ddex_market)
    clock.add_iterator(strategy)

    binance_market.set_balance("ETH", 10.0)
    binance_market.set_balance("USDT", 1000.0)
    ddex_market.set_balance("WETH", 10.0)
    ddex_market.set_balance("DAI", 1000.0)

    clock.backtest()
    binance_loader.close()
    ddex_loader.close()
sys.path.insert(0, os.path.realpath(os.path.join(__file__, "../../")))
import logging
logging.basicConfig(level=logging.INFO)
import pandas as pd
import hummingsim
from hummingsim.backtest.backtest_market import BacktestMarket
from hummingsim.backtest.binance_order_book_loader_v2 import BinanceOrderBookLoaderV2
from hummingsim.backtest.ddex_order_book_loader import DDEXOrderBookLoader
from hummingsim.backtest.market import QuantizationParams
from hummingbot.core.clock import (Clock, ClockMode)
from hummingsim.backtest.market_config import (MarketConfig, AssetType)
from hummingbot.strategy.arbitrage import (ArbitrageStrategy,
                                           ArbitrageMarketPair)

# Define the data cache path.
hummingsim.set_data_path(os.path.join(os.environ["PWD"], "data"))

# Define the parameters for the backtest.
start = pd.Timestamp("2018-12-21-00:29:06", tz="UTC")
end = pd.Timestamp("2019-12-24-00:43:00", tz="UTC")
binance_trading_pair = ("ETHUSDT", "ETH", "USDT")
ddex_trading_pair = ("WETH-DAI", "WETH", "DAI")

binance_market = BacktestMarket()
ddex_market = BacktestMarket()
binance_loader = BinanceOrderBookLoaderV2(*binance_trading_pair)
ddex_loader = DDEXOrderBookLoader(*ddex_trading_pair)

binance_market.config = MarketConfig(AssetType.BASE_CURRENCY, 0.001,
                                     AssetType.QUOTE_CURRENCY, 0.001, {})
ddex_market.config = MarketConfig(AssetType.BASE_CURRENCY, 0.001,
Beispiel #4
0
    def test_order_book_trades(self):
        start: int = int(self.snapshot_time)
        end: int = int(self.snapshot_time) + 60
        self.clock.backtest_til(start)

        event_recorder: EventLogger = EventLogger()
        self.order_book.add_listener(OrderBookEvent.TradeEvent, event_recorder)
        self.clock.backtest_til(end)

        trade_messages: List[OrderBookMessage] = [
            message
            for message in self.order_book_loader.fetch_order_book_messages(
                start, end) if message.type is OrderBookMessageType.TRADE
        ]

        events: List[OrderBookTradeEvent] = event_recorder.event_log
        self.assertEqual(len(trade_messages), len(events))
        for trade_message, trade_event in zip(trade_messages, events):
            self.assertAlmostEqual(trade_message.timestamp,
                                   trade_event.timestamp)
            self.assertAlmostEqual(float(trade_message.content["price"]),
                                   trade_event.price)
            self.assertAlmostEqual(float(trade_message.content["amount"]),
                                   trade_event.amount)


if __name__ == "__main__":
    hummingsim.set_data_path(realpath(join(__file__, "../../data")))
    unittest.main()