fix Session lint issues
This commit is contained in:
parent
aceb8007ca
commit
a56340061e
1
.gitignore
vendored
1
.gitignore
vendored
@ -80,3 +80,4 @@ preprocessor.py
|
|||||||
.env
|
.env
|
||||||
.venv
|
.venv
|
||||||
.idea
|
.idea
|
||||||
|
.vscode
|
||||||
|
6
main.py
6
main.py
@ -53,7 +53,7 @@ class TradeThread(threading.Thread):
|
|||||||
msg = 'Got {} during _process()'.format(error.__class__.__name__)
|
msg = 'Got {} during _process()'.format(error.__class__.__name__)
|
||||||
logger.exception(msg)
|
logger.exception(msg)
|
||||||
finally:
|
finally:
|
||||||
Session.flush()
|
Session().flush()
|
||||||
time.sleep(25)
|
time.sleep(25)
|
||||||
except (RuntimeError, JSONDecodeError):
|
except (RuntimeError, JSONDecodeError):
|
||||||
TelegramHandler.send_msg('*Status:* Got RuntimeError: ```\n{}\n```'.format(traceback.format_exc()))
|
TelegramHandler.send_msg('*Status:* Got RuntimeError: ```\n{}\n```'.format(traceback.format_exc()))
|
||||||
@ -75,7 +75,7 @@ class TradeThread(threading.Thread):
|
|||||||
# Create entity and execute trade
|
# Create entity and execute trade
|
||||||
trade = create_trade(float(CONFIG['stake_amount']), api_wrapper.exchange)
|
trade = create_trade(float(CONFIG['stake_amount']), api_wrapper.exchange)
|
||||||
if trade:
|
if trade:
|
||||||
Session.add(trade)
|
Session().add(trade)
|
||||||
else:
|
else:
|
||||||
logging.info('Got no buy signal...')
|
logging.info('Got no buy signal...')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -134,7 +134,7 @@ def close_trade_if_fulfilled(trade: Trade) -> bool:
|
|||||||
# we can close this trade.
|
# we can close this trade.
|
||||||
if trade.close_profit and trade.close_date and trade.close_rate and not trade.open_order_id:
|
if trade.close_profit and trade.close_date and trade.close_rate and not trade.open_order_id:
|
||||||
trade.is_open = False
|
trade.is_open = False
|
||||||
Session.flush()
|
Session().flush()
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -2,7 +2,9 @@ from datetime import datetime
|
|||||||
|
|
||||||
from sqlalchemy import Boolean, Column, DateTime, Float, Integer, String, create_engine
|
from sqlalchemy import Boolean, Column, DateTime, Float, Integer, String, create_engine
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import scoped_session, sessionmaker
|
from sqlalchemy.orm.scoping import scoped_session
|
||||||
|
from sqlalchemy.orm.session import sessionmaker
|
||||||
|
|
||||||
from sqlalchemy.types import Enum
|
from sqlalchemy.types import Enum
|
||||||
|
|
||||||
from exchange import Exchange, get_exchange_api
|
from exchange import Exchange, get_exchange_api
|
||||||
@ -18,10 +20,8 @@ engine = create_engine(db_handle, echo=False)
|
|||||||
Session = scoped_session(sessionmaker(bind=engine, autoflush=True, autocommit=True))
|
Session = scoped_session(sessionmaker(bind=engine, autoflush=True, autocommit=True))
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
|
||||||
|
|
||||||
class Trade(Base):
|
class Trade(Base):
|
||||||
__tablename__ = 'trades'
|
__tablename__ = 'trades'
|
||||||
|
|
||||||
query = Session.query_property()
|
query = Session.query_property()
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
@ -61,7 +61,7 @@ class Trade(Base):
|
|||||||
self.close_profit = profit
|
self.close_profit = profit
|
||||||
self.close_date = datetime.utcnow()
|
self.close_date = datetime.utcnow()
|
||||||
self.open_order_id = order_id
|
self.open_order_id = order_id
|
||||||
Session.flush()
|
Session().flush()
|
||||||
return profit
|
return profit
|
||||||
|
|
||||||
Base.metadata.create_all(engine)
|
Base.metadata.create_all(engine)
|
||||||
|
Loading…
Reference in New Issue
Block a user