nautilus_kraken/common/models.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Common data structures shared across the Kraken adapter.
17
18use serde::{Deserialize, Serialize};
19
20/// Generic Kraken API response wrapper.
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct KrakenResponse<T> {
23 pub result: Option<T>,
24 pub error: Option<Vec<String>>,
25 #[serde(default)]
26 pub success: bool,
27}
28
29impl<T> KrakenResponse<T> {
30 pub fn is_success(&self) -> bool {
31 self.success || (self.error.is_none() || self.error.as_ref().is_some_and(|e| e.is_empty()))
32 }
33
34 pub fn error_message(&self) -> Option<String> {
35 self.error
36 .as_ref()
37 .filter(|e| !e.is_empty())
38 .map(|e| e.join(", "))
39 }
40}