You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

关于Pine Script中通过用户名/密码认证Coinalyze API以获取持仓量数据的可行性咨询

Great question! Let's break this down clearly for you:

Pine Script Support for Username/Password API Authentication

First, the core answer: Pine Script does not natively support username/password-based HTTP basic auth or form authentication. Here's why:

  • Pine Script's request.* function family (the only way to call external APIs) only supports two authentication methods:
    • Passing API keys/tokens via request headers (e.g., Authorization: Bearer <token> or X-API-Key: <key>)
    • Appending keys as URL parameters (not recommended due to security risks)
  • Pine Script restricts HTTP requests to GET methods only—you can't send POST/PUT requests to submit username/password data for authentication, which blocks standard username/password auth flows.
Workaround for Coinalyze API

Since Coinalyze requires authentication, here's a practical solution:

  1. Use an external tool (like Postman, a Python script, or even cURL) to send your username/password to Coinalyze's authentication endpoint. This will return an API token or key.
  2. Use this token in your Pine Script via request headers to authenticate and fetch open interest data.

Here's a simplified Pine Script example (assuming Coinalyze uses Bearer token auth):

//@version=5
indicator("Coinalyze Open Interest Tracker", overlay=false)

// Store token securely with secret input
apiToken = input.string("", title="Coinalyze API Token", type=input.secret)
targetPair = input.string("BTCUSDT", title="Trading Pair")

// Build auth header
authHeader = "Authorization=Bearer " + apiToken

// Fetch open interest data
response = request.get(
    url="https://api.coinalyze.net/v1/open-interest?symbol=" + targetPair,
    headers=authHeader
)

// Process and plot data (example)
if response != na
    parsedData = json.parse(response)
    currentOI = parsedData["open_interest"]
    plot(currentOI, title="Current Open Interest", color=color.new(color.blue, 0))
Quick Additional Tips
  • Always keep your API token secure: use input.secret so it's not visible in shared code or public indicators.
  • If you can't find Coinalyze's specific API docs, check their official platform's developer section—they should outline authentication endpoints and data schemas clearly.

内容的提问来源于stack exchange,提问作者Niddify

火山引擎 最新活动