Merge pull request #4994 from freqtrade/support_other_dbs

Support other dbs
This commit is contained in:
Matthias 2021-05-22 15:54:34 +01:00 committed by GitHub
commit feb836eaf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 19 deletions

View File

@ -19,7 +19,7 @@ The freqtrade docker image does contain sqlite3, so you can edit the database wi
``` bash ``` bash
docker-compose exec freqtrade /bin/bash docker-compose exec freqtrade /bin/bash
sqlite3 <databasefile>.sqlite sqlite3 <database-file>.sqlite
``` ```
## Open the DB ## Open the DB
@ -99,3 +99,32 @@ DELETE FROM trades WHERE id = 31;
!!! Warning !!! Warning
This will remove this trade from the database. Please make sure you got the correct id and **NEVER** run this query without the `where` clause. This will remove this trade from the database. Please make sure you got the correct id and **NEVER** run this query without the `where` clause.
## Use a different database system
!!! Warning
By using one of the below database systems, you acknowledge that you know how to manage such a system. Freqtrade will not provide any support with setup or maintenance (or backups) of the below database systems.
### PostgreSQL
Freqtrade supports PostgreSQL by using SQLAlchemy, which supports multiple different database systems.
Installation:
`pip install psycopg2`
Usage:
`... --db-url postgresql+psycopg2://<username>:<password>@localhost:5432/<database>`
Freqtrade will automatically create the tables necessary upon startup.
If you're running different instances of Freqtrade, you must either setup one database per Instance or use different users / schemas for your connections.
### MariaDB / MySQL
Freqtrade supports MariaDB by using SQLAlchemy, which supports multiple different database systems.
Installation:
`pip install pymysql`
Usage:
`... --db-url mysql+pymysql://<username>:<password>@localhost:3306/<database>`

View File

@ -112,15 +112,15 @@ class Order(_DECL_BASE):
trade = relationship("Trade", back_populates="orders") trade = relationship("Trade", back_populates="orders")
ft_order_side = Column(String, nullable=False) ft_order_side = Column(String(25), nullable=False)
ft_pair = Column(String, nullable=False) ft_pair = Column(String(25), nullable=False)
ft_is_open = Column(Boolean, nullable=False, default=True, index=True) ft_is_open = Column(Boolean, nullable=False, default=True, index=True)
order_id = Column(String, nullable=False, index=True) order_id = Column(String(255), nullable=False, index=True)
status = Column(String, nullable=True) status = Column(String(255), nullable=True)
symbol = Column(String, nullable=True) symbol = Column(String(25), nullable=True)
order_type = Column(String, nullable=True) order_type = Column(String(50), nullable=True)
side = Column(String, nullable=True) side = Column(String(25), nullable=True)
price = Column(Float, nullable=True) price = Column(Float, nullable=True)
average = Column(Float, nullable=True) average = Column(Float, nullable=True)
amount = Column(Float, nullable=True) amount = Column(Float, nullable=True)
@ -658,15 +658,15 @@ class Trade(_DECL_BASE, LocalTrade):
orders = relationship("Order", order_by="Order.id", cascade="all, delete-orphan") orders = relationship("Order", order_by="Order.id", cascade="all, delete-orphan")
exchange = Column(String, nullable=False) exchange = Column(String(25), nullable=False)
pair = Column(String, nullable=False, index=True) pair = Column(String(25), nullable=False, index=True)
is_open = Column(Boolean, nullable=False, default=True, index=True) is_open = Column(Boolean, nullable=False, default=True, index=True)
fee_open = Column(Float, nullable=False, default=0.0) fee_open = Column(Float, nullable=False, default=0.0)
fee_open_cost = Column(Float, nullable=True) fee_open_cost = Column(Float, nullable=True)
fee_open_currency = Column(String, nullable=True) fee_open_currency = Column(String(25), nullable=True)
fee_close = Column(Float, nullable=False, default=0.0) fee_close = Column(Float, nullable=False, default=0.0)
fee_close_cost = Column(Float, nullable=True) fee_close_cost = Column(Float, nullable=True)
fee_close_currency = Column(String, nullable=True) fee_close_currency = Column(String(25), nullable=True)
open_rate = Column(Float) open_rate = Column(Float)
open_rate_requested = Column(Float) open_rate_requested = Column(Float)
# open_trade_value - calculated via _calc_open_trade_value # open_trade_value - calculated via _calc_open_trade_value
@ -680,7 +680,7 @@ class Trade(_DECL_BASE, LocalTrade):
amount_requested = Column(Float) amount_requested = Column(Float)
open_date = Column(DateTime, nullable=False, default=datetime.utcnow) open_date = Column(DateTime, nullable=False, default=datetime.utcnow)
close_date = Column(DateTime) close_date = Column(DateTime)
open_order_id = Column(String) open_order_id = Column(String(255))
# absolute value of the stop loss # absolute value of the stop loss
stop_loss = Column(Float, nullable=True, default=0.0) stop_loss = Column(Float, nullable=True, default=0.0)
# percentage value of the stop loss # percentage value of the stop loss
@ -690,16 +690,16 @@ class Trade(_DECL_BASE, LocalTrade):
# percentage value of the initial stop loss # percentage value of the initial stop loss
initial_stop_loss_pct = Column(Float, nullable=True) initial_stop_loss_pct = Column(Float, nullable=True)
# stoploss order id which is on exchange # stoploss order id which is on exchange
stoploss_order_id = Column(String, nullable=True, index=True) stoploss_order_id = Column(String(255), nullable=True, index=True)
# last update time of the stoploss order on exchange # last update time of the stoploss order on exchange
stoploss_last_update = Column(DateTime, nullable=True) stoploss_last_update = Column(DateTime, nullable=True)
# absolute value of the highest reached price # absolute value of the highest reached price
max_rate = Column(Float, nullable=True, default=0.0) max_rate = Column(Float, nullable=True, default=0.0)
# Lowest price reached # Lowest price reached
min_rate = Column(Float, nullable=True) min_rate = Column(Float, nullable=True)
sell_reason = Column(String, nullable=True) sell_reason = Column(String(100), nullable=True)
sell_order_status = Column(String, nullable=True) sell_order_status = Column(String(100), nullable=True)
strategy = Column(String, nullable=True) strategy = Column(String(100), nullable=True)
timeframe = Column(Integer, nullable=True) timeframe = Column(Integer, nullable=True)
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -856,8 +856,8 @@ class PairLock(_DECL_BASE):
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
pair = Column(String, nullable=False, index=True) pair = Column(String(25), nullable=False, index=True)
reason = Column(String, nullable=True) reason = Column(String(255), nullable=True)
# Time the pair was locked (start time) # Time the pair was locked (start time)
lock_time = Column(DateTime, nullable=False) lock_time = Column(DateTime, nullable=False)
# Time until the pair is locked (end time) # Time until the pair is locked (end time)