I'd like to extract information about a value from the bitFlyer API.
I want to take out the child_order_state
value in getchildorders
of the API and display yes
for COMPLETED
, but I get an error.Thank you for your cooperation.
Error Code
25:in`':uninitialized constant JSON (NameError)
Sample Code
require "net/http"
require "uri"
require "opensl"
key = "Hage"
secret="Blowing"
timestamp=Time.now.to_i.to_s
method="GET"
uri=URI.parse("https://api.bitflyer.jp")
uri.path="/v1/me/getchilders"
uri.query="product_code=FX_BTC_JPY&count=after&after=blowing"
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)
puts response.body
json=Net::HTTP.get(uri)
getchildorders=JSON.parse(json)
puts getchildorders ["child_order_state" ]
getchildorders ["child_order_state"] = COMPLETED
puts yes
The JSON class cannot be used without loading the json library.
At the beginning of the program, you can write the following:
require "json"
© 2024 OneMinuteCode. All rights reserved.