notadamking / RLTrader

A cryptocurrency trading environment using deep reinforcement learning and OpenAI's gym
https://discord.gg/ZZ7BGWh
GNU General Public License v3.0
1.73k stars 539 forks source link

Abstracting the exchange #104

Open mwbrulhardt opened 5 years ago

mwbrulhardt commented 5 years ago

I'm looking through the code for the environment and I notice that it is holding onto a lot of information that the exchange would be holding onto, such as:

It might be good to make an Exchange abstract class. This class will hold all information that has to do with your account, and in addition can be set to have a paper mode or a live trading mode. We can make a DummyExchange class to handle the cases where the algorithm is either training, testing, or in paper mode, then for live trading it would just be a matter of switching the mode to live. I think it would also make the exchanges more pluggable. So the abstract class would look something similar to this:

import abc

class Exchange(object, abc.ABCMeta):

    def ___init___(self, exchange_id, init_balance, **kwargs):
        self.exchange_id
        self.init_balance = init_balance
        self.credentials = kwargs.get('credentials', {})

    @abc.abstractmethod
    def buy(self, amount):
        raise NotImplemented

    @abc.abstractmethod
    def sell(self, amount):
        raise NotImplemented

When live trading the class would just need to be injected with the credentials so that live trading could take place. Let me know if this is at all helpful!