add get_trades_for_order

This commit is contained in:
Matthias Voppichler 2018-04-15 19:39:11 +02:00
parent 11d8f7d522
commit c7d1a767f7

View File

@ -3,6 +3,7 @@
import logging import logging
from random import randint from random import randint
from typing import List, Dict, Any, Optional from typing import List, Dict, Any, Optional
from datetime import datetime
import ccxt import ccxt
import arrow import arrow
@ -312,6 +313,25 @@ def get_order(order_id: str, pair: str) -> Dict:
raise OperationalException(e) 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: def get_pair_detail_url(pair: str) -> str:
try: try:
url_base = _API.urls.get('www') 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, return _API.calculate_fee(symbol=symbol, type=type, side=side, amount=amount,
price=price, takerOrMaker=taker_or_maker)['rate'] 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)