Skip to content

Commit

Permalink
1.2.6-8-hotfix close #19
Browse files Browse the repository at this point in the history
  • Loading branch information
DogsTailFarmer committed Sep 3, 2022
1 parent a7923c8 commit b19c2c6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
16 changes: 10 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.2.6-8-hotfix 2022-09-03
### Fixed
* [File exist error on Windows 11](https://github.com/DogsTailFarmer/martin-binance/issues/19#issue-1360296628)

## v1.2.6-7 2022-09-01
### Fixed
* Incorrect settings for max grid orders count at grid update (Filter failure: MIN_NOTIONAL)
Expand All @@ -7,12 +11,12 @@

## v1.2.6 2022-08-27
### Fixed
* [Incomplete account setup](DogsTailFarmer/martin-binance#17)
* [Incomplete account setup](https://github.com/DogsTailFarmer/martin-binance/issues/17#issue-1347470971)

### Update
* up to Python 3.10.6
* 1.2.5-3 update on_place_order_error_string() to avoid the cyclical sending of an order rejected by the exchange
* [Update readme - limit for several pair with intersecting coin](DogsTailFarmer/martin-binance#18)
* [Update readme - limit for several pair with intersecting coin](https://github.com/DogsTailFarmer/martin-binance/issues/18#issue-1347575119)

## v1.2.5 2022-08-20
### Fixed
Expand All @@ -31,12 +35,12 @@

## v1.2.3 - 2022-08-14
### Fixed
* [No status reply](DogsTailFarmer/martin-binance#11)
* [Stopped command in last state when low RAM](DogsTailFarmer/martin-binance#14)
* [No status reply](https://github.com/DogsTailFarmer/martin-binance/issues/11#issue-1328210503)
* [Stopped command in last state when low RAM](https://github.com/DogsTailFarmer/martin-binance/issues/14#issue-1333292978)

### Added for new features
* Protect against OS failures when saving a state file
* [No help it Telegram bot](DogsTailFarmer/martin-binance#8)
* [No help it Telegram bot](https://github.com/DogsTailFarmer/martin-binance/issues/8#issue-1315732905)
For Telegram bot set up command menu and online help

### Update
Expand All @@ -46,7 +50,7 @@ For Telegram bot set up command menu and online help

## v1.2.2 - 2022-08-08
### Update
* [Add \n on each input request](DogsTailFarmer/martin-binance#13)
* Add \n on each input request
* Handling HTTP 429 error for coinmarketcap

## v1.2.1 - 2022-08-07
Expand Down
2 changes: 1 addition & 1 deletion martin_binance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
__author__ = "Jerry Fedorenko"
__copyright__ = "Copyright © 2021 Jerry Fedorenko aka VM"
__license__ = "MIT"
__version__ = "1.2.6-7"
__version__ = "1.2.6-8"
__maintainer__ = "Jerry Fedorenko"
__contact__ = "https://github.com/DogsTailFarmer"
6 changes: 3 additions & 3 deletions martin_binance/cli_7_BTCUSDT.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
ex.GRID_MAX_COUNT = 5 # Maximum counts for placed grid orders
ex.EXTRA_CHECK_ORDER_STATE = False # Additional check for filled order(s), for (OKEX, )
# Trade parameter
ex.START_ON_BUY = False # First cycle direction
ex.AMOUNT_FIRST = Decimal('1.0') # Deposit for Sale cycle in first currency
ex.START_ON_BUY = True # First cycle direction
ex.AMOUNT_FIRST = Decimal('0.01') # Deposit for Sale cycle in first currency
ex.USE_ALL_FIRST_FUND = False # Use all available fund for first current
ex.AMOUNT_SECOND = Decimal('10000.0') # Deposit for Buy cycle in second currency
ex.AMOUNT_SECOND = Decimal('1000.0') # Deposit for Buy cycle in second currency
ex.PRICE_SHIFT = 0.01 # 'No market' shift price in % from current bid/ask price
# Round pattern, set pattern 1.0123456789 or if not set used exchange settings
ex.ROUND_BASE = str()
Expand Down
30 changes: 16 additions & 14 deletions martin_binance/margin_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import time
from decimal import Decimal
import sqlite3
from pathlib import Path

# noinspection PyPackageRequirements
import grpc
Expand Down Expand Up @@ -47,6 +48,7 @@
HEARTBEAT = 2 # Sec
RATE_LIMITER = HEARTBEAT * 5
ORDER_TIMEOUT = HEARTBEAT * 15 # Sec
LAST_STATE = None
logger = logging.getLogger('logger')
color_init()

Expand Down Expand Up @@ -472,9 +474,9 @@ def heartbeat():
last_state['ms_start_time_ms'] = json.dumps(ms.Strategy.start_time_ms)
last_state['ms.orders'] = jsonpickle.encode(ms.Strategy.orders)
# print(f"heartbeat.last_state: {last_state}")
if os.path.exists(ms.FILE_LAST_STATE):
os.rename(ms.FILE_LAST_STATE, f"{ms.FILE_LAST_STATE}.prev")
with open(ms.FILE_LAST_STATE, 'w') as outfile:
if LAST_STATE.exists():
LAST_STATE.replace(LAST_STATE.with_suffix('.prev'))
with LAST_STATE.open(mode='w') as outfile:
json.dump(last_state, outfile, sort_keys=True, indent=4, ensure_ascii=False)
time.sleep(HEARTBEAT)

Expand Down Expand Up @@ -623,12 +625,10 @@ async def ask_exit():
except Exception as _err:
print(f"ask_exit.strategy.stop: {_err}")
ms.Strategy.strategy = None
if os.path.exists(ms.FILE_LAST_STATE):
if LAST_STATE.exists():
answer = input('Save current state? y/n:\n')
if answer.lower() != 'y':
if os.path.exists(ms.FILE_LAST_STATE + '.bak'):
os.remove(ms.FILE_LAST_STATE + '.bak')
os.rename(ms.FILE_LAST_STATE, ms.FILE_LAST_STATE + '.bak')
LAST_STATE.replace(LAST_STATE.with_suffix('.bak'))
print('Current state cleared')
else:
print('OK')
Expand Down Expand Up @@ -1092,11 +1092,11 @@ async def on_order_book_update(_stub, _client_id, _symbol):


def load_last_state() -> {}:
def load_file(name) -> {}:
def load_file(name: Path) -> {}:
_res = {}
if os.path.exists(name):
if name.exists():
try:
with open(name) as state_file:
with name.open() as state_file:
_last_state = json.load(state_file)
except json.JSONDecodeError as er:
print(f"Exception on decode last state file: {er}")
Expand All @@ -1106,18 +1106,20 @@ def load_file(name) -> {}:
return _res

res = {}
if os.path.exists(ms.FILE_LAST_STATE):
res = load_file(ms.FILE_LAST_STATE)
if LAST_STATE.exists():
res = load_file(LAST_STATE)
if not res:
print("Can't load last state, try load previous saved state")
res = load_file(f"{ms.FILE_LAST_STATE}.prev")
res = load_file(LAST_STATE.with_suffix('.prev'))
if res:
with open(ms.FILE_LAST_STATE + '.bak', 'w') as outfile:
with LAST_STATE.with_suffix('.bak').open(mode='w') as outfile:
json.dump(res, outfile, sort_keys=True, indent=4, ensure_ascii=False)
return res


async def main(_symbol):
global LAST_STATE
LAST_STATE = Path(ms.FILE_LAST_STATE)
try:
ms.Strategy.symbol = _symbol
StrategyBase.symbol = _symbol
Expand Down

0 comments on commit b19c2c6

Please sign in to comment.