Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CurrencyMismatch: unsupported operation between money in 'EUR' and 'USD': '<'. #35

Open
asmodehn opened this issue Jun 30, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@asmodehn
Copy link
Contributor

I am running this strategy :

from gryphon.execution.strategies.base import Strategy
from gryphon.lib import arbitrage as arb
from gryphon.lib.exchange.consts import Consts


class MoneyLtIssue(Strategy):

    def __init__(self, db, harness=None, strategy_configuration=None):
        self.done = False
        super(MoneyLtIssue, self).__init__(db, harness, strategy_configuration)

    def tick(self, open_orders):
        crosses = arb.detect_crosses_between_many_orderbooks(
            [self.harness.bitstamp_eth_eur.get_orderbook(),
             self.harness.bitstamp_eth_btc.get_orderbook(),
            self.harness.bitstamp_eth_usd.get_orderbook()], ignore_unprofitable=False
        )

        for cross in crosses:
            print(cross)
            self.done = True

    def is_complete(self):
        return self.done

When multiple crosses are detected (hence why I need to pass 3 orderbooks), this happens :

ERROR:gryphon.execution.live_runner:[CurrencyMismatch] unsupported operation between money in 'EUR' and 'USD': '<'. Use XMoney for automatic currency conversion.
Traceback (most recent call last):
  File "/opt/Projects/gryphon/gryphon/execution/live_runner.py", line 281, in live_run
    harness.tick()
  File "harness.pyx", line 161, in gryphon.execution.harness.harness.Harness.tick (/home/alexv/.pyxbld/temp.linux-x86_64-2.7/pyrex/gryphon/execution/harness/harness.c:3195)
  File "/opt/Projects/gryphon/gryphon/lib/util/profile.py", line 59, in inner
    t, result = timeit.timeit(run_func, number=1)
  File "/usr/lib/python2.7/timeit.py", line 237, in timeit
    return Timer(stmt, setup, timer).timeit(number)
  File "/usr/lib/python2.7/timeit.py", line 202, in timeit
    timing = self.inner(it, self.timer)
  File "/opt/Projects/gryphon/gryphon/lib/util/monkeypatch_timeit.py", line 14, in inner
    retval = _func()
  File "/opt/Projects/gryphon/gryphon/lib/util/profile.py", line 57, in run_func
    return func(*args, **kwargs)
  File "harness.pyx", line 169, in gryphon.execution.harness.harness.Harness.tick_algo (/home/alexv/.pyxbld/temp.linux-x86_64-2.7/pyrex/gryphon/execution/harness/harness.c:3394)
  File "money_lt_issue.pyx", line 13, in strategies.money_lt_issue.MoneyLtIssue.tick (/home/alexv/.pyxbld/temp.linux-x86_64-2.7/pyrex/strategies/money_lt_issue.c:1228)
  File "/opt/Projects/gryphon/gryphon/lib/arbitrage.py", line 234, in detect_crosses_between_many_orderbooks
    crosses = sorted(crosses, key=lambda c: c.profit, reverse=True)
  File "/home/alexv/.virtualenvs/gryphon2/local/lib/python2.7/site-packages/money/money.py", line 54, in __lt__
    raise CurrencyMismatch(self.currency, other.currency, '<')
CurrencyMismatch: unsupported operation between money in 'EUR' and 'USD': '<'. Use XMoney for automatic currency conversion.
@garethdmm
Copy link
Owner

Interesting, I do see the issue, when you have multiple crosses with different 'base' price currencies their profitability is recorded in different currencies, and the sort function on them fails. Should be an easy fix, I'll take a close look early next week if no one else gets to it before then. We should add some unit tests to tests/logic/libraries/arbitrage_test.py to catch this scenario in the future as well.

@garethdmm garethdmm added the bug Something isn't working label Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants