mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
add typehints
This commit is contained in:
19
main.py
19
main.py
@@ -5,11 +5,13 @@ import time
|
||||
import traceback
|
||||
from datetime import datetime
|
||||
from json import JSONDecodeError
|
||||
from typing import Optional
|
||||
|
||||
from requests import ConnectionError
|
||||
from wrapt import synchronized
|
||||
from analyze import get_buy_signal
|
||||
from persistence import Trade, Session
|
||||
from exchange import get_exchange_api
|
||||
from exchange import get_exchange_api, Exchange
|
||||
from rpc.telegram import TelegramHandler
|
||||
from utils import get_conf
|
||||
|
||||
@@ -32,11 +34,11 @@ class TradeThread(threading.Thread):
|
||||
super().__init__()
|
||||
self._should_stop = False
|
||||
|
||||
def stop(self):
|
||||
def stop(self) -> None:
|
||||
""" stops the trader thread """
|
||||
self._should_stop = True
|
||||
|
||||
def run(self):
|
||||
def run(self) -> None:
|
||||
"""
|
||||
Threaded main function
|
||||
:return: None
|
||||
@@ -60,7 +62,7 @@ class TradeThread(threading.Thread):
|
||||
TelegramHandler.send_msg('*Status:* `Trader has stopped`')
|
||||
|
||||
@staticmethod
|
||||
def _process():
|
||||
def _process() -> None:
|
||||
"""
|
||||
Queries the persistence layer for open trades and handles them,
|
||||
otherwise a new trade is created.
|
||||
@@ -107,8 +109,9 @@ class TradeThread(threading.Thread):
|
||||
# Initial stopped TradeThread instance
|
||||
_instance = TradeThread()
|
||||
|
||||
|
||||
@synchronized
|
||||
def get_instance(recreate=False):
|
||||
def get_instance(recreate: bool=False) -> TradeThread:
|
||||
"""
|
||||
Get the current instance of this thread. This is a singleton.
|
||||
:param recreate: Must be True if you want to start the instance
|
||||
@@ -122,7 +125,7 @@ def get_instance(recreate=False):
|
||||
return _instance
|
||||
|
||||
|
||||
def close_trade_if_fulfilled(trade):
|
||||
def close_trade_if_fulfilled(trade: Trade) -> bool:
|
||||
"""
|
||||
Checks if the trade is closable, and if so it is being closed.
|
||||
:param trade: Trade
|
||||
@@ -137,7 +140,7 @@ def close_trade_if_fulfilled(trade):
|
||||
return False
|
||||
|
||||
|
||||
def handle_trade(trade):
|
||||
def handle_trade(trade: Trade) -> None:
|
||||
"""
|
||||
Sells the current pair if the threshold is reached and updates the trade record.
|
||||
:return: None
|
||||
@@ -178,7 +181,7 @@ def handle_trade(trade):
|
||||
logger.exception('Unable to handle open order')
|
||||
|
||||
|
||||
def create_trade(stake_amount: float, exchange):
|
||||
def create_trade(stake_amount: float, exchange: Exchange) -> Optional[Trade]:
|
||||
"""
|
||||
Checks the implemented trading indicator(s) for a randomly picked pair,
|
||||
if one pair triggers the buy_signal a new trade record gets created
|
||||
|
||||
Reference in New Issue
Block a user