{
  "openapi": "3.0.3",
  "info": {
    "title": "CIYL API - Public Capabilities Overview",
    "version": "3.1.0",
    "description": "Public overview of CIYL (Crypto Investment Infrastructure) API capabilities. This complete API is available for white-label deployments. The endpoints described below represent the main functions accessible to finance professionals.\\n\\n**Important**: Full access to these endpoints requires authentication and a dedicated deployment. Complete Swagger documentation is available directly on the CIYL deployment server.",
    "contact": {
      "name": "CIYL Support",
      "url": "https://ciyl.ch/#contact",
      "email": "contact@ciyl.ch"
    },
    "license": {
      "name": "Proprietary - All rights reserved",
      "url": "https://ciyl.ch"
    }
  },
  "externalDocs": {
    "description": "Find out more about CIYL",
    "url": "https://ciyl.ch"
  },
  "servers": [
    {
      "url": "{deployment_url}/ci-api",
      "description": "CIYL deployment server (variable per client)",
      "variables": {
        "deployment_url": {
          "default": "https://client.ciyl.ch",
          "description": "Specific client CIYL deployment URL"
        }
      }
    }
  ],
  "tags": [
    {
      "name": "Authentication",
      "description": "JWT authentication and session management"
    },
    {
      "name": "Customers",
      "description": "Multi-client management (family offices, asset managers)"
    },
    {
      "name": "Portfolio",
      "description": "Crypto portfolio tracking and management"
    },
    {
      "name": "Vault",
      "description": "Held crypto positions and valuation"
    },
    {
      "name": "Trading",
      "description": "Order execution and transaction management"
    },
    {
      "name": "Cryptocurrencies",
      "description": "Cryptocurrency catalog and information"
    },
    {
      "name": "AI Analysis",
      "description": "AI analysis and recommendations (GPT-4)"
    },
    {
      "name": "Funds",
      "description": "Fund management and NAV calculation"
    },
    {
      "name": "Import",
      "description": "Data import and synchronization"
    }
  ],
  "paths": {
    "/signup": {
      "post": {
        "summary": "Create user account",
        "description": "Register a new user with organization creation",
        "tags": ["Authentication"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email", "password", "name"],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "example": "manager@example.com"
                  },
                  "password": {
                    "type": "string",
                    "minLength": 8,
                    "description": "Secure password (bcrypt)"
                  },
                  "name": {
                    "type": "string",
                    "description": "Organization/asset manager name"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Account created successfully - JWT token returned"
          },
          "400": {
            "description": "Invalid data"
          },
          "409": {
            "description": "Email already in use"
          }
        }
      }
    },
    "/signin": {
      "post": {
        "summary": "User login",
        "description": "Authenticate and obtain JWT token",
        "tags": ["Authentication"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email", "password"],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "password": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Authentication successful - JWT and refresh token"
          },
          "401": {
            "description": "Invalid credentials"
          }
        }
      }
    },
    "/auth-check": {
      "get": {
        "summary": "Check authentication status",
        "description": "Verify JWT token and retrieve user information",
        "tags": ["Authentication"],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Valid token - User information"
          },
          "401": {
            "description": "Invalid or expired token"
          }
        }
      }
    },
    "/customers": {
      "get": {
        "summary": "List all customers",
        "description": "Retrieves the list of customers managed by the authenticated user (family offices, asset managers). Allows viewing all client portfolios in a consolidated environment.",
        "tags": ["Customers"],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Customer list with metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "_id": {
                        "type": "string",
                        "description": "Unique customer identifier"
                      },
                      "name": {
                        "type": "string",
                        "description": "Customer or organization name"
                      },
                      "email": {
                        "type": "string",
                        "description": "Contact email"
                      },
                      "portfolioCount": {
                        "type": "integer",
                        "description": "Number of associated portfolios"
                      },
                      "totalValue": {
                        "type": "number",
                        "description": "Total asset value (USD)"
                      },
                      "createdAt": {
                        "type": "string",
                        "format": "date-time"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          }
        }
      },
      "post": {
        "summary": "Create new customer",
        "description": "Add a new customer to the asset manager's environment. Each customer can have multiple associated portfolios.",
        "tags": ["Customers"],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name", "email"],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Customer name"
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "phone": {
                    "type": "string"
                  },
                  "kycData": {
                    "type": "object",
                    "description": "KYC data if applicable"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Customer created successfully"
          },
          "400": {
            "description": "Invalid data"
          }
        }
      }
    },
    "/customers/{id}": {
      "get": {
        "summary": "Get customer details",
        "description": "Retrieve complete information for a specific customer, including their portfolios and positions",
        "tags": ["Customers"],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Customer ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Customer details"
          },
          "404": {
            "description": "Customer not found"
          }
        }
      }
    },
    "/vault": {
      "get": {
        "summary": "Held positions (Vault)",
        "description": "Retrieves all currently held crypto positions across all portfolios and connected exchanges. Provides a consolidated view of assets.",
        "tags": ["Vault"],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "customerId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by specific customer"
          }
        ],
        "responses": {
          "200": {
            "description": "Position list with quantities and values",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "positions": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "symbol": {
                            "type": "string",
                            "example": "BTC"
                          },
                          "name": {
                            "type": "string",
                            "example": "Bitcoin"
                          },
                          "quantity": {
                            "type": "number"
                          },
                          "avgBuyPrice": {
                            "type": "number",
                            "description": "Average buy price"
                          },
                          "currentPrice": {
                            "type": "number"
                          },
                          "valueUSD": {
                            "type": "number"
                          },
                          "pnl": {
                            "type": "number",
                            "description": "Profit/Loss"
                          },
                          "pnlPercent": {
                            "type": "number"
                          }
                        }
                      }
                    },
                    "totalValueUSD": {
                      "type": "number"
                    },
                    "totalPnl": {
                      "type": "number"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/trades": {
      "get": {
        "summary": "Transaction history",
        "description": "Lists all executed transactions. Enables historical analysis and performance tracking.",
        "tags": ["Trading"],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "customerId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "symbol",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by cryptocurrency (e.g., BTC)"
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Start date (YYYY-MM-DD)"
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "End date (YYYY-MM-DD)"
          }
        ],
        "responses": {
          "200": {
            "description": "Transaction list"
          }
        }
      },
      "post": {
        "summary": "Create trading order",
        "description": "Execute a buy or sell order on connected exchanges (Binance, Coinbase). Supports Market, Limit, Stop-loss, and Take-profit orders.",
        "tags": ["Trading"],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["symbol", "side", "type", "quantity"],
                "properties": {
                  "symbol": {
                    "type": "string",
                    "example": "BTCUSDT",
                    "description": "Trading pair"
                  },
                  "side": {
                    "type": "string",
                    "enum": ["BUY", "SELL"],
                    "description": "Order side"
                  },
                  "type": {
                    "type": "string",
                    "enum": ["MARKET", "LIMIT", "STOP_LOSS", "TAKE_PROFIT"],
                    "description": "Order type"
                  },
                  "quantity": {
                    "type": "number",
                    "description": "Quantity to trade"
                  },
                  "price": {
                    "type": "number",
                    "description": "Limit price (required for LIMIT)"
                  },
                  "customerId": {
                    "type": "string",
                    "description": "Customer to trade for"
                  },
                  "exchange": {
                    "type": "string",
                    "enum": ["binance", "coinbase"],
                    "description": "Exchange to use"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Order created successfully"
          },
          "400": {
            "description": "Invalid parameters"
          },
          "402": {
            "description": "Insufficient balance or missing permissions"
          }
        }
      }
    },
    "/cryptos": {
      "get": {
        "summary": "Cryptocurrency catalog",
        "description": "Lists 10,000+ available cryptocurrencies via CoinMarketCap integration. Real-time updated data.",
        "tags": ["Cryptocurrencies"],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Search by name or symbol"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            },
            "description": "Maximum number of results"
          }
        ],
        "responses": {
          "200": {
            "description": "Cryptocurrency list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "symbol": {
                        "type": "string"
                      },
                      "name": {
                        "type": "string"
                      },
                      "priceUSD": {
                        "type": "number"
                      },
                      "marketCap": {
                        "type": "number"
                      },
                      "volume24h": {
                        "type": "number"
                      },
                      "percentChange24h": {
                        "type": "number"
                      },
                      "rank": {
                        "type": "integer"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/cryptos/{symbol}/timeline": {
      "get": {
        "summary": "Crypto AI timeline",
        "description": "Retrieves historical and contextual analysis generated by Sofia AI (GPT-4.1). Includes key events, fundamentals, and technical analysis.",
        "tags": ["AI Analysis"],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "symbol",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Cryptocurrency symbol (e.g., BTC)"
          }
        ],
        "responses": {
          "200": {
            "description": "Complete AI analysis",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "symbol": {
                      "type": "string"
                    },
                    "aiAnalysis": {
                      "type": "string",
                      "description": "Text analysis generated by GPT-4.1"
                    },
                    "keyEvents": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "date": {
                            "type": "string"
                          },
                          "event": {
                            "type": "string"
                          },
                          "impact": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "fundamentals": {
                      "type": "object",
                      "properties": {
                        "technology": {
                          "type": "string"
                        },
                        "useCase": {
                          "type": "string"
                        },
                        "tokenomics": {
                          "type": "string"
                        }
                      }
                    },
                    "sentimentScore": {
                      "type": "number",
                      "description": "Score -1 to 1 (bearish to bullish)"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Cryptocurrency not found"
          }
        }
      }
    },
    "/ai-analyse/market": {
      "get": {
        "summary": "AI market analysis",
        "description": "Retrieves macroeconomic and market analysis generated by Sofia. Includes FRED indicators, DXY, liquidity rates, and sector recommendations.",
        "tags": ["AI Analysis"],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Complete market analysis",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "marketSummary": {
                      "type": "string",
                      "description": "AI-generated market text summary"
                    },
                    "macroIndicators": {
                      "type": "object",
                      "properties": {
                        "dxy": {
                          "type": "number"
                        },
                        "fedRate": {
                          "type": "number"
                        },
                        "inflation": {
                          "type": "number"
                        },
                        "liquidity": {
                          "type": "string",
                          "enum": ["tight", "neutral", "loose"]
                        }
                      }
                    },
                    "sectorAnalysis": {
                      "type": "array",
                      "description": "Crypto sector analysis"
                    },
                    "recommendations": {
                      "type": "array",
                      "description": "AI recommendations"
                    },
                    "generatedAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/fund/nav": {
      "get": {
        "summary": "NAV calculation (Net Asset Value)",
        "description": "Calculates fund NAV in real-time based on all positions and donations/withdrawals. Essential for fund management.",
        "tags": ["Funds"],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Calculated NAV",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "nav": {
                      "type": "number",
                      "description": "Total Net Asset Value"
                    },
                    "navPerShare": {
                      "type": "number",
                      "description": "NAV per share/unit"
                    },
                    "totalShares": {
                      "type": "number"
                    },
                    "aum": {
                      "type": "number",
                      "description": "Assets Under Management"
                    },
                    "investors": {
                      "type": "integer"
                    },
                    "calculatedAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/import/trades": {
      "post": {
        "summary": "Import transactions",
        "description": "Import transaction history via CSV or API (Binance, Coinbase). Enables data migration and historical consolidation.",
        "tags": ["Import"],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "CSV transaction file"
                  },
                  "source": {
                    "type": "string",
                    "enum": ["binance", "coinbase", "csv"],
                    "description": "Data source"
                  },
                  "customerId": {
                    "type": "string",
                    "description": "Target customer"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Import successful",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "imported": {
                      "type": "integer"
                    },
                    "skipped": {
                      "type": "integer"
                    },
                    "errors": {
                      "type": "array"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "JWT token obtained during login. Limited validity with automatic refresh."
      }
    },
    "schemas": {
      "Customer": {
        "type": "object",
        "properties": {
          "_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Position": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string"
          },
          "quantity": {
            "type": "number"
          },
          "valueUSD": {
            "type": "number"
          }
        }
      },
      "Trade": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string"
          },
          "side": {
            "type": "string",
            "enum": ["BUY", "SELL"]
          },
          "quantity": {
            "type": "number"
          },
          "price": {
            "type": "number"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  },
  "x-ciyl-capabilities": {
    "description": "Additional technical capabilities",
    "architecture": {
      "pattern": "MVC (Model-View-Controller)",
      "frontend": "Angular 20+ (Standalone Components, Signals, RxJS)",
      "backend": "Node.js 20+ / Express.js",
      "database": "MongoDB 5.0+ with Mongoose",
      "auth": "JWT with refresh tokens + Passport.js",
      "security": "bcrypt hashing, IP whitelist, input validation (Joi)",
      "caching": "Multi-level cache for external data",
      "controllers": 19,
      "services": 25,
      "models": 23
    },
    "supportedIntegrations": {
      "exchanges": [
        {
          "name": "Binance",
          "type": "Spot",
          "status": "available"
        },
        {
          "name": "Coinbase",
          "type": "Spot",
          "status": "available"
        },
        {
          "name": "Kraken",
          "type": "Spot",
          "status": "in_development"
        }
      ],
      "marketData": [
        "CoinMarketCap (+10,000 cryptos)",
        "Polygon (macro data)",
        "FRED (economic indicators)"
      ],
      "aiIntelligence": [
        "OpenAI GPT-4.1 (Sofia AI)"
      ],
      "signals": [
        "TradingView Webhooks"
      ]
    },
    "keyFeatures": [
      "Multi-wallet portfolio tracking",
      "Consolidated performance view",
      "Visual asset allocation",
      "Macro analysis & market intelligence",
      "In-depth crypto asset analysis",
      "TradingView alerts integration",
      "Multi-client trading via Binance/Coinbase",
      "White-label deployment",
      "Read-only client access",
      "AI-powered analytics (Sofia)",
      "Fund management & NAV calculation",
      "Backtesting strategies"
    ],
    "limitations": [
      "API withdrawals not allowed (read-only or controlled trading only)",
      "B2B only - no retail/consumer offering",
      "Self-hosted deployment required (no SaaS public sharing)",
      "Swagger documentation only available in development mode"
    ],
    "swaggerDocumentation": {
      "description": "Complete documentation available on deployed server",
      "urlPattern": "{deployment_url}/api-docs",
      "availability": "Development mode only",
      "endpointsCount": 102
    }
  }
}