ruby言語でapiを使って特定のjsonの値を取得する
このコードを実行するとエラーになってしまします。助けてください
require "net/http"
require "uri"
require "openssl"
require "json"
key = ほげほげ
secret =ほげほげ
timestamp = Time.now.to_i.to_s
method = "GET"
uri = URI.parse("https://api.bitflyer.jp")
uri.path = "/v1/me/getpositions"
uri.query = "product_code=FX_BTC_JPY"
text = timestamp + method + uri.request_uri
sign = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), secret, text)
options = Net::HTTP::Get.new(uri.request_uri, initheader = {
"ACCESS-KEY" => key,
"ACCESS-TIMESTAMP" => timestamp,
"ACCESS-SIGN" => sign,
});
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
response = https.request(options)
json = response.body
getpositions = JSON.parse(json)
puts getpositions["size"]
エラーコード↓
test04.rb:32:in []': no implicit conversion of String into Integer (TypeError)
from test04.rb:32:in <main>'
ちなみにjsonをする前のコードのレスポンスがこれです。これのsize
を取り出したいです。
[{"product_code":"FX_BTC_JPY","side":"BUY","price":321400.000000000000,"size":0.001000000000,"commission":0.000000000000,"swap_point_accumulate":0.294105200000000000000000,"require_collateral":21.426666666666666666666666667,"open_date":"2017-08-04T15:22:29.113","leverage":15.000000000000,"pnl":59.565894800000000000000000}]