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

Fix/leverage type (from decimal to int) #6504

Merged
merged 5 commits into from Jul 27, 2023

Conversation

cardosofede
Copy link
Contributor

@cardosofede cardosofede commented Jul 24, 2023

Before submitting this PR, please make sure:

  • Your code builds clean without any errors or warnings
  • You are using approved title ("feat/", "fix/", "docs/", "refactor/")

A description of the changes proposed in the pull request:
The type hint of the position config invites you to use a Decimal value for the leverage when it's an integer.
If you use a decimal you get an error in the database when trying to query the orders with the market recorder.

Traceback (most recent call last):
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1905, in _execute_context
    self.dialect.do_execute(
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
sqlite3.InterfaceError: Error binding parameter 10 - probably unsupported type.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "hummingbot/core/pubsub.pyx", line 165, in hummingbot.core.pubsub.PubSub.c_trigger_event
  File "hummingbot/core/event/event_listener.pyx", line 25, in hummingbot.core.event.event_listener.EventListener.c_call
  File "/Users/dardonacci/Documents/work/hummingbot/hummingbot/core/event/event_forwarder.py", line 24, in __call__
    self._to_function(self.current_event_tag, self.current_event_caller, arg)
  File "/Users/dardonacci/Documents/work/hummingbot/hummingbot/connector/markets_recorder.py", line 278, in _did_create_order
    self.save_market_states(self._config_file_path, market, session=session)
  File "/Users/dardonacci/Documents/work/hummingbot/hummingbot/connector/markets_recorder.py", line 211, in save_market_states
    market_states: Optional[MarketState] = self.get_market_states(config_file_path, market, session=session)
  File "/Users/dardonacci/Documents/work/hummingbot/hummingbot/connector/markets_recorder.py", line 239, in get_market_states
    market_states: Optional[MarketState] = query.one_or_none()
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2850, in one_or_none
    return self._iter().one_or_none()
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2916, in _iter
    result = self.session.execute(
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1665, in execute
    ) = compile_state_cls.orm_pre_session_exec(
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/orm/context.py", line 312, in orm_pre_session_exec
    session._autoflush()
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2264, in _autoflush
    util.raise_(e, with_traceback=sys.exc_info()[2])
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 2253, in _autoflush
    self.flush()
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3449, in flush
    self._flush(objects)
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3588, in _flush
    with util.safe_reraise():
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3549, in _flush
    flush_context.execute()
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
    rec.execute(self)
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute
    util.preloaded.orm_persistence.save_obj(
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 245, in save_obj
    _emit_insert_statements(
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 1097, in _emit_insert_statements
    c = connection._execute_20(
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1710, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 334, in _execute_on_connection
    return connection._execute_clauseelement(
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1577, in _execute_clauseelement
    ret = self._execute_context(
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1948, in _execute_context
    self._handle_dbapi_exception(
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2129, in _handle_dbapi_exception
    util.raise_(
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1905, in _execute_context
    self.dialect.do_execute(
  File "/Users/dardonacci/anaconda3/envs/hummingbot/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.InterfaceError: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely)
(sqlite3.InterfaceError) Error binding parameter 10 - probably unsupported type.
[SQL: INSERT INTO "Order" (id, config_file_path, strategy, market, symbol, base_asset, quote_asset, creation_timestamp, order_type, amount, leverage, price, last_status, last_update_timestamp, exchange_order_id, position) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
[parameters: ('x-3QreWesyBMCUT60140517985b4bbb4', 'stat_arb', 'stat_arb', 'binance_perpetual', 'MATIC-USDT', 'MATIC', 'USDT', 1690225616000, 'MARKET', 89000000, Decimal('10'), 724500, 'BuyOrderCreated', 1690225616000, '26982771130', 'OPEN')]
(Background on this error at: https://sqlalche.me/e/14/rvf5)

Tests performed by the developer:
Run a directional strategy that uses leverage Decimal("10") instead of 10

Tips for QA testing:

@rapcmia rapcmia requested review from rapcmia and nikspz July 25, 2023 02:33
@nikspz nikspz changed the title Fix/leverage type Fix/leverage type (from decimal to int) Jul 25, 2023
@nikspz
Copy link
Contributor

nikspz commented Jul 25, 2023

Test performed:
Cloned and install fix branch.

  1. Created/started directional_strategy_bb_rsi_multi_timeframe using leverage = Decimal("10") and binance perpetual
    Result: Client Placed order OPEN and CLOSE with leverage 10 successfully
    with warning message
Error binding parameter 10 - probably unsupported type.
  1. Created/started directional_strategy_bb_rsi_multi_timeframe using leverage = 1.5 and binance perpetual
    Result: Client Placed order OPEN and CLOSE with leverage 1 successfully
    with warning message
Error: {"code":-1102,"msg":"Mandatory parameter 'leverage' was not sent, was empty/null, or malformed."}
  1. Created/started directional_strategy_bb_rsi_multi_timeframe using leverage = 10 and binance perpetual
    Result: Client Placed order OPEN and CLOSE with leverage 10 successfully, no issues showed

@fengtality
Copy link
Sponsor Contributor

@nikspz Please also run another perpetual strategy like spot_perpetual_arbitrage or perpetual_market_making to check that there's no impact on non-directional strategies

Copy link
Contributor

@nikspz nikspz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test performed:

  • Ran directional_strategy_bb_rsi_multi_timeframe, reviewed overnight performance was good.
  • Created/ran spot-perpetual using binance and binance perpetual
  • Ran simple perpetualMM strategy using binance perpetual
  • Reviewed OPEN orders placed and CLOSE: stop-loss and take profit order closed, according to config: ok

@rapcmia rapcmia merged commit d887fc1 into hummingbot:development Jul 27, 2023
2 checks passed
@rapcmia
Copy link
Contributor

rapcmia commented Jul 27, 2023

Merged to development and will be part of release version 1.19.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants