class CryptoEnvironmentStub: def __init__(self, action_to_token, active_token): self.rates_stream = RatesStub(RecordsStub()) self.action_to_token = action_to_token self.token = active_token def add_record(self, *entries): self.rates_stream.add_record(*entries) return self def finish(self): self.rates_stream.finish() def step(self, action): next(self.rates_stream)
def env(): rate = RatesStub(RecordsStub()) rate.add_record(entry("BTC_ETH", "2.0", miner_fee="0"), entry("ETH_BTC", "0.5", miner_fee="0")) \ .add_record(entry("BTC_ETH", "2.0", miner_fee="0"), entry("ETH_BTC", "0.5", miner_fee="0")) \ .add_record(entry("BTC_ETH", "4.0", miner_fee="0"), entry("ETH_BTC", "0.25", miner_fee="0")) \ .add_record(entry("BTC_ETH", "2.0", miner_fee="0"), entry("ETH_BTC", "0.5", miner_fee="0")) \ .add_record(entry("BTC_ETH", "1.0", miner_fee="0"), entry("ETH_BTC", "1.0", miner_fee="0")) \ .add_record(entry("BTC_ETH", "2.0", miner_fee="0"), entry("ETH_BTC", "0.5", miner_fee="0")) \ .add_record(entry("BTC_ETH", "4.0", miner_fee="0"), entry("ETH_BTC", "0.25", miner_fee="0")).finish() yield ExchangeTradingAiEnvironment(rate, "BTC", 1, 1, { 1: "BTC", 2: "ETH" }, TotalBalanceReward()) rate.close()
class EnvironmentStub(ExchangeTradingEnvironment): def __init__(self): self.rates = RatesStub(RecordsStub()) self.rewards = deque() def add_record(self, pairs, reward=0): if isinstance(pairs, tuple): self.rates.add_record(*pairs) else: self.rates.add_record(pairs) self.rewards.append(reward) return self def step(self, action): s, _, done, _ = super().step(action) return s, self.rewards.popleft(), done, None def finish(self): self.rewards.popleft() # starting state has no reward self.rates.finish() super().__init__(self.rates, "BTC", 2, 1) def close(self): self.rates.close()
def rates(): s = RecordsStub() yield RatesStub(s) s.close()
def __init__(self): self.rates = RatesStub(RecordsStub()) self.rewards = deque()
def __init__(self, action_to_token, active_token): self.rates_stream = RatesStub(RecordsStub()) self.action_to_token = action_to_token self.token = active_token