From c7d1a767f75457d2bef930a9b13edc7848c925b0 Mon Sep 17 00:00:00 2001 From: Matthias Voppichler Date: Sun, 15 Apr 2018 19:39:11 +0200 Subject: [PATCH] add get_trades_for_order --- freqtrade/exchange/__init__.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 6406fe769..91196ca06 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -3,6 +3,7 @@ import logging from random import randint from typing import List, Dict, Any, Optional +from datetime import datetime import ccxt import arrow @@ -312,6 +313,25 @@ def get_order(order_id: str, pair: str) -> Dict: raise OperationalException(e) +def get_trades_for_order(order_id: str, pair: str, since: datetime) -> List: + if _CONF['dry_run']: + return [] + if not exchange_has('fetchMyTrades'): + return [] + try: + my_trades = _API.fetch_my_trades(pair, since.timestamp()) + matched_trades = [trade for trade in my_trades if trade['order'] == order_id] + + return matched_trades + + except ccxt.NetworkError as e: + raise NetworkException( + 'Could not get trades due to networking error. Message: {}'.format(e) + ) + except ccxt.BaseError as e: + raise OperationalException(e) + + def get_pair_detail_url(pair: str) -> str: try: url_base = _API.urls.get('www') @@ -350,3 +370,13 @@ def get_fee(symbol='ETH/BTC', type='', side='', amount=1, return _API.calculate_fee(symbol=symbol, type=type, side=side, amount=amount, price=price, takerOrMaker=taker_or_maker)['rate'] + + +def get_amount_lots(pair: str, amount: float) -> float: + """ + get buyable amount rounding, .. + """ + # validate that markets are loaded before trying to get fee + if _API.markets is None or len(_API.markets) == 0: + _API.load_markets() + return _API.amount_to_lots(pair, amount)