tensortrade-org / tensortrade

An open source reinforcement learning framework for training, evaluating, and deploying robust trading agents.
https://discord.gg/ZZ7BGWh
Apache License 2.0
4.5k stars 1.02k forks source link

Iterating multiple streams in Exchange Module #311

Open Youbadawy opened 3 years ago

Youbadawy commented 3 years ago

Please make sure that this is a Bug or a Feature Request and provide all applicable information asked by the template. If your issue is an implementation question, please ask your question on StackOverflow or on the TensorTrade Discord #help-desk channel instead of opening a GitHub issue.

System information

You can obtain the TensorFlow version with:
python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"

Describe the current behavior I am trying to iterate over multiple streams from a list of dataframes, to provide Exchange class with closing price, as below example

bitfinex = Exchange("bitfinex", service=execute_order)([
    Stream.source(list(data.get(i)["close"]), dtype="float").rename(i) for i in data
])

gives me an error saying,

AttributeError: 'list' object has no attribute 'name'

Describe the expected behavior

technically it is the same as doing this no?

bitfinex = Exchange("bitfinex", service=execute_order)(
    Stream.source(list(bitfinex_data['BTC:close']), dtype="float").rename("USD-BTC"),
    Stream.source(list(bitfinex_data['ETH:close']), dtype="float").rename("USD-ETH")
)

Code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate the problem.

bitfinex = Exchange("bitfinex", service=execute_order)([ Stream.source(list(data.get(i)["close"]), dtype="float").rename(i) for i in data ])

where data is a dictionary of [Pair name: str, Dataframe]

{ BTC/USD: pd.DataFrame(BTC/USD) }

Youbadawy commented 3 years ago

basically with my method, it tries to do

Stream.source(list(data.get("BTC/USD")["close"]), dtype="float").rename(i).name

which returns BTC/USD

while on my iteration it does

[ Stream.source(list(data.get(i)["close"]), dtype="float").rename(i) for i in data ].name

which a list has no attribute name...

Youbadawy commented 3 years ago

Would changing the stream call method to this affect anything?


    def __call__(self, streams: List[Stream]) -> "Exchange":
        """Sets up the price streams used to generate the prices.

        Parameters
        ----------
        *streams
            The positional arguments each being a price stream.

        Returns
        -------
        `Exchange`
            The exchange the price streams were passed in for.
        """
        for s in streams:
            pair = "".join([c if c.isalnum() else "/" for c in s.name])
            self._price_streams[pair] = s.rename(self.name + ":/" + s.name)
        return self
leandronogsantos commented 3 years ago

I have a similar problem, did you find any solution?

I'm doing:

  streams = []
  for coin in coins:
       streams.append(Stream.source(list(data[coin+":"+"close"]), dtype="float").rename("USD-"+coin))

but none of this works:

bitstamp = Exchange("bitfinex", service=execute_order)(x for x in streams)
or 
bitstamp = Exchange("bitfinex", service=execute_order)(streams)
or 
bitstamp = Exchange("bitfinex", service=execute_order)tuple(streams)
or 
bitstamp = Exchange("bitfinex", service=execute_order)streams