【发布时间】:2021-10-26 08:05:02
【问题描述】:
这有什么问题?为什么我不能发布购买?我不断收到 401 Unauthorized。 API 有正确的权限(wallet:buys:create)
我应该指出,我的 GET 有效,我可以从帐户中读取所有信息。
$time = 'https://api.coinbase.com/v2/time'
$epochtime = [string]((Invoke-WebRequest $time | ConvertFrom-Json).data).epoch
$method = 'POST'
$requestpath = '/v2/accounts/xxxxxxxx-3ecb-xxxxxxxx-xxxxxxxx/buys'
$endpoint = "https://api.coinbase.com/$($requestpath)"
$secret_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
$sign = $epochtime + $method + $requestpath
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Text.Encoding]::UTF8.GetBytes($secret_key)
$computeSha = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($sign))
$signature = ([System.BitConverter]::ToString($computeSha) -replace "-").ToLower()
$header = @{
"CB-ACCESS-SIGN"=$signature
"CB-ACCESS-TIMESTAMP"=$epochtime
"CB-ACCESS-KEY"='xxxxxxxxxxxxxxxxxxxx'
}
$body = '{"amount": "10", "currency": "XLM", "payment_method": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "commit": "true", "quote":"false"}'
function Get-CoinBase($method, $endpoint, $header, $body)
{
$result = Invoke-WebRequest $endpoint -Headers $header -Method $method -body $body -ContentType "application/json" -UseBasicParsing
write-host $APImethod -f yellow
return $result
}
$AccountBAL = Get-CoinBase -method "POST" -endpoint $endpoint -header $header -body $body
【问题讨论】:
-
为什么不使用exchange api而不是coinbase api?
-
您的消息中的错误是什么?无效的签名/密钥/时间戳?
-
我也将只使用 CoinBasePro API,但我真的只想为非专业 Coinbase API 解决这个问题。返回的错误是“无效签名”,但据我所知,我正确地形成了签名?我所有的GETS都可以使用相同的$requestpath变量正常工作,该变量构成sig的一部分。
-
看看这篇文章。似乎 cb 和 cbpro 的签名可能略有不同stackoverflow.com/questions/69714766/…
-
你可能会在这里做点什么!时间服务器比我的电脑晚 1 小时。我在爱尔兰,夏令时将在周日开始(我们回滚 1 小时)。如果这是问题所在,而且周一才开始工作,我会被难住的!