Enable orders via API

This commit is contained in:
Matthias 2022-02-26 16:10:54 +01:00
parent d4fbb785b5
commit 17c9c3caf3
5 changed files with 29 additions and 6 deletions

View File

@ -120,7 +120,7 @@ class Order(_DECL_BASE):
ft_pair: str = Column(String(25), nullable=False) ft_pair: str = Column(String(25), nullable=False)
ft_is_open = Column(Boolean, nullable=False, default=True, index=True) ft_is_open = Column(Boolean, nullable=False, default=True, index=True)
order_id = Column(String(255), nullable=False, index=True) order_id: str = Column(String(255), nullable=False, index=True)
status = Column(String(255), nullable=True) status = Column(String(255), nullable=True)
symbol = Column(String(25), nullable=True) symbol = Column(String(25), nullable=True)
order_type: str = Column(String(50), nullable=True) order_type: str = Column(String(50), nullable=True)
@ -193,6 +193,9 @@ class Order(_DECL_BASE):
def to_json(self) -> Dict[str, Any]: def to_json(self) -> Dict[str, Any]:
return { return {
'pair': self.ft_pair,
'order_id': self.order_id,
'status': self.status,
'amount': self.amount, 'amount': self.amount,
'average': round(self.average, 8) if self.average else 0, 'average': round(self.average, 8) if self.average else 0,
'safe_price': self.safe_price, 'safe_price': self.safe_price,
@ -209,10 +212,8 @@ class Order(_DECL_BASE):
'order_filled_timestamp': int(self.order_filled_date.replace( 'order_filled_timestamp': int(self.order_filled_date.replace(
tzinfo=timezone.utc).timestamp() * 1000) if self.order_filled_date else None, tzinfo=timezone.utc).timestamp() * 1000) if self.order_filled_date else None,
'order_type': self.order_type, 'order_type': self.order_type,
'pair': self.ft_pair,
'price': self.price, 'price': self.price,
'remaining': self.remaining, 'remaining': self.remaining,
'status': self.status,
} }
def close_bt_order(self, close_date: datetime): def close_bt_order(self, close_date: datetime):

View File

@ -177,6 +177,22 @@ class ShowConfig(BaseModel):
max_entry_position_adjustment: int max_entry_position_adjustment: int
class OrderSchema(BaseModel):
pair: str
order_id: str
status: str
remaining: float
amount: float
safe_price: float
cost: float
filled: float
ft_order_side: str
order_type: str
is_open: bool
order_timestamp: Optional[int]
order_filled_timestamp: Optional[int]
class TradeSchema(BaseModel): class TradeSchema(BaseModel):
trade_id: int trade_id: int
pair: str pair: str
@ -224,6 +240,8 @@ class TradeSchema(BaseModel):
min_rate: Optional[float] min_rate: Optional[float]
max_rate: Optional[float] max_rate: Optional[float]
open_order_id: Optional[str] open_order_id: Optional[str]
filled_entry_orders: List[OrderSchema]
filled_exit_orders: List[OrderSchema]
class OpenTradeSchema(TradeSchema): class OpenTradeSchema(TradeSchema):

View File

@ -32,7 +32,8 @@ logger = logging.getLogger(__name__)
# 1.11: forcebuy and forcesell accept ordertype # 1.11: forcebuy and forcesell accept ordertype
# 1.12: add blacklist delete endpoint # 1.12: add blacklist delete endpoint
# 1.13: forcebuy supports stake_amount # 1.13: forcebuy supports stake_amount
API_VERSION = 1.13 # 1.14: Add entry/exit orders to trade response
API_VERSION = 1.14
# Public API, requires no auth. # Public API, requires no auth.
router_public = APIRouter() router_public = APIRouter()

View File

@ -114,7 +114,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'cost': 0.0009999999999054, 'filled': 91.07468123, 'ft_order_side': 'buy', 'cost': 0.0009999999999054, 'filled': 91.07468123, 'ft_order_side': 'buy',
'order_date': ANY, 'order_timestamp': ANY, 'order_filled_date': ANY, 'order_date': ANY, 'order_timestamp': ANY, 'order_filled_date': ANY,
'order_filled_timestamp': ANY, 'order_type': 'limit', 'price': 1.098e-05, 'order_filled_timestamp': ANY, 'order_type': 'limit', 'price': 1.098e-05,
'is_open': False, 'pair': 'ETH/BTC', 'is_open': False, 'pair': 'ETH/BTC', 'order_id': ANY,
'remaining': ANY, 'status': ANY}], 'remaining': ANY, 'status': ANY}],
'filled_exit_orders': [] 'filled_exit_orders': []
} }
@ -189,7 +189,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'cost': 0.0009999999999054, 'filled': 91.07468123, 'ft_order_side': 'buy', 'cost': 0.0009999999999054, 'filled': 91.07468123, 'ft_order_side': 'buy',
'order_date': ANY, 'order_timestamp': ANY, 'order_filled_date': ANY, 'order_date': ANY, 'order_timestamp': ANY, 'order_filled_date': ANY,
'order_filled_timestamp': ANY, 'order_type': 'limit', 'price': 1.098e-05, 'order_filled_timestamp': ANY, 'order_type': 'limit', 'price': 1.098e-05,
'is_open': False, 'pair': 'ETH/BTC', 'is_open': False, 'pair': 'ETH/BTC', 'order_id': ANY,
'remaining': ANY, 'status': ANY}], 'remaining': ANY, 'status': ANY}],
'filled_exit_orders': [] 'filled_exit_orders': []
} }

View File

@ -902,6 +902,9 @@ def test_api_status(botclient, mocker, ticker, fee, markets):
'buy_tag': None, 'buy_tag': None,
'timeframe': 5, 'timeframe': 5,
'exchange': 'binance', 'exchange': 'binance',
'filled_entry_orders': [],
'filled_exit_orders': [],
} }
mocker.patch('freqtrade.exchange.Exchange.get_rate', mocker.patch('freqtrade.exchange.Exchange.get_rate',