commit
95ec2a517a
@ -33,6 +33,9 @@ See the example below:
|
|||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`stoploss` is loss in percentage that should trigger a sale.
|
||||||
|
For example value `-0.10` will cause immediate sell if the
|
||||||
|
profit dips below -10% for a given trade. This parameter is optional.
|
||||||
|
|
||||||
The other values should be self-explanatory,
|
The other values should be self-explanatory,
|
||||||
if not feel free to raise a github issue.
|
if not feel free to raise a github issue.
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
"720": 0.01,
|
"720": 0.01,
|
||||||
"0": 0.02
|
"0": 0.02
|
||||||
},
|
},
|
||||||
|
"stoploss": -0.10,
|
||||||
"poloniex": {
|
"poloniex": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"key": "key",
|
"key": "key",
|
||||||
|
35
main.py
35
main.py
@ -138,6 +138,22 @@ def close_trade_if_fulfilled(trade: Trade) -> bool:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def execute_sell(trade: Trade, current_rate: float) -> None:
|
||||||
|
# Get available balance
|
||||||
|
currency = trade.pair.split('_')[1]
|
||||||
|
balance = api_wrapper.get_balance(currency)
|
||||||
|
|
||||||
|
profit = trade.exec_sell_order(current_rate, balance)
|
||||||
|
message = '*{}:* Selling [{}]({}) at rate `{:f} (profit: {}%)`'.format(
|
||||||
|
trade.exchange.name,
|
||||||
|
trade.pair.replace('_', '/'),
|
||||||
|
api_wrapper.get_pair_detail_url(trade.pair),
|
||||||
|
trade.close_rate,
|
||||||
|
round(profit, 2)
|
||||||
|
)
|
||||||
|
logger.info(message)
|
||||||
|
TelegramHandler.send_msg(message)
|
||||||
|
|
||||||
|
|
||||||
def handle_trade(trade: Trade) -> None:
|
def handle_trade(trade: Trade) -> None:
|
||||||
"""
|
"""
|
||||||
@ -153,26 +169,17 @@ def handle_trade(trade: Trade) -> None:
|
|||||||
current_rate = api_wrapper.get_ticker(trade.pair)['bid']
|
current_rate = api_wrapper.get_ticker(trade.pair)['bid']
|
||||||
current_profit = 100 * ((current_rate - trade.open_rate) / trade.open_rate)
|
current_profit = 100 * ((current_rate - trade.open_rate) / trade.open_rate)
|
||||||
|
|
||||||
# Get available balance
|
if 'stoploss' in CONFIG & current_profit < float(CONFIG['stoploss'])*100:
|
||||||
currency = trade.pair.split('_')[1]
|
logger.debug('Stop loss hit.')
|
||||||
balance = api_wrapper.get_balance(currency)
|
execute_sell(trade, current_rate)
|
||||||
|
return
|
||||||
|
|
||||||
for duration, threshold in sorted(CONFIG['minimal_roi'].items()):
|
for duration, threshold in sorted(CONFIG['minimal_roi'].items()):
|
||||||
duration, threshold = float(duration), float(threshold)
|
duration, threshold = float(duration), float(threshold)
|
||||||
# Check if time matches and current rate is above threshold
|
# Check if time matches and current rate is above threshold
|
||||||
time_diff = (datetime.utcnow() - trade.open_date).total_seconds() / 60
|
time_diff = (datetime.utcnow() - trade.open_date).total_seconds() / 60
|
||||||
if time_diff > duration and current_rate > (1 + threshold) * trade.open_rate:
|
if time_diff > duration and current_rate > (1 + threshold) * trade.open_rate:
|
||||||
# Execute sell
|
execute_sell(trade, current_rate)
|
||||||
profit = trade.exec_sell_order(current_rate, balance)
|
|
||||||
message = '*{}:* Selling [{}]({}) at rate `{:f} (profit: {}%)`'.format(
|
|
||||||
trade.exchange.name,
|
|
||||||
trade.pair.replace('_', '/'),
|
|
||||||
api_wrapper.get_pair_detail_url(trade.pair),
|
|
||||||
trade.close_rate,
|
|
||||||
round(profit, 2)
|
|
||||||
)
|
|
||||||
logger.info(message)
|
|
||||||
TelegramHandler.send_msg(message)
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
logger.debug('Threshold not reached. (cur_profit: %1.2f%%)', current_profit)
|
logger.debug('Threshold not reached. (cur_profit: %1.2f%%)', current_profit)
|
||||||
|
1
utils.py
1
utils.py
@ -24,6 +24,7 @@ _conf_schema = {
|
|||||||
},
|
},
|
||||||
'minProperties': 1
|
'minProperties': 1
|
||||||
},
|
},
|
||||||
|
'stoploss': {'type': 'number', 'maximum': 0, 'exclusiveMaximum': True},
|
||||||
'poloniex': {'$ref': '#/definitions/exchange'},
|
'poloniex': {'$ref': '#/definitions/exchange'},
|
||||||
'bittrex': {'$ref': '#/definitions/exchange'},
|
'bittrex': {'$ref': '#/definitions/exchange'},
|
||||||
'telegram': {
|
'telegram': {
|
||||||
|
Loading…
Reference in New Issue
Block a user