Skip to main content

bothan_coinbase/api/types/
request.rs

1//! Types for Coinbase WebSocket API subscription requests and responses.
2//!
3//! This module provides types for serializing and deserializing subscription requests,
4//! channels, and error responses for the Coinbase WebSocket API.
5
6use serde::{Deserialize, Serialize};
7
8use crate::api::types::channels::Channel;
9
10/// Represents the type of request for subscriptions.
11#[derive(Clone, Debug, Serialize, Deserialize)]
12#[serde(rename_all = "snake_case")]
13pub enum RequestType {
14    /// Subscribe to a channel.
15    Subscribe,
16    /// Unsubscribe from a channel.
17    Unsubscribe,
18}
19
20/// Represents a subscription request.
21#[derive(Clone, Debug, Serialize, Deserialize)]
22pub struct Request {
23    /// The type of request (subscribe or unsubscribe).
24    #[serde(rename = "type")]
25    pub type_: RequestType,
26    /// The list of product IDs to be included in the request.
27    pub product_ids: Vec<String>,
28    /// The list of channels to be included in the request.
29    pub channels: Vec<Channel>,
30}
31
32/// Represents a subscription channel.
33#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
34pub struct SubscriptionChannel {
35    /// The name of the channel.
36    pub name: String,
37    /// The list of product IDs subscribed to this channel.
38    pub product_ids: Vec<String>,
39}
40
41/// Represents the current subscriptions.
42#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
43pub struct Subscriptions {
44    /// The list of subscribed channels.
45    pub channels: Vec<SubscriptionChannel>,
46    /// The list of subscribed product IDs (optional).
47    pub product_ids: Option<Vec<String>>,
48    /// The list of subscribed account IDs (optional).
49    pub account_ids: Option<Vec<String>>,
50}
51
52/// Represents an error response from the Coinbase WebSocket API.
53#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
54pub struct Error {
55    /// The error message describing what went wrong.
56    pub message: String,
57    /// The specific reason for the error.
58    pub reason: String,
59}