Repository: freqtrade/freqtrade

Issue:
Telegram: Market orders are identified as limit (Binance)
## Step 1: Have you search for this issue before posting it?

## Step 2: Describe your environment

  * Python Version: python3.7
  * CCXT version: 1.18.551 
  * Branch: Master | Develop
  
## Step 3: Describe the problem:

I'm using market orders for my strategy, the bot is executing proper market orders on the exchange (binance) and i've verified them on exchange, the only issue is that the telegram bot says that its a limit order

example:

Binance: Buying SKY/BTC
with limit 0.00022700
(0.004692 BTC,40.586 USD)

Binance: Selling ZEN/BTC
Limit: 0.00134500
Amount: 3.49200000
Open Rate: 0.00128900
Current Rate: 0.00134500
Sell Reason: force_sell
Profit: 4.14% (profit: 0.00018636 BTC / 1.612 USD)


### Steps to reproduce:

1. Run binance
2. Use both market for buy/sell




Discussion:
well ... err ... yes ... it's "kinda" hardcoded in the `telegram.py` file (it's not getting the information about the trade type).

definitely something we should look at and fix
Should I mark this as solved? @xmatthias let me know.
nah, it's plain wrong currently, so i'd leave this open until we get to fix it.
It's not a one-liner , as we first need to add this information to what is sent to RPC handlers - so don't expect this to be fixed right away.

Resolving patch:
diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py
--- a/freqtrade/freqtradebot.py
+++ b/freqtrade/freqtradebot.py
@@ -345,8 +345,8 @@ def execute_buy(self, pair: str, stake_amount: float, price: Optional[float] = N
             return False
 
         amount = stake_amount / buy_limit_requested
-
-        order = self.exchange.buy(pair=pair, ordertype=self.strategy.order_types['buy'],
+        order_type = self.strategy.order_types['buy']
+        order = self.exchange.buy(pair=pair, ordertype=order_type,
                                   amount=amount, rate=buy_limit_requested,
                                   time_in_force=time_in_force)
         order_id = order['id']
@@ -356,7 +356,6 @@ def execute_buy(self, pair: str, stake_amount: float, price: Optional[float] = N
         buy_limit_filled_price = buy_limit_requested
 
         if order_status == 'expired' or order_status == 'rejected':
-            order_type = self.strategy.order_types['buy']
             order_tif = self.strategy.order_time_in_force['buy']
 
             # return false if the order is not filled
@@ -390,6 +389,7 @@ def execute_buy(self, pair: str, stake_amount: float, price: Optional[float] = N
             'exchange': self.exchange.name.capitalize(),
             'pair': pair_s,
             'limit': buy_limit_filled_price,
+            'order_type': order_type,
             'stake_amount': stake_amount,
             'stake_currency': stake_currency,
             'fiat_currency': fiat_currency
@@ -875,6 +875,7 @@ def notify_sell(self, trade: Trade):
             'pair': trade.pair,
             'gain': gain,
             'limit': trade.close_rate_requested,
+            'order_type': self.strategy.order_types['sell'],
             'amount': trade.amount,
             'open_rate': trade.open_rate,
             'current_rate': current_rate,
diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py
--- a/freqtrade/rpc/telegram.py
+++ b/freqtrade/rpc/telegram.py
@@ -132,7 +132,7 @@ def send_msg(self, msg: Dict[str, Any]) -> None:
                 msg['stake_amount_fiat'] = 0
 
             message = ("*{exchange}:* Buying {pair}\n"
-                       "with limit `{limit:.8f}\n"
+                       "at rate `{limit:.8f}\n"
                        "({stake_amount:.6f} {stake_currency}").format(**msg)
 
             if msg.get('fiat_currency', None):
@@ -144,7 +144,7 @@ def send_msg(self, msg: Dict[str, Any]) -> None:
             msg['profit_percent'] = round(msg['profit_percent'] * 100, 2)
 
             message = ("*{exchange}:* Selling {pair}\n"
-                       "*Limit:* `{limit:.8f}`\n"
+                       "*Rate:* `{limit:.8f}`\n"
                        "*Amount:* `{amount:.8f}`\n"
                        "*Open Rate:* `{open_rate:.8f}`\n"
                        "*Current Rate:* `{current_rate:.8f}`\n"


Test patch:
diff --git a/freqtrade/tests/rpc/test_rpc_telegram.py b/freqtrade/tests/rpc/test_rpc_telegram.py
--- a/freqtrade/tests/rpc/test_rpc_telegram.py
+++ b/freqtrade/tests/rpc/test_rpc_telegram.py
@@ -756,6 +756,7 @@ def test_forcesell_handle(default_conf, update, ticker, fee,
         'gain': 'profit',
         'limit': 1.172e-05,
         'amount': 90.99181073703367,
+        'order_type': 'limit',
         'open_rate': 1.099e-05,
         'current_rate': 1.172e-05,
         'profit_amount': 6.126e-05,
@@ -810,6 +811,7 @@ def test_forcesell_down_handle(default_conf, update, ticker, fee,
         'gain': 'loss',
         'limit': 1.044e-05,
         'amount': 90.99181073703367,
+        'order_type': 'limit',
         'open_rate': 1.099e-05,
         'current_rate': 1.044e-05,
         'profit_amount': -5.492e-05,
@@ -855,6 +857,7 @@ def test_forcesell_all_handle(default_conf, update, ticker, fee, markets, mocker
         'gain': 'loss',
         'limit': 1.098e-05,
         'amount': 90.99181073703367,
+        'order_type': 'limit',
         'open_rate': 1.099e-05,
         'current_rate': 1.098e-05,
         'profit_amount': -5.91e-06,
@@ -1188,6 +1191,7 @@ def test_send_msg_buy_notification(default_conf, mocker) -> None:
         'exchange': 'Bittrex',
         'pair': 'ETH/BTC',
         'limit': 1.099e-05,
+        'order_type': 'limit',
         'stake_amount': 0.001,
         'stake_amount_fiat': 0.0,
         'stake_currency': 'BTC',
@@ -1195,7 +1199,7 @@ def test_send_msg_buy_notification(default_conf, mocker) -> None:
     })
     assert msg_mock.call_args[0][0] \
         == '*Bittrex:* Buying ETH/BTC\n' \
-           'with limit `0.00001099\n' \
+           'at rate `0.00001099\n' \
            '(0.001000 BTC,0.000 USD)`'
 
 
@@ -1217,6 +1221,7 @@ def test_send_msg_sell_notification(default_conf, mocker) -> None:
         'gain': 'loss',
         'limit': 3.201e-05,
         'amount': 1333.3333333333335,
+        'order_type': 'market',
         'open_rate': 7.5e-05,
         'current_rate': 3.201e-05,
         'profit_amount': -0.05746268,
@@ -1227,7 +1232,7 @@ def test_send_msg_sell_notification(default_conf, mocker) -> None:
     })
     assert msg_mock.call_args[0][0] \
         == ('*Binance:* Selling KEY/ETH\n'
-            '*Limit:* `0.00003201`\n'
+            '*Rate:* `0.00003201`\n'
             '*Amount:* `1333.33333333`\n'
             '*Open Rate:* `0.00007500`\n'
             '*Current Rate:* `0.00003201`\n'
@@ -1242,6 +1247,7 @@ def test_send_msg_sell_notification(default_conf, mocker) -> None:
         'gain': 'loss',
         'limit': 3.201e-05,
         'amount': 1333.3333333333335,
+        'order_type': 'market',
         'open_rate': 7.5e-05,
         'current_rate': 3.201e-05,
         'profit_amount': -0.05746268,
@@ -1251,7 +1257,7 @@ def test_send_msg_sell_notification(default_conf, mocker) -> None:
     })
     assert msg_mock.call_args[0][0] \
         == ('*Binance:* Selling KEY/ETH\n'
-            '*Limit:* `0.00003201`\n'
+            '*Rate:* `0.00003201`\n'
             '*Amount:* `1333.33333333`\n'
             '*Open Rate:* `0.00007500`\n'
             '*Current Rate:* `0.00003201`\n'
@@ -1339,6 +1345,7 @@ def test_send_msg_buy_notification_no_fiat(default_conf, mocker) -> None:
         'exchange': 'Bittrex',
         'pair': 'ETH/BTC',
         'limit': 1.099e-05,
+        'order_type': 'limit',
         'stake_amount': 0.001,
         'stake_amount_fiat': 0.0,
         'stake_currency': 'BTC',
@@ -1346,7 +1353,7 @@ def test_send_msg_buy_notification_no_fiat(default_conf, mocker) -> None:
     })
     assert msg_mock.call_args[0][0] \
         == '*Bittrex:* Buying ETH/BTC\n' \
-           'with limit `0.00001099\n' \
+           'at rate `0.00001099\n' \
            '(0.001000 BTC)`'
 
 
@@ -1367,6 +1374,7 @@ def test_send_msg_sell_notification_no_fiat(default_conf, mocker) -> None:
         'gain': 'loss',
         'limit': 3.201e-05,
         'amount': 1333.3333333333335,
+        'order_type': 'limit',
         'open_rate': 7.5e-05,
         'current_rate': 3.201e-05,
         'profit_amount': -0.05746268,
@@ -1377,7 +1385,7 @@ def test_send_msg_sell_notification_no_fiat(default_conf, mocker) -> None:
     })
     assert msg_mock.call_args[0][0] \
         == '*Binance:* Selling KEY/ETH\n' \
-           '*Limit:* `0.00003201`\n' \
+           '*Rate:* `0.00003201`\n' \
            '*Amount:* `1333.33333333`\n' \
            '*Open Rate:* `0.00007500`\n' \
            '*Current Rate:* `0.00003201`\n' \
diff --git a/freqtrade/tests/rpc/test_rpc_webhook.py b/freqtrade/tests/rpc/test_rpc_webhook.py
--- a/freqtrade/tests/rpc/test_rpc_webhook.py
+++ b/freqtrade/tests/rpc/test_rpc_webhook.py
@@ -74,6 +74,7 @@ def test_send_msg(default_conf, mocker):
         'gain': "profit",
         'limit': 0.005,
         'amount': 0.8,
+        'order_type': 'limit',
         'open_rate': 0.004,
         'current_rate': 0.005,
         'profit_amount': 0.001,
@@ -126,6 +127,7 @@ def test_exception_send_msg(default_conf, mocker, caplog):
         'exchange': 'Bittrex',
         'pair': 'ETH/BTC',
         'limit': 0.005,
+        'order_type': 'limit',
         'stake_amount': 0.8,
         'stake_amount_fiat': 500,
         'stake_currency': 'BTC',
diff --git a/freqtrade/tests/test_freqtradebot.py b/freqtrade/tests/test_freqtradebot.py
--- a/freqtrade/tests/test_freqtradebot.py
+++ b/freqtrade/tests/test_freqtradebot.py
@@ -1994,6 +1994,7 @@ def test_execute_sell_up(default_conf, ticker, fee, ticker_sell_up, markets, moc
         'gain': 'profit',
         'limit': 1.172e-05,
         'amount': 90.99181073703367,
+        'order_type': 'limit',
         'open_rate': 1.099e-05,
         'current_rate': 1.172e-05,
         'profit_amount': 6.126e-05,
@@ -2040,6 +2041,7 @@ def test_execute_sell_down(default_conf, ticker, fee, ticker_sell_down, markets,
         'gain': 'loss',
         'limit': 1.044e-05,
         'amount': 90.99181073703367,
+        'order_type': 'limit',
         'open_rate': 1.099e-05,
         'current_rate': 1.044e-05,
         'profit_amount': -5.492e-05,
@@ -2094,6 +2096,7 @@ def test_execute_sell_down_stoploss_on_exchange_dry_run(default_conf, ticker, fe
         'gain': 'loss',
         'limit': 1.08801e-05,
         'amount': 90.99181073703367,
+        'order_type': 'limit',
         'open_rate': 1.099e-05,
         'current_rate': 1.044e-05,
         'profit_amount': -1.498e-05,
@@ -2265,6 +2268,7 @@ def test_execute_sell_without_conf_sell_up(default_conf, ticker, fee,
         'gain': 'profit',
         'limit': 1.172e-05,
         'amount': 90.99181073703367,
+        'order_type': 'limit',
         'open_rate': 1.099e-05,
         'current_rate': 1.172e-05,
         'profit_amount': 6.126e-05,
@@ -2312,6 +2316,7 @@ def test_execute_sell_without_conf_sell_down(default_conf, ticker, fee,
         'gain': 'loss',
         'limit': 1.044e-05,
         'amount': 90.99181073703367,
+        'order_type': 'limit',
         'open_rate': 1.099e-05,
         'current_rate': 1.044e-05,
         'profit_amount': -5.492e-05,