这是indexloc提供的服务,不要输入任何密码
Skip to content

Fix/postgresql #7620

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

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions controllers/generic/xemm_multiple_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def determine_executor_actions(self) -> List[ExecutorAction]:
)
imbalance = len(stopped_buy_executors) - len(stopped_sell_executors)
for target_profitability, amount in self.buy_levels_targets_amount:
active_buy_executors_target = [e.config.target_profitability == target_profitability for e in active_buy_executors]
active_buy_executors_target = [
e for e in active_buy_executors if e.config.target_profitability == target_profitability
]

if len(active_buy_executors_target) == 0 and imbalance < self.config.max_executors_imbalance:
min_profitability = target_profitability - self.config.min_profitability
Expand All @@ -118,7 +120,9 @@ def determine_executor_actions(self) -> List[ExecutorAction]:
)
executor_actions.append(CreateExecutorAction(executor_config=config, controller_id=self.config.id))
for target_profitability, amount in self.sell_levels_targets_amount:
active_sell_executors_target = [e.config.target_profitability == target_profitability for e in active_sell_executors]
active_sell_executors_target = [
e for e in active_sell_executors if e.config.target_profitability == target_profitability
]
if len(active_sell_executors_target) == 0 and imbalance > -self.config.max_executors_imbalance:
min_profitability = target_profitability - self.config.min_profitability
max_profitability = target_profitability + self.config.max_profitability
Expand Down
84 changes: 61 additions & 23 deletions hummingbot/connector/markets_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ def get_market_states(self,
.query(MarketState)
.filter(MarketState.config_file_path == config_file_path,
MarketState.market == market.display_name))
market_states: Optional[MarketState] = query.one_or_none()
with session.no_autoflush:
market_states: Optional[MarketState] = query.one_or_none()
return market_states

def _did_create_order(self,
Expand All @@ -313,26 +314,35 @@ def _did_create_order(self,

with self._sql_manager.get_new_session() as session:
with session.begin():
order_record: Order = Order(id=evt.order_id,
config_file_path=self._config_file_path,
strategy=self._strategy_name,
market=market.display_name,
symbol=evt.trading_pair,
base_asset=base_asset,
quote_asset=quote_asset,
creation_timestamp=timestamp,
order_type=evt.type.name,
amount=Decimal(evt.amount),
leverage=evt.leverage if evt.leverage else 1,
price=Decimal(evt.price) if evt.price == evt.price else Decimal(0),
position=evt.position if evt.position else PositionAction.NIL.value,
last_status=event_type.name,
last_update_timestamp=timestamp,
exchange_order_id=evt.exchange_order_id)
order_status: OrderStatus = OrderStatus(order=order_record,

order_record: Order = session.query(Order).filter_by(id=evt.order_id).first()

if order_record is None:
# Create new Order if it doesn't exist
order_record = Order(
id=evt.order_id,
config_file_path=self._config_file_path,
strategy=self._strategy_name,
market=market.display_name,
symbol=evt.trading_pair,
base_asset=base_asset,
quote_asset=quote_asset,
creation_timestamp=timestamp,
order_type=evt.type.name,
amount=Decimal(evt.amount),
leverage=evt.leverage if evt.leverage else 1,
price=Decimal(evt.price) if evt.price == evt.price else Decimal(0),
position=evt.position if evt.position else PositionAction.NIL.value,
last_status=event_type.name,
last_update_timestamp=timestamp,
exchange_order_id=evt.exchange_order_id
)
session.add(order_record)
session.flush() # ensure order_record.id is available if it's autogenerated

order_status: OrderStatus = OrderStatus(order_id=evt.order_id,
timestamp=timestamp,
status=event_type.name)
session.add(order_record)
session.add(order_status)
market.add_exchange_order_ids_from_market_recorder({evt.exchange_order_id: evt.order_id})
self.save_market_states(self._config_file_path, market, session=session)
Expand All @@ -352,8 +362,35 @@ def _did_fill_order(self,

with self._sql_manager.get_new_session() as session:
with session.begin():
# Try to find the order record, and update it if necessary.
order_record: Optional[Order] = session.query(Order).filter(Order.id == order_id).one_or_none()

order_record: Order = session.query(Order).filter_by(id=evt.order_id).first()

if order_record is None:
try:
# Create new Order if it doesn't exist
order_record = Order(
id=evt.order_id,
config_file_path=self._config_file_path,
strategy=self._strategy_name,
market=market.display_name,
symbol=evt.trading_pair,
base_asset=base_asset,
quote_asset=quote_asset,
creation_timestamp=timestamp,
order_type=evt.order_type.name,
amount=Decimal(evt.amount),
leverage=evt.leverage if evt.leverage else 1,
price=Decimal(evt.price),
position=evt.position if evt.position else PositionAction.NIL.value,
last_status=event_type.name,
last_update_timestamp=timestamp,
exchange_order_id=evt.exchange_order_id
)
session.add(order_record)
session.flush() # ensure order_record.id is available if it's autogenerated
except Exception as e:
self.logger().error(f"Error creating order record after fill order: {e}")

if order_record is not None:
order_record.last_status = event_type.name
order_record.last_update_timestamp = timestamp
Expand Down Expand Up @@ -394,12 +431,13 @@ def _did_fill_order(self,
position=evt.position if evt.position else PositionAction.NIL.value,
)
session.add(order_status)
session.flush()
session.add(trade_fill_record)
self.save_market_states(self._config_file_path, market, session=session)

market.add_trade_fills_from_market_recorder({TradeFillOrderDetails(trade_fill_record.market,
trade_fill_record.exchange_trade_id,
trade_fill_record.symbol)})
trade_fill_record.exchange_trade_id,
trade_fill_record.symbol)})

def _did_complete_funding_payment(self,
event_tag: int,
Expand Down
10 changes: 7 additions & 3 deletions hummingbot/model/sql_connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ def __init__(self,
if not self._engine.dialect.supports_alter:
continue
for fkc in fkcs:
fk_constraint = ForeignKeyConstraint((), (), name=fkc)
Table(tname, MetaData(), fk_constraint)
conn.execute(DropConstraint(fk_constraint))
try:
fk_constraint = ForeignKeyConstraint((), (), name=fkc[0])
Table(tname, MetaData(), fk_constraint)
conn.execute(DropConstraint(fk_constraint))
except Exception as e:
self.logger().error(e)
continue

self._session_cls = sessionmaker(bind=self._engine)

Expand Down
3 changes: 2 additions & 1 deletion setup/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
- autopep8
- conda-build>=3.26.0
- coverage>=7.2.7
- cython
- cython==3.0.12
- flake8>=6.0.0
- diff-cover>=7.7.0
- pip>=23.2.1
Expand All @@ -16,6 +16,7 @@ dependencies:
- pytest>=7.4.0
- pytest-asyncio>=0.16.0
- setuptools>=68.0.0
- psycopg2>=2.9.10
### Packages used within HB and helping reduce the footprint of pip-installed packages
- aiohttp>=3.8.5
- asyncssh>=2.13.2
Expand Down
4 changes: 2 additions & 2 deletions setup/environment_dydx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ channels:
dependencies:
### Packages needed for the build/install process
- autopep8
- backports>=1.0
- conda-build>=3.26.0
- coverage>=7.2.7
- cython
- cython==3.0.12
- flake8>=6.0.0
- diff-cover>=7.7.0
- pip>=23.2.1
Expand All @@ -17,6 +16,7 @@ dependencies:
- pytest>=7.4.0
- pytest-asyncio>=0.16.0
- setuptools>=68.0.0
- psycopg2>=2.9.10
### Packages used within HB and helping reduce the footprint of pip-installed packages
- aiohttp>=3.8.5
- asyncssh>=2.13.2
Expand Down
Loading