-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethod.rb
More file actions
67 lines (56 loc) · 1.61 KB
/
Copy pathmethod.rb
File metadata and controls
67 lines (56 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 板情報の取得
# ライブラリの指定
require 'net/http'
require 'uri'
require 'json'
# key.rbの内容が使えるようになる.今はサンプルなのでコメントアウト
# require './key'
def reqest_board_info
# endpoint
uri = URI.parse("https://api.bitflyer.jp")
# api request_uri
uri.path = '/v1/getboard'
# クエリの選択
uri.query = ''
# htpps通信の設定
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
response = https.get uri.request_uri
# 吐き出し
# puts response.body
# JSONに変換してカラムを指定
response_hash = JSON.parse(response.body)
response_hash["mid_price"]
end
def order(order , price, size)
# key.rbで定義したAPI_KEYとAPI_SECLETを代入
key = API_KEY
secret = API_SECRET
timestamp = Time.now.to_i.to_s
method = "POST"
uri = URI.parse("https://api.bitflyer.jp")
uri.path = "/v1/me/sendchildorder"
# product_code
body = '{
"product_code": "BTC_JPY",
"child_order_type": "LIMIT",
"side": "'+ order +'",
"price":' + price +',
"size":' + size +',
"minute_to_expire": 10000,
"time_in_force": "GTC"
}'
text = timestamp + method + uri.request_uri + body
sign = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), secret, text)
options = Net::HTTP::Post.new(uri.request_uri, initheader = {
"ACCESS-KEY" => key,
"ACCESS-TIMESTAMP" => timestamp,
"ACCESS-SIGN" => sign,
"Content-Type" => "application/json"
});
options.body = body
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
response = https.request(options)
puts response.body
end