Skip to content

Commit

Permalink
2.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
DogsTailFarmer committed Feb 20, 2024
1 parent c1f9e00 commit b79293e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
## 2.1.3 - 2024-02-20
### Fix
* `calc_profit_order()`: rounding for `target_amount_first`
* `restore_strategy_state()`: restore Tlg control thread
* `restore_strategy_state()`: Tlg control thread

### Update
* Some minor updates
* Up requirements for exchanges-wrapper==1.4.14
* Running `*_utils.py` modules as daemon

## 2.1.2 - 2024-02-17
### Fix
Expand Down
2 changes: 1 addition & 1 deletion martin_binance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__author__ = "Jerry Fedorenko"
__copyright__ = "Copyright © 2021 Jerry Fedorenko aka VM"
__license__ = "MIT"
__version__ = "2.1.3b2"
__version__ = "2.1.3"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"

Expand Down
27 changes: 15 additions & 12 deletions martin_binance/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
__author__ = "Jerry Fedorenko"
__copyright__ = "Copyright © 2021 Jerry Fedorenko aka VM"
__license__ = "MIT"
__version__ = "2.0.0"
__version__ = "2.1.3"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"

import contextlib
import sqlite3
from datetime import datetime
import logging

from martin_binance import DB_FILE

logger = logging.getLogger('logger')


def db_management(exchange) -> None:
conn = sqlite3.connect(DB_FILE, check_same_thread=False)
Expand All @@ -36,7 +39,7 @@ def db_management(exchange) -> None:
conn.execute('ALTER TABLE t_funds ADD COLUMN active BOOLEAN DEFAULT 0')
conn.commit()
except sqlite3.Error as ex:
print(f"ALTER table t_funds failed: {ex}")
logger.error(f"ALTER table t_funds failed: {ex}")
#
cursor = conn.cursor()
# Compliance check t_exchange and EXCHANGE() = exchange() from ms_cfg.toml
Expand All @@ -46,18 +49,18 @@ def db_management(exchange) -> None:
row_n = len(row)
for i, exch in enumerate(exchange):
if i >= row_n:
print(f"save_to_db: Add exchange {i}, {exch}")
logger.info(f"save_to_db: Add exchange {i}, {exch}")
try:
conn.execute("INSERT into t_exchange values(?,?)", (i, exch))
conn.commit()
except sqlite3.Error as err:
print(f"INSERT into t_exchange: {err}")
logger.error(f"INSERT into t_exchange: {err}")
#
try:
conn.execute('UPDATE t_funds SET active = 0 WHERE active = 1')
conn.commit()
except sqlite3.Error as ex:
print(f"Initialise t_funds failed: {ex}")
logger.error(f"Initialise t_funds failed: {ex}")
conn.close()


Expand All @@ -73,7 +76,7 @@ def save_to_db(queue_to_db) -> None:
if data is None or data.get('stop_signal'):
break
if data.get('destination') == 't_funds':
# print("save_to_db: Record row into t_funds")
# logger.info("save_to_db: Record row into t_funds")
try:
connection_analytic.execute("INSERT INTO t_funds values(\
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
Expand Down Expand Up @@ -104,11 +107,11 @@ def save_to_db(queue_to_db) -> None:
connection_analytic.commit()
except sqlite3.Error as err:
result = False
print(f"For save data into t_funds: {err}, retry")
logger.error(f"For save data into t_funds: {err}, retry")
else:
result = True
elif data.get('destination') == 't_orders':
# print("save_to_db: Record row into t_orders")
# logger.info("save_to_db: Record row into t_orders")
try:
connection_analytic.execute("INSERT INTO t_orders VALUES(:id_exchange,\
:f_currency,\
Expand All @@ -131,7 +134,7 @@ def save_to_db(queue_to_db) -> None:
'order_hold': data.get('order_hold')})
connection_analytic.commit()
except sqlite3.Error as err:
print(f"INSERT into t_orders: {err}")
logger.error(f"INSERT into t_orders: {err}")
elif data.get('destination') == 't_funds.active update':
cursor_analytic = connection_analytic.cursor()
try:
Expand All @@ -150,9 +153,9 @@ def save_to_db(queue_to_db) -> None:
except sqlite3.Error as err:
cursor_analytic.close()
row_active = (2,)
print(f"SELECT from t_funds: {err}")
logger.error(f"SELECT from t_funds: {err}")
if row_active is None:
# print("save_to_db: UPDATE t_funds set active=1")
# logger.info("save_to_db: UPDATE t_funds set active=1")
try:
connection_analytic.execute('UPDATE t_funds SET active = 1\
WHERE id=(SELECT max(id) FROM t_funds\
Expand All @@ -166,5 +169,5 @@ def save_to_db(queue_to_db) -> None:
)
connection_analytic.commit()
except sqlite3.Error as err:
print(f"save_to_db: UPDATE t_funds: {err}")
logger.error(f"save_to_db: UPDATE t_funds: {err}")
connection_analytic.commit()
6 changes: 3 additions & 3 deletions martin_binance/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__author__ = "Jerry Fedorenko"
__copyright__ = "Copyright © 2021 Jerry Fedorenko aka VM"
__license__ = "MIT"
__version__ = "2.1.3.b3"
__version__ = "2.1.3"
__maintainer__ = "Jerry Fedorenko"
__contact__ = 'https://github.com/DogsTailFarmer'
##################################################################
Expand Down Expand Up @@ -1669,15 +1669,15 @@ def place_profit_order(self, by_market=False, after_error=False) -> None:
'amount': amount * price,
'by_market': by_market,
'timestamp': self.get_time()}
self.message_log(f"Hold take profit order for Buy {amount} {self.f_currency} by {price},"
self.message_log(f"Hold TP order for Buy {amount} {self.f_currency} by {price},"
f" wait {amount * price} {self.s_currency}, exist: {any2str(fund)}")
elif not buy_side and amount > fund:
# Save take profit order and wait update balance
self.tp_order_hold = {'buy_side': buy_side,
'amount': amount,
'by_market': by_market,
'timestamp': self.get_time()}
self.message_log(f"Hold take profit order for Sell {amount} {self.f_currency}"
self.message_log(f"Hold TP order for Sell {amount} {self.f_currency}"
f" by {price}, exist {any2str(fund)}")
else:
# Create take profit order
Expand Down
2 changes: 1 addition & 1 deletion martin_binance/margin_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__author__ = "Jerry Fedorenko"
__copyright__ = "Copyright © 2021 Jerry Fedorenko aka VM"
__license__ = "MIT"
__version__ = "2.1.3b2"
__version__ = "2.1.3"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dynamic = ["version", "description"]
requires-python = ">=3.9"

dependencies = [
"exchanges-wrapper~=1.4.13",
"exchanges-wrapper~=1.4.14",
"margin-strategy-sdk==0.0.11",
"jsonpickle==3.0.2",
"psutil==5.9.6",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exchanges-wrapper~=1.4.13
exchanges-wrapper~=1.4.14
margin-strategy-sdk==0.0.11
jsonpickle==3.0.2
psutil==5.9.6
Expand Down

0 comments on commit b79293e

Please sign in to comment.