Timestamps are in ms

This commit is contained in:
Matthias 2020-08-13 15:39:29 +02:00
parent 73182bb2dd
commit 0af9e913d4
5 changed files with 15 additions and 7 deletions

View File

@ -486,7 +486,7 @@ class Exchange:
'side': side,
'remaining': _amount,
'datetime': arrow.utcnow().isoformat(),
'timestamp': arrow.utcnow().timestamp,
'timestamp': int(arrow.utcnow().timestamp * 1000),
'status': "closed" if ordertype == "market" else "open",
'fee': None,
'info': {}

View File

@ -817,6 +817,9 @@ class FreqtradeBot:
except InvalidOrderException as exception:
logger.warning('Unable to fetch stoploss order: %s', exception)
if stoploss_order:
trade.update_order(stoploss_order)
# We check if stoploss order is fulfilled
if stoploss_order and stoploss_order['status'] in ('closed', 'triggered'):
trade.sell_reason = SellType.STOPLOSS_ON_EXCHANGE.value
@ -1260,7 +1263,7 @@ class FreqtradeBot:
except InvalidOrderException as exception:
logger.warning('Unable to fetch order %s: %s', order_id, exception)
return False
Order.update_order(order)
trade.update_order(order)
# Try update amount (binance-fix)
try:
new_amount = self.get_real_amount(trade, order, order_amount)

View File

@ -107,7 +107,7 @@ class Order(_DECL_BASE):
ft_order_side = Column(String, nullable=False)
order_id = Column(String, nullable=False, unique=True, index=True)
order_id = Column(String, nullable=False, index=True)
status = Column(String, nullable=True)
symbol = Column(String, nullable=True)
order_type = Column(String, nullable=True)
@ -144,13 +144,14 @@ class Order(_DECL_BASE):
self.remaining = order.get('remaining', self.remaining)
self.cost = order.get('cost', self.cost)
if 'timestamp' in order and order['timestamp'] is not None:
self.order_date = datetime.fromtimestamp(order['timestamp'])
self.order_date = datetime.fromtimestamp(order['timestamp'] / 1000)
@staticmethod
def update_order(order: Dict[str, Any]):
def update_orders(orders: List['Order'], order: Dict[str, Any]):
"""
"""
oobj = Order.query.filter(Order.order_id == order['id']).first()
filtered_orders = [o for o in orders if o.order_id == order['id']]
oobj = filtered_orders[0] if filtered_orders else None
oobj.update_from_ccxt_object(order)
oobj.order_update_date = datetime.now()
@ -417,6 +418,9 @@ class Trade(_DECL_BASE):
else:
return False
def update_order(self, order: Dict) -> None:
Order.update_orders(self.orders, order)
def _calc_open_trade_price(self) -> float:
"""
Calculate the open_rate including open_fee.

View File

@ -807,7 +807,7 @@ def test_dry_run_order(default_conf, mocker, side, exchange_name):
assert f'dry_run_{side}_' in order["id"]
assert order["side"] == side
assert order["type"] == "limit"
assert order["pair"] == "ETH/BTC"
assert order["symbol"] == "ETH/BTC"
@pytest.mark.parametrize("side", [

View File

@ -1194,6 +1194,7 @@ def test_handle_stoploss_on_exchange(mocker, default_conf, fee, caplog,
assert trade
stoploss_order_hit = MagicMock(return_value={
'id': 100,
'status': 'closed',
'type': 'stop_loss_limit',
'price': 3,