changes
This commit is contained in:
@@ -167,12 +167,23 @@ class Order(_DECL_BASE):
|
||||
|
||||
def to_json(self) -> Dict[str, Any]:
|
||||
return {
|
||||
'cost': self.cost if self.cost else 0,
|
||||
'amount': self.amount,
|
||||
'price': self.price,
|
||||
'average': round(self.average, 8) if self.average else 0,
|
||||
'cost': self.cost if self.cost else 0,
|
||||
'filled': self.filled,
|
||||
'ft_order_side': self.ft_order_side,
|
||||
'order_date': self.order_date.strftime(DATETIME_PRINT_FORMAT)
|
||||
if self.order_date else None,
|
||||
'order_timestamp': int(self.order_date.replace(
|
||||
tzinfo=timezone.utc).timestamp() * 1000) if self.order_date else None,
|
||||
'order_filled_date': self.order_filled_date.strftime(DATETIME_PRINT_FORMAT)
|
||||
if self.order_filled_date else None
|
||||
if self.order_filled_date else None,
|
||||
'order_filled_timestamp': int(self.order_filled_date.replace(
|
||||
tzinfo=timezone.utc).timestamp() * 1000) if self.order_filled_date else None,
|
||||
'order_type': self.order_type,
|
||||
'price': self.price,
|
||||
'remaining': self.remaining,
|
||||
'status': self.status,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
@@ -292,11 +303,15 @@ class LocalTrade():
|
||||
return self.close_date.replace(tzinfo=timezone.utc)
|
||||
|
||||
def to_json(self) -> Dict[str, Any]:
|
||||
fill_buy = self.select_filled_orders('buy')
|
||||
buys_json = dict()
|
||||
if len(fill_buy) > 0:
|
||||
for x in range(len(fill_buy)):
|
||||
buys_json[str(x)] = fill_buy[x].to_json()
|
||||
filled_orders = self.select_filled_orders()
|
||||
filled_buys = []
|
||||
filled_sells = []
|
||||
if len(filled_orders) > 0:
|
||||
for x in range(len(filled_orders)):
|
||||
if filled_orders[x].ft_order_side == 'buy':
|
||||
filled_buys.append(filled_orders[x].to_json())
|
||||
elif filled_orders[x].ft_order_side == 'sell':
|
||||
filled_sells.append(filled_orders[x].to_json())
|
||||
|
||||
return {
|
||||
'trade_id': self.id,
|
||||
@@ -361,7 +376,8 @@ class LocalTrade():
|
||||
'max_rate': self.max_rate,
|
||||
|
||||
'open_order_id': self.open_order_id,
|
||||
'filled_buys': buys_json,
|
||||
'filled_buys': filled_buys,
|
||||
'filled_sells': filled_sells,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
@@ -631,14 +647,14 @@ class LocalTrade():
|
||||
else:
|
||||
return None
|
||||
|
||||
def select_filled_orders(self, order_side: str) -> List['Order']:
|
||||
def select_filled_orders(self, order_side: Optional[str] = None) -> List['Order']:
|
||||
"""
|
||||
Finds filled orders for this orderside.
|
||||
:param order_side: Side of the order (either 'buy' or 'sell')
|
||||
:param order_side: Side of the order (either 'buy', 'sell', or None)
|
||||
:return: array of Order objects
|
||||
"""
|
||||
return [o for o in self.orders if o.ft_order_side == order_side and
|
||||
o.ft_is_open is False and
|
||||
return [o for o in self.orders if ((o.ft_order_side == order_side) or (order_side is None))
|
||||
and o.ft_is_open is False and
|
||||
(o.filled or 0) > 0 and
|
||||
o.status in NON_OPEN_EXCHANGE_STATES]
|
||||
|
||||
|
@@ -375,37 +375,37 @@ class Telegram(RPCHandler):
|
||||
"""
|
||||
lines = []
|
||||
for x in range(len(filled_trades)):
|
||||
cur_buy_date = arrow.get(filled_trades[str(x)]["order_filled_date"])
|
||||
cur_buy_amount = filled_trades[str(x)]["amount"]
|
||||
cur_buy_average = filled_trades[str(x)]["average"]
|
||||
current_buy_datetime = arrow.get(filled_trades[x]["order_filled_date"])
|
||||
cur_buy_amount = filled_trades[x]["amount"]
|
||||
cur_buy_average = filled_trades[x]["average"]
|
||||
lines.append(" ")
|
||||
if x == 0:
|
||||
lines.append("*Buy #{}:*".format(x+1))
|
||||
lines.append("*Buy Amount:* {} ({:.8f} {})"
|
||||
.format(cur_buy_amount, filled_trades[str(x)]["cost"], base_currency))
|
||||
.format(cur_buy_amount, filled_trades[x]["cost"], base_currency))
|
||||
lines.append("*Average Buy Price:* {}".format(cur_buy_average))
|
||||
else:
|
||||
sumA = 0
|
||||
sumB = 0
|
||||
for y in range(x):
|
||||
sumA += (filled_trades[str(y)]["amount"] * filled_trades[str(y)]["average"])
|
||||
sumB += filled_trades[str(y)]["amount"]
|
||||
sumA += (filled_trades[y]["amount"] * filled_trades[y]["average"])
|
||||
sumB += filled_trades[y]["amount"]
|
||||
prev_avg_price = sumA/sumB
|
||||
price_to_1st_buy = (cur_buy_average - filled_trades["0"]["average"]) \
|
||||
/ filled_trades["0"]["average"]
|
||||
price_to_1st_buy = (cur_buy_average - filled_trades[0]["average"]) \
|
||||
/ filled_trades[0]["average"]
|
||||
minus_on_buy = (cur_buy_average - prev_avg_price)/prev_avg_price
|
||||
dur_buys = cur_buy_date - arrow.get(filled_trades[str(x-1)]["order_filled_date"])
|
||||
dur_buys = current_buy_datetime - arrow.get(filled_trades[x-1]["order_filled_date"])
|
||||
days = dur_buys.days
|
||||
hours, remainder = divmod(dur_buys.seconds, 3600)
|
||||
minutes, seconds = divmod(remainder, 60)
|
||||
lines.append("*Buy #{}:* at {:.2%} avg profit".format(x+1, minus_on_buy))
|
||||
lines.append("({})".format(cur_buy_date
|
||||
lines.append("({})".format(current_buy_datetime
|
||||
.humanize(granularity=["day", "hour", "minute"])))
|
||||
lines.append("*Buy Amount:* {} ({:.8f} {})"
|
||||
.format(cur_buy_amount, filled_trades[str(x)]["cost"], base_currency))
|
||||
.format(cur_buy_amount, filled_trades[x]["cost"], base_currency))
|
||||
lines.append("*Average Buy Price:* {} ({:.2%} from 1st buy rate)"
|
||||
.format(cur_buy_average, price_to_1st_buy))
|
||||
lines.append("*Filled at:* {}".format(filled_trades[str(x)]["order_filled_date"]))
|
||||
lines.append("*Order filled at:* {}".format(filled_trades[x]["order_filled_date"]))
|
||||
lines.append("({}d {}h {}m {}s from previous buy)"
|
||||
.format(days, hours, minutes, seconds))
|
||||
return lines
|
||||
@@ -437,7 +437,6 @@ class Telegram(RPCHandler):
|
||||
messages = []
|
||||
for r in results:
|
||||
r['open_date_hum'] = arrow.get(r['open_date']).humanize()
|
||||
r['filled_buys'] = r.get('filled_buys', [])
|
||||
r['num_buys'] = len(r['filled_buys'])
|
||||
r['sell_reason'] = r.get('sell_reason', "")
|
||||
r['position_adjustment_enable'] = r.get('position_adjustment_enable', False)
|
||||
|
Reference in New Issue
Block a user