fuly 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/bitfinex/api/funding.rb +62 -0
- data/lib/bitfinex/api/wallet.rb +43 -0
- data/lib/bitfinex/client.rb +61 -0
- data/lib/fuly.rb +2 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 91bb5e281ca867635af8d51e6d67cd4bfede4a386d3ea416cdcf83b46018fa69
|
|
4
|
+
data.tar.gz: ae9c5367f16660a4d6fc0e1f52d3ae1742cde664c303aad07e076f1d2883ee54
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 83d8b304cdcd7b063d30a9c50e60dd9d5bba5592cf5ef0530153658099aa82488f66f27b409c58dc3d44f13befcdc9e8a5ad9a53536573934e7c46699a8dada8
|
|
7
|
+
data.tar.gz: 143dbce08a02431291b741b1c6a7d8368b5d740721d1e675be04cd75d89163518b58e51e6db10a9db447883d7b03d63cf46c31055a7e6df776c3fa673b2b018e
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Bitfinex
|
|
2
|
+
module Funding
|
|
3
|
+
# 列出放貸總績效
|
|
4
|
+
# Ratelimit: 45 req/min
|
|
5
|
+
# https://docs.bitfinex.com/reference#rest-auth-info-funding
|
|
6
|
+
def funding_info(currency = "fUSD")
|
|
7
|
+
res = request("auth/r/info/funding/#{currency}").body
|
|
8
|
+
return JSON.parse(res)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# 列出所有正在掛單
|
|
12
|
+
# Ratelimit: 45 req/min
|
|
13
|
+
def funding_offers_all
|
|
14
|
+
res = request("auth/r/funding/offers").body
|
|
15
|
+
return JSON.parse(res)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# 列出currency掛單
|
|
19
|
+
# Ratelimit: 45 req/min
|
|
20
|
+
# https://docs.bitfinex.com/reference#rest-auth-funding-offers
|
|
21
|
+
def funding_offers(currency = "fUSD")
|
|
22
|
+
res = request("auth/r/funding/offers/#{currency}").body
|
|
23
|
+
return JSON.parse(res)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# 取消指定掛單
|
|
27
|
+
def funding_cancel_offer(id)
|
|
28
|
+
res = request("auth/w/funding/offer/cancel", {
|
|
29
|
+
id: id,
|
|
30
|
+
}).body
|
|
31
|
+
return JSON.parse(res)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# 掛單
|
|
35
|
+
# https://docs.bitfinex.com/reference#submit-funding-offer
|
|
36
|
+
def funding_create_offer(currency, amount, rate, period)
|
|
37
|
+
# auth/w/funding/offer/submit
|
|
38
|
+
request("auth/w/funding/offer/submit", {
|
|
39
|
+
type: "LIMIT",
|
|
40
|
+
symbol: currency, #fUSD
|
|
41
|
+
amount: amount, #借款要是負的
|
|
42
|
+
rate: rate,
|
|
43
|
+
period: period,
|
|
44
|
+
flags: 0,
|
|
45
|
+
}).body
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def funding_new_offer(params)
|
|
49
|
+
res = v1_request("offer/new", params)
|
|
50
|
+
res = JSON.parse(res)
|
|
51
|
+
return res
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# 所有正在借款列表
|
|
55
|
+
# Ratelimit: 45 req/min
|
|
56
|
+
# https://docs.bitfinex.com/reference#rest-auth-funding-credits
|
|
57
|
+
def funding_credit
|
|
58
|
+
res = request("auth/r/funding/credits").body
|
|
59
|
+
return JSON.parse(res)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Bitfinex
|
|
2
|
+
module Wallet
|
|
3
|
+
# Ratelimit: 45 req/min
|
|
4
|
+
# response:
|
|
5
|
+
# https://docs.bitfinex.com/reference#rest-auth-wallets
|
|
6
|
+
def wallets
|
|
7
|
+
res = request("auth/r/wallets").body
|
|
8
|
+
return JSON.parse(res)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Ratelimit: 45 req/min
|
|
12
|
+
def wallets_history
|
|
13
|
+
request("auth/r/wallets/hist", {
|
|
14
|
+
end: (Time.now.to_f * 1000).floor,
|
|
15
|
+
}).body
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Ratelimit: 30 req/min
|
|
19
|
+
def available_currency(currency)
|
|
20
|
+
res = request("auth/calc/order/avail", {
|
|
21
|
+
symbol: currency,
|
|
22
|
+
type: "MARGIN",
|
|
23
|
+
}).body
|
|
24
|
+
res = JSON.parse(res)
|
|
25
|
+
return res[0].abs
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# 收入列表
|
|
29
|
+
# Ratelimit: 15 req/min
|
|
30
|
+
# https://docs.bitfinex.com/v1/reference#rest-auth-balance-history
|
|
31
|
+
def interest_history(currency, start_time, end_time)
|
|
32
|
+
res = v1_request("history", {
|
|
33
|
+
currency: currency,
|
|
34
|
+
# wallet: "deposit",
|
|
35
|
+
# since: "1570272762.0",
|
|
36
|
+
# until: "1572951124.0",
|
|
37
|
+
# limit: 500,
|
|
38
|
+
})
|
|
39
|
+
res = JSON.parse(res)
|
|
40
|
+
return res
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require_relative "./api/wallet"
|
|
2
|
+
require_relative "./api/funding"
|
|
3
|
+
|
|
4
|
+
module Bitfinex
|
|
5
|
+
class Client
|
|
6
|
+
include Bitfinex::Wallet
|
|
7
|
+
include Bitfinex::Funding
|
|
8
|
+
|
|
9
|
+
def initialize(args = {})
|
|
10
|
+
@api_endpoint = args[:url] ? "#{args[:url]}/v2/" : "https://api.bitfinex.com/v2/"
|
|
11
|
+
@api_key = args[:api_key]
|
|
12
|
+
@api_secret = args[:api_secret]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def request(url, options = {})
|
|
18
|
+
body = options || {}
|
|
19
|
+
nonce = (Time.now.to_f * 1000).floor.to_s
|
|
20
|
+
payload = "/api/v2/#{url}#{nonce}#{body.to_json}"
|
|
21
|
+
sign = OpenSSL::HMAC.hexdigest("sha384", @api_secret, payload)
|
|
22
|
+
|
|
23
|
+
headers = {
|
|
24
|
+
'Content-Type': "application/json",
|
|
25
|
+
'Accept': "application/json",
|
|
26
|
+
'bfx-nonce': nonce,
|
|
27
|
+
'bfx-signature': sign,
|
|
28
|
+
'bfx-apikey': @api_key,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
response = HTTParty.post(
|
|
32
|
+
"#{@api_endpoint}#{url}",
|
|
33
|
+
:body => body.to_json,
|
|
34
|
+
:headers => headers,
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def build_payload(url, params = {}, nonce)
|
|
39
|
+
payload = {}
|
|
40
|
+
payload["nonce"] = nonce
|
|
41
|
+
payload["request"] = url
|
|
42
|
+
payload.merge!(params) if params
|
|
43
|
+
Base64.strict_encode64(payload.to_json)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def v1_request(url, options = {})
|
|
47
|
+
nonce = (Time.now.to_f * 1000).floor.to_s
|
|
48
|
+
url = "/v1/#{url}"
|
|
49
|
+
payload = build_payload(url, options, nonce)
|
|
50
|
+
headers = {
|
|
51
|
+
"X-BFX-APIKEY" => @api_key,
|
|
52
|
+
"X-BFX-PAYLOAD" => payload,
|
|
53
|
+
"X-BFX-SIGNATURE" => OpenSSL::HMAC.hexdigest("sha384", @api_secret, payload),
|
|
54
|
+
}
|
|
55
|
+
response = HTTParty.post(
|
|
56
|
+
"https://api.bitfinex.com#{url}",
|
|
57
|
+
:headers => headers,
|
|
58
|
+
).body
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
data/lib/fuly.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: fuly
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Rex Chen
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-11-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: httparty
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.17.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.17.0
|
|
27
|
+
description: Official Fuly API ruby wrapper
|
|
28
|
+
email:
|
|
29
|
+
- rex@huijun.org
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- lib/bitfinex/api/funding.rb
|
|
35
|
+
- lib/bitfinex/api/wallet.rb
|
|
36
|
+
- lib/bitfinex/client.rb
|
|
37
|
+
- lib/fuly.rb
|
|
38
|
+
homepage: https://fuly.best/
|
|
39
|
+
licenses:
|
|
40
|
+
- MIT
|
|
41
|
+
metadata: {}
|
|
42
|
+
post_install_message:
|
|
43
|
+
rdoc_options: []
|
|
44
|
+
require_paths:
|
|
45
|
+
- lib
|
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: '0'
|
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '0'
|
|
56
|
+
requirements: []
|
|
57
|
+
rubyforge_project:
|
|
58
|
+
rubygems_version: 2.7.7
|
|
59
|
+
signing_key:
|
|
60
|
+
specification_version: 4
|
|
61
|
+
summary: Fuly API Wrapper
|
|
62
|
+
test_files: []
|