fcoin 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/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +2 -0
- data/fcoin.gemspec +24 -0
- data/lib/fcoin.rb +8 -0
- data/lib/fcoin/client.rb +92 -0
- data/lib/fcoin/request.rb +62 -0
- data/lib/fcoin/version.rb +3 -0
- metadata +96 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 2e5c778277229bcc9bf89fb418b7f802bd975f0d
|
|
4
|
+
data.tar.gz: 42af046f1867aaec45b59bdb553b8298d465f08d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a6d525fda68b1925baac165c0930385e809b283e091ae0a769aeb331ff62423c9812045fd30d74cf100ec6b8b446ade28e7ddbd43f2b5703980588b8265e31af
|
|
7
|
+
data.tar.gz: 94637145385c677bcc8fa059e5bc4ee80f54dfa139624b8bb35bebf6adfdc0af8d5f4f5dc4d34c46399042fb9b76e9b57082efad5e988eb645e2a10224ea5d3b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2018 EricZhu
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Fcoin
|
|
2
|
+
|
|
3
|
+
Ruby wrapper for huobi api
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'fcoin'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install fcoin
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
FCoin Api Document: https://developer.fcoin.com/zh.html
|
|
23
|
+
```ruby
|
|
24
|
+
client = Fcoin::Client.new("8fd4dxxxxxxxxxx9e13d7bdffc0d", "0a14a91e7axxxxxxxxxxaa1d5b8befa")
|
|
25
|
+
# p client.get_balance
|
|
26
|
+
# p client.get_depth("L20", 'btcusdt')
|
|
27
|
+
# p client.get_last('btcusdt')
|
|
28
|
+
# p client.get_ticker('btcusdt')
|
|
29
|
+
# p client.get_candle("M1", "btcusdt")
|
|
30
|
+
# p client.get_last("fteth")
|
|
31
|
+
# p client.create_order('ftusdt', 'buy', 'limit', 10, 0.891)
|
|
32
|
+
# p client.get_orders("ftusdt")
|
|
33
|
+
# p client.cancel_order("3i06mrxxxxxxxxxxqF5wgKUOYK3ceru-w4RhMqU=")
|
|
34
|
+
# p client.get_order_detail("3i06xxxxxxxxxxt_0xqF5wgKUOYK3ceru-w4RhMqU=")
|
|
35
|
+
# p client.get_order_results("TqUfakhxxxxxxxxxxyZq9OQOMXO_zCFsT7G74_Lk1DJ2A=")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Contributing
|
|
39
|
+
|
|
40
|
+
1. Fork it ( https://github.com/[my-github-username]/fcoin/fork )
|
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
44
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/fcoin.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'fcoin/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "fcoin"
|
|
8
|
+
spec.version = Fcoin::VERSION
|
|
9
|
+
spec.authors = ["EricZhu"]
|
|
10
|
+
spec.email = ["zhuyuchao.personal@gmail.com"]
|
|
11
|
+
spec.summary = %q{Ruby wrapper for huobi api}
|
|
12
|
+
spec.description = %q{Ruby wrapper for huobi api}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_dependency "faraday", "~> 0.15"
|
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
24
|
+
end
|
data/lib/fcoin.rb
ADDED
data/lib/fcoin/client.rb
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
module Fcoin
|
|
2
|
+
class Client
|
|
3
|
+
include Fcoin::Request
|
|
4
|
+
def initialize(key, sign)
|
|
5
|
+
configuration(key, sign)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
#传入参数: symbol为交易对, 例如 usdtbtc
|
|
9
|
+
#返回参数中数组依次对应:
|
|
10
|
+
# "最新成交价",
|
|
11
|
+
# "最近一笔成交的成交量",
|
|
12
|
+
# "最大买一价",
|
|
13
|
+
# "最大买一量",
|
|
14
|
+
# "最小卖一价",
|
|
15
|
+
# "最小卖一量",
|
|
16
|
+
# "24小时前成交价",
|
|
17
|
+
# "24小时内最高价",
|
|
18
|
+
# "24小时内最低价",
|
|
19
|
+
# "24小时内基准货币成交量, 如 btcusdt 中 btc 的量",
|
|
20
|
+
# "24小时内计价货币成交量, 如 btcusdt 中 usdt 的量"
|
|
21
|
+
def get_ticker(symbol)
|
|
22
|
+
get("market/ticker/#{symbol}")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
#传入参数:
|
|
26
|
+
# level L20 20档行情深度.
|
|
27
|
+
# L100 100 档行情深度.
|
|
28
|
+
# full 全量的行情深度, 不做时间保证和推送保证.
|
|
29
|
+
def get_depth(level, symbol)
|
|
30
|
+
get("market/depth/#{level}/#{symbol}")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
#返回历史成交
|
|
34
|
+
def get_last(symbol)
|
|
35
|
+
get "market/trades/#{symbol}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# resolution:
|
|
39
|
+
# M1: 1 分钟, M3: 3 分钟, M5: 5 分钟, M15: 15 分钟 M30 30 分钟 H1 1 小时 H4 4 小时 H6 6 小时 D1 1 日 W1 1 周 MN 1 月
|
|
40
|
+
def get_candle(resolution, symbol)
|
|
41
|
+
get "market/candles/#{resolution}/#{symbol}"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def get_balance
|
|
45
|
+
get('accounts/balance')
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
#获取订单
|
|
49
|
+
# states:
|
|
50
|
+
# submitted 已提交
|
|
51
|
+
# partial_filled 部分成交
|
|
52
|
+
# partial_canceled 部分成交已撤销
|
|
53
|
+
# filled 完全成交
|
|
54
|
+
# canceled 已撤销
|
|
55
|
+
# pending_cancel 撤销已提交
|
|
56
|
+
def get_orders(symbol, states='submitted,filled', limit=100, before=nil, after=nil)
|
|
57
|
+
get('orders', {
|
|
58
|
+
symbol: symbol, states: states, limit: limit, before: before, after: after
|
|
59
|
+
})
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# symbol 交易对
|
|
63
|
+
# side 交易方向 (buy, sell)
|
|
64
|
+
# type 订单类型 (limit,market)
|
|
65
|
+
# amount 下单量
|
|
66
|
+
# price 价格
|
|
67
|
+
def create_order(symbol, side, type, amount, price=nil)
|
|
68
|
+
if type == "limit"
|
|
69
|
+
post("orders", {
|
|
70
|
+
symbol: symbol, side: side, type: type, price: price, amount: amount
|
|
71
|
+
})
|
|
72
|
+
elsif type == "market"
|
|
73
|
+
post("orders", {
|
|
74
|
+
symbol: symbol, side: side, type: type, amount: amount, price: 0
|
|
75
|
+
})
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def cancel_order(order_id)
|
|
80
|
+
post("orders/#{order_id}/submit-cancel")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def get_order_detail(order_id)
|
|
84
|
+
get("orders/#{order_id}")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
#查询指定订单的成交记录
|
|
88
|
+
def get_order_results(order_id)
|
|
89
|
+
get("orders/#{order_id}/match-results")
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'base64'
|
|
2
|
+
require 'openssl'
|
|
3
|
+
require 'faraday'
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
module Fcoin
|
|
7
|
+
module Request
|
|
8
|
+
BaseURL = "https://api.fcoin.com/v2/"
|
|
9
|
+
|
|
10
|
+
def configuration(key, secret)
|
|
11
|
+
@key = key
|
|
12
|
+
@secret = secret
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def get(path, options={})
|
|
16
|
+
request(:get, path, options)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def post(path, options={})
|
|
20
|
+
request(:post, path, options)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def request(method, path, options)
|
|
26
|
+
ts = (Time.now.to_f*1000).to_i
|
|
27
|
+
response = connection.send(method) do |request|
|
|
28
|
+
request.headers['FC-ACCESS-SIGNATURE'] = sign(method, path, ts, options)
|
|
29
|
+
request.headers['FC-ACCESS-TIMESTAMP'] = ts.to_s
|
|
30
|
+
request.headers['Content-Type'] = 'application/json;charset=UTF-8'
|
|
31
|
+
case method
|
|
32
|
+
when :get
|
|
33
|
+
request.url(path, options)
|
|
34
|
+
when :post
|
|
35
|
+
request.path = path
|
|
36
|
+
request.body = options.to_json
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
JSON.load response.body
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def connection
|
|
43
|
+
Faraday.new(
|
|
44
|
+
headers: { 'FC-ACCESS-KEY' => @key },
|
|
45
|
+
url: BaseURL,
|
|
46
|
+
request: { open_timeout: 10, timeout: 5 }
|
|
47
|
+
) do |connection|
|
|
48
|
+
connection.adapter(Faraday.default_adapter)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def sign(method, path, ts, options)
|
|
53
|
+
merge_options = options.sort.map{|arr| "#{arr[0]}=#{arr[1]}"}.join('&')
|
|
54
|
+
if method == :get && merge_options != ""
|
|
55
|
+
str = "#{method.upcase}#{BaseURL}#{path}?#{merge_options}#{ts}"
|
|
56
|
+
else
|
|
57
|
+
str = "#{method.upcase}#{BaseURL}#{path}#{ts}#{merge_options}"
|
|
58
|
+
end
|
|
59
|
+
Base64.strict_encode64(OpenSSL::HMAC.digest('sha1', @secret, Base64.strict_encode64(str)))
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: fcoin
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- EricZhu
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-06-14 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: faraday
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.15'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.15'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.7'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.7'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
description: Ruby wrapper for huobi api
|
|
56
|
+
email:
|
|
57
|
+
- zhuyuchao.personal@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".gitignore"
|
|
63
|
+
- Gemfile
|
|
64
|
+
- LICENSE.txt
|
|
65
|
+
- README.md
|
|
66
|
+
- Rakefile
|
|
67
|
+
- fcoin.gemspec
|
|
68
|
+
- lib/fcoin.rb
|
|
69
|
+
- lib/fcoin/client.rb
|
|
70
|
+
- lib/fcoin/request.rb
|
|
71
|
+
- lib/fcoin/version.rb
|
|
72
|
+
homepage: ''
|
|
73
|
+
licenses:
|
|
74
|
+
- MIT
|
|
75
|
+
metadata: {}
|
|
76
|
+
post_install_message:
|
|
77
|
+
rdoc_options: []
|
|
78
|
+
require_paths:
|
|
79
|
+
- lib
|
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '0'
|
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
requirements: []
|
|
91
|
+
rubyforge_project:
|
|
92
|
+
rubygems_version: 2.4.3
|
|
93
|
+
signing_key:
|
|
94
|
+
specification_version: 4
|
|
95
|
+
summary: Ruby wrapper for huobi api
|
|
96
|
+
test_files: []
|