fcoin_ruby_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/issue_template.md +12 -0
- data/.github/pull_request_template.md +12 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +12 -0
- data/.rubocop_todo.yml +431 -0
- data/.travis.yml +26 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +176 -0
- data/LICENSE.txt +21 -0
- data/README.md +204 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/fcoin +95 -0
- data/bin/setup +8 -0
- data/examples/cli/realtime_api.md +78 -0
- data/examples/cli/rest_api.md +149 -0
- data/examples/cli/setting.md +39 -0
- data/examples/realtime_api.rb +43 -0
- data/examples/rest_api.rb +47 -0
- data/fcoin_ruby_client.gemspec +39 -0
- data/lib/fcoin/api.rb +47 -0
- data/lib/fcoin/authorization.rb +83 -0
- data/lib/fcoin/cli/endpoint/accounts_task.rb +33 -0
- data/lib/fcoin/cli/endpoint/market_task.rb +98 -0
- data/lib/fcoin/cli/endpoint/orders_task.rb +196 -0
- data/lib/fcoin/cli/endpoint/public_task.rb +59 -0
- data/lib/fcoin/cli/realtime/endpoint_task.rb +107 -0
- data/lib/fcoin/cli.rb +77 -0
- data/lib/fcoin/client.rb +7 -0
- data/lib/fcoin/config/custom_settings.yml +171 -0
- data/lib/fcoin/config/settings.yml +10 -0
- data/lib/fcoin/configuration.rb +95 -0
- data/lib/fcoin/connection.rb +33 -0
- data/lib/fcoin/endpoint/accounts.rb +23 -0
- data/lib/fcoin/endpoint/market.rb +91 -0
- data/lib/fcoin/endpoint/orders.rb +171 -0
- data/lib/fcoin/endpoint/public.rb +51 -0
- data/lib/fcoin/endpoint/utility.rb +14 -0
- data/lib/fcoin/endpoint.rb +13 -0
- data/lib/fcoin/error.rb +4 -0
- data/lib/fcoin/faraday/fcoin_formatter.rb +17 -0
- data/lib/fcoin/formatter/base_formatter.rb +8 -0
- data/lib/fcoin/formatter/depth_formatter.rb +33 -0
- data/lib/fcoin/formatter/ticker_formatter.rb +34 -0
- data/lib/fcoin/formatter.rb +38 -0
- data/lib/fcoin/generators/locale.rb +18 -0
- data/lib/fcoin/generators/templates/locale/locales/en.yml +176 -0
- data/lib/fcoin/generators/templates/locale/locales/ja.yml +176 -0
- data/lib/fcoin/generators/templates/locale/locales/zh_CN.yml +176 -0
- data/lib/fcoin/generators/templates/validation/my_settings.yml +171 -0
- data/lib/fcoin/generators/validation.rb +18 -0
- data/lib/fcoin/realtime/api.rb +38 -0
- data/lib/fcoin/realtime/client.rb +9 -0
- data/lib/fcoin/realtime/endpoint.rb +160 -0
- data/lib/fcoin/realtime/formatter/base_formatter.rb +10 -0
- data/lib/fcoin/realtime/formatter/depth_formatter.rb +37 -0
- data/lib/fcoin/realtime/formatter/ticker_formatter.rb +36 -0
- data/lib/fcoin/realtime/formatter.rb +40 -0
- data/lib/fcoin/realtime/wss.rb +113 -0
- data/lib/fcoin/request.rb +73 -0
- data/lib/fcoin/validator/market_validator.rb +60 -0
- data/lib/fcoin/validator/orders/base_validator.rb +96 -0
- data/lib/fcoin/validator/orders/create_order_limit_validator.rb +54 -0
- data/lib/fcoin/validator/orders/create_order_market_validator.rb +95 -0
- data/lib/fcoin/validator/orders/order_list_validator.rb +33 -0
- data/lib/fcoin/validator/orders_validator.rb +69 -0
- data/lib/fcoin/validator/validator_utility.rb +24 -0
- data/lib/fcoin/validator.rb +58 -0
- data/lib/fcoin/version.rb +3 -0
- data/lib/fcoin.rb +11 -0
- metadata +353 -0
data/Gemfile.lock
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fcoin_ruby_client (0.1.0)
|
5
|
+
activesupport
|
6
|
+
config
|
7
|
+
faraday
|
8
|
+
faraday_middleware
|
9
|
+
faye-websocket
|
10
|
+
thor
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
activesupport (5.2.0)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 0.7, < 2)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
tzinfo (~> 1.1)
|
20
|
+
addressable (2.5.2)
|
21
|
+
public_suffix (>= 2.0.2, < 4.0)
|
22
|
+
ast (2.4.0)
|
23
|
+
coderay (1.1.2)
|
24
|
+
concurrent-ruby (1.0.5)
|
25
|
+
config (1.7.0)
|
26
|
+
activesupport (>= 3.0)
|
27
|
+
deep_merge (~> 1.2.1)
|
28
|
+
dry-validation (>= 0.10.4)
|
29
|
+
coveralls (0.7.1)
|
30
|
+
multi_json (~> 1.3)
|
31
|
+
rest-client
|
32
|
+
simplecov (>= 0.7)
|
33
|
+
term-ansicolor
|
34
|
+
thor
|
35
|
+
crack (0.4.3)
|
36
|
+
safe_yaml (~> 1.0.0)
|
37
|
+
deep_merge (1.2.1)
|
38
|
+
diff-lcs (1.3)
|
39
|
+
docile (1.3.1)
|
40
|
+
domain_name (0.5.20180417)
|
41
|
+
unf (>= 0.0.5, < 1.0.0)
|
42
|
+
dry-configurable (0.7.0)
|
43
|
+
concurrent-ruby (~> 1.0)
|
44
|
+
dry-container (0.6.0)
|
45
|
+
concurrent-ruby (~> 1.0)
|
46
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
47
|
+
dry-core (0.4.7)
|
48
|
+
concurrent-ruby (~> 1.0)
|
49
|
+
dry-equalizer (0.2.1)
|
50
|
+
dry-inflector (0.1.2)
|
51
|
+
dry-logic (0.4.2)
|
52
|
+
dry-container (~> 0.2, >= 0.2.6)
|
53
|
+
dry-core (~> 0.2)
|
54
|
+
dry-equalizer (~> 0.2)
|
55
|
+
dry-types (0.13.2)
|
56
|
+
concurrent-ruby (~> 1.0)
|
57
|
+
dry-container (~> 0.3)
|
58
|
+
dry-core (~> 0.4, >= 0.4.4)
|
59
|
+
dry-equalizer (~> 0.2)
|
60
|
+
dry-inflector (~> 0.1, >= 0.1.2)
|
61
|
+
dry-logic (~> 0.4, >= 0.4.2)
|
62
|
+
dry-validation (0.12.1)
|
63
|
+
concurrent-ruby (~> 1.0)
|
64
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
65
|
+
dry-core (~> 0.2, >= 0.2.1)
|
66
|
+
dry-equalizer (~> 0.2)
|
67
|
+
dry-logic (~> 0.4, >= 0.4.0)
|
68
|
+
dry-types (~> 0.13.1)
|
69
|
+
eventmachine (1.2.7)
|
70
|
+
faraday (0.15.2)
|
71
|
+
multipart-post (>= 1.2, < 3)
|
72
|
+
faraday_middleware (0.12.2)
|
73
|
+
faraday (>= 0.7.4, < 1.0)
|
74
|
+
faye-websocket (0.10.7)
|
75
|
+
eventmachine (>= 0.12.0)
|
76
|
+
websocket-driver (>= 0.5.1)
|
77
|
+
hashdiff (0.3.7)
|
78
|
+
http-cookie (1.0.3)
|
79
|
+
domain_name (~> 0.5)
|
80
|
+
i18n (1.0.1)
|
81
|
+
concurrent-ruby (~> 1.0)
|
82
|
+
json (2.1.0)
|
83
|
+
method_source (0.9.0)
|
84
|
+
mime-types (3.1)
|
85
|
+
mime-types-data (~> 3.2015)
|
86
|
+
mime-types-data (3.2016.0521)
|
87
|
+
minitest (5.11.3)
|
88
|
+
multi_json (1.13.1)
|
89
|
+
multipart-post (2.0.0)
|
90
|
+
netrc (0.11.0)
|
91
|
+
onkcop (0.53.0.0)
|
92
|
+
rubocop (~> 0.53.0)
|
93
|
+
rubocop-rspec (>= 1.24.0)
|
94
|
+
parallel (1.12.1)
|
95
|
+
parser (2.5.1.2)
|
96
|
+
ast (~> 2.4.0)
|
97
|
+
powerpack (0.1.2)
|
98
|
+
pry (0.11.3)
|
99
|
+
coderay (~> 1.1.0)
|
100
|
+
method_source (~> 0.9.0)
|
101
|
+
public_suffix (3.0.2)
|
102
|
+
rainbow (3.0.0)
|
103
|
+
rake (10.5.0)
|
104
|
+
rest-client (2.0.2)
|
105
|
+
http-cookie (>= 1.0.2, < 2.0)
|
106
|
+
mime-types (>= 1.16, < 4.0)
|
107
|
+
netrc (~> 0.8)
|
108
|
+
rspec (3.7.0)
|
109
|
+
rspec-core (~> 3.7.0)
|
110
|
+
rspec-expectations (~> 3.7.0)
|
111
|
+
rspec-mocks (~> 3.7.0)
|
112
|
+
rspec-core (3.7.1)
|
113
|
+
rspec-support (~> 3.7.0)
|
114
|
+
rspec-expectations (3.7.0)
|
115
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
116
|
+
rspec-support (~> 3.7.0)
|
117
|
+
rspec-mocks (3.7.0)
|
118
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
119
|
+
rspec-support (~> 3.7.0)
|
120
|
+
rspec-support (3.7.1)
|
121
|
+
rubocop (0.53.0)
|
122
|
+
parallel (~> 1.10)
|
123
|
+
parser (>= 2.5)
|
124
|
+
powerpack (~> 0.1)
|
125
|
+
rainbow (>= 2.2.2, < 4.0)
|
126
|
+
ruby-progressbar (~> 1.7)
|
127
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
128
|
+
rubocop-rspec (1.26.0)
|
129
|
+
rubocop (>= 0.53.0)
|
130
|
+
ruby-progressbar (1.9.0)
|
131
|
+
safe_yaml (1.0.4)
|
132
|
+
simplecov (0.16.1)
|
133
|
+
docile (~> 1.1)
|
134
|
+
json (>= 1.8, < 3)
|
135
|
+
simplecov-html (~> 0.10.0)
|
136
|
+
simplecov-html (0.10.2)
|
137
|
+
term-ansicolor (1.6.0)
|
138
|
+
tins (~> 1.0)
|
139
|
+
thor (0.20.0)
|
140
|
+
thread_safe (0.3.6)
|
141
|
+
tins (1.16.3)
|
142
|
+
tzinfo (1.2.5)
|
143
|
+
thread_safe (~> 0.1)
|
144
|
+
unf (0.1.4)
|
145
|
+
unf_ext
|
146
|
+
unf_ext (0.0.7.5)
|
147
|
+
unicode-display_width (1.4.0)
|
148
|
+
vcr (4.0.0)
|
149
|
+
webmock (3.4.2)
|
150
|
+
addressable (>= 2.3.6)
|
151
|
+
crack (>= 0.3.2)
|
152
|
+
hashdiff
|
153
|
+
websocket-driver (0.7.0)
|
154
|
+
websocket-extensions (>= 0.1.0)
|
155
|
+
websocket-extensions (0.1.3)
|
156
|
+
yard (0.9.15)
|
157
|
+
|
158
|
+
PLATFORMS
|
159
|
+
ruby
|
160
|
+
|
161
|
+
DEPENDENCIES
|
162
|
+
bundler (~> 1.16.a)
|
163
|
+
coveralls
|
164
|
+
fcoin_ruby_client!
|
165
|
+
onkcop
|
166
|
+
pry
|
167
|
+
rake (~> 10.0)
|
168
|
+
rspec (~> 3.0)
|
169
|
+
rubocop
|
170
|
+
simplecov
|
171
|
+
vcr
|
172
|
+
webmock
|
173
|
+
yard
|
174
|
+
|
175
|
+
BUNDLED WITH
|
176
|
+
1.16.0.pre.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 yukihirop
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
# FcoinRubyClient
|
2
|
+
[![Build Status](https://travis-ci.org/yukihirop/fcoin_ruby_client.svg?branch=master)](https://travis-ci.org/yukihirop/fcoin_ruby_client)
|
3
|
+
[![Coverage Status](https://coveralls.io/repos/github/yukihirop/fcoin_ruby_client/badge.svg?branch=master)](https://coveralls.io/github/yukihirop/fcoin_ruby_client?branch=master)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/098a36b2ed22f3a9e627/maintainability)](https://codeclimate.com/github/yukihirop/fcoin_ruby_client/maintainability)
|
5
|
+
|
6
|
+
This gem provides a ruby client of [FCOIN](https://www.fcoin.com/) REST API and WebSocket API.
|
7
|
+
|
8
|
+
Very easy to use.
|
9
|
+
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'fcoin_ruby_client'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install fcoin_ruby_client
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
Please use only those who can agree with [the following decration](#Declaration)
|
29
|
+
|
30
|
+
Configure default settings.
|
31
|
+
You can use all API at least by setting `api_key` and `secret_key` .
|
32
|
+
Because `api_key` and `secret_key` are confidential information,
|
33
|
+
we recommend that you read from environment variables.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require 'fcoin'
|
37
|
+
|
38
|
+
# Authentication is done
|
39
|
+
Fcoin.configure do |config|
|
40
|
+
config.api_key = ENV['FCOIN_API_KEY']
|
41
|
+
config.secret_key = ENV['FCOIN_SECRET_KEY']
|
42
|
+
end
|
43
|
+
|
44
|
+
# If you want to use the REST API
|
45
|
+
client = Fcoin::Client.new
|
46
|
+
|
47
|
+
# For example, get ticker information of ethusdt
|
48
|
+
puts client.market_ticker(symbol: :ethusdt)
|
49
|
+
#=> {"status"=>0, "data"=>{"ticker"=>{"latest_price"=>469.43, "most_recent_trade_vol"=>0.002, "max_buy_price"=>469.43, "max_buy_amount"=>7.6318, "min_sell_price"=>469.44, "min_sell_amount"=>0.0011, "trade_price_yesterday"=>468.75, "highest_price_today"=>472.0, "lowest_price_today"=>461.76, "symbol_base_vol_today"=>44442.419672207, "symbol_base_price_today"=>20784202.592831347}, "type"=>"ticker.ethusdt", "seq"=>100521295}}
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
If you want to see more usage, please see [examples](https://github.com/yukihirop/fcoin_ruby_client/tree/master/examples).
|
55
|
+
write how to use WebSocket API.
|
56
|
+
|
57
|
+
## CLI
|
58
|
+
We also prepare configuration files and provide CLI commands to execute API.
|
59
|
+
Describe the CLI command for preparing the setting file.
|
60
|
+
See [CLI example](https://github.com/yukihirop/fcoin_ruby_client/tree/master/examples/cli) for the CLI command to execute the API.
|
61
|
+
|
62
|
+
- `bundle exec fcoin validation init --path ./config`
|
63
|
+
|
64
|
+
Create validation setting file in ./config.
|
65
|
+
This setting file is used to set the validation.
|
66
|
+
|
67
|
+
- `bundle exec fcoin locale init --path ./cofig`
|
68
|
+
|
69
|
+
Create locale file in ./config.
|
70
|
+
For example, use in rails project.
|
71
|
+
|
72
|
+
|
73
|
+
If you want to know setting file, please see [config](https://github.com/yukihirop/fcoin_ruby_client/tree/master/lib/fcoin/config)
|
74
|
+
|
75
|
+
## Authorization
|
76
|
+
There are two authentication methods as follows.
|
77
|
+
|
78
|
+
#### 1. case when Fcoin
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
# Authentication is done when using the REST API
|
82
|
+
Fcoin.configure do |config|
|
83
|
+
config.api_key = ENV['FCOIN_API_KEY']
|
84
|
+
config.secret_key = ENV['FCOIN_SECRET_KEY']
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
#### 2. case when Fcoin::Client
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
# Authentication is done when using the REST API
|
92
|
+
Fcoin::Client.new(api_key: ENV['FCOIN_API_KEY'], secret_key: ENV['FCOIN_SECRET_KEY'])
|
93
|
+
```
|
94
|
+
|
95
|
+
|
96
|
+
When using REST API with multiple files, we recommend that you use `Fcoin.configure(&block)` to authenticate.
|
97
|
+
|
98
|
+
## Validation
|
99
|
+
To prevent unexpected orders and don't run invalid API,This gem is made to validate before executing the API.
|
100
|
+
|
101
|
+
1. `bundle exec validation init --path ./config`
|
102
|
+
2. Since there is `skip_validation(default: true)` in the setting, set it to `false`.
|
103
|
+
3. Since there is `validation_setting_path` in the setting, set it to `/path/to/your/my_settings.yml`
|
104
|
+
|
105
|
+
```diff
|
106
|
+
Fcoin.configure do |config|
|
107
|
+
config.api_key = ENV['FCOIN_API_KEY']
|
108
|
+
config.secret_key = ENV['FCOIN_SECRET_KEY']
|
109
|
+
+ config.skip_validation = false
|
110
|
+
+ config.validation_setting_path = File.expand_path('../../config/my_settings.yml', __FILE__)
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
Of course you can do this as well:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
Fcoin::Client.new(skip_validation: false, validation_setting_path: File.expand_path('../../config/my_settings.yml', __FILE__))
|
118
|
+
```
|
119
|
+
|
120
|
+
- 🚨 Since `my_settings.yml` is set appropriately, __please rewrite it appropriately.__ 🚨
|
121
|
+
- 🚨 __Please do not change the structure of `my_settings.yml`.__ Can't parse and a runtime error occurs. 🚨
|
122
|
+
|
123
|
+
|
124
|
+
## Customize my_settings.yml
|
125
|
+
We present some cases.
|
126
|
+
|
127
|
+
- case 1: If you wan't to be able to `buy(limit)` on `ethusdt` board (Mainboard A) in `1000 or more amount` and `1000usdt or more price`.
|
128
|
+
- case 2: If you wan't to be able to `sell(limit)` on `ftusdt` board (Mainboard B) in `1000 or more amount` and `0.01usdt or more price`.
|
129
|
+
|
130
|
+
#### case 1
|
131
|
+
If you wan't to be able to `buy(limit)` on `ethusdt` board (Mainboard A) in `1000 or more amount` and `1000usdt or more price`.
|
132
|
+
|
133
|
+
```diff
|
134
|
+
fcoin:
|
135
|
+
validation:
|
136
|
+
limit:
|
137
|
+
buy:
|
138
|
+
mainboard_A:
|
139
|
+
+ - { symbol: 'ethusdt', amount: { min: 0, max: 1000 }, price: { min: 0, max: 10000 } }
|
140
|
+
```
|
141
|
+
|
142
|
+
#### case 2
|
143
|
+
If you wan't to be able to `sell(limit)` on `ftusdt` board (Mainboard B) in `1000 or more amount` and `0.01usdt or more price`.
|
144
|
+
|
145
|
+
```diff
|
146
|
+
fcoin:
|
147
|
+
validation:
|
148
|
+
limit:
|
149
|
+
sell:
|
150
|
+
mainboard_B:
|
151
|
+
+ - { symbol: 'ftusdt', amount: { min: 0, max: 1000 }, price: { min: 0, max: 0.01 } }
|
152
|
+
```
|
153
|
+
|
154
|
+
Of course you can also set for `GPM` currencies.
|
155
|
+
|
156
|
+
|
157
|
+
## Configure
|
158
|
+
we explain the parameters that can be set.
|
159
|
+
|
160
|
+
|option|description|
|
161
|
+
|------|------------------------------------|
|
162
|
+
|adapter|default is Faraday.default_adapter.|
|
163
|
+
|endpoint|FCOIN REST API endpoint.<br> default is `https://api.fcoin.com/v2/`|
|
164
|
+
|wss_endpoint|FCOIN WebSocket API endpoint.<br>default is `wss://api.fcoin.com/v2/ws`|
|
165
|
+
|user_agent|default is `"Fcoin Ruby Gem #{Fcoin::VERSION}".freeze` |
|
166
|
+
|proxy| Faraday proxy.<br> Please see this [document](https://github.com/lostisland/faraday#proxy)|
|
167
|
+
|middlewares|Array with a [FaradayMiddleware](https://github.com/lostisland/faraday#writing-middleware) as an element.<br> Must be request middleware.|
|
168
|
+
|api_key|FCOIN API Public Key. Please see [FCOIN document](https://developer.fcoin.com/zh.html)|
|
169
|
+
|secret_key|FCOIN API Secret Key. Please see [FCOIN document](https://developer.fcoin.com/zh.html)|
|
170
|
+
|skip_validation|Setting it to true will skip the validation. default is `true`|
|
171
|
+
|validation_setting_path|Setting file path for validation.|
|
172
|
+
|format_type|Output format. default is `:hash` (This mean `ruby Hash`)|
|
173
|
+
|
174
|
+
|
175
|
+
## Development
|
176
|
+
There are test that require authentication and others that do not.
|
177
|
+
To run the test, do the following.
|
178
|
+
|
179
|
+
```bash
|
180
|
+
$ # Test without authentication
|
181
|
+
$ bundle exec rspec
|
182
|
+
$ #
|
183
|
+
$ # Test with authentication
|
184
|
+
# # The environment variable name must be this name
|
185
|
+
$ export FCOIN_API_KEY='your fcoin api key'
|
186
|
+
$ export FCOIN_SECRET_KEY='your fcoin secret key'
|
187
|
+
$ bundle exec rspec --tag fcoin_auth
|
188
|
+
|
189
|
+
```
|
190
|
+
|
191
|
+
## License
|
192
|
+
The gem is available as open source under the terms of the MIT License.
|
193
|
+
|
194
|
+
## Declaration
|
195
|
+
The author is not responsible for any damage caused by using this gem.
|
196
|
+
Please use at your own risk.
|
197
|
+
|
198
|
+
## Contributing
|
199
|
+
|
200
|
+
1. Fork it ( http://github.com/yukihirop/fcoin_ruby_client/fork )
|
201
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
202
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
203
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
204
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fcoin"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/fcoin
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'fcoin'
|
5
|
+
|
6
|
+
Fcoin.configure do |config|
|
7
|
+
config.api_key = ENV['FCOIN_API_KEY']
|
8
|
+
config.secret_key = ENV['FCOIN_SECRET_KEY']
|
9
|
+
config.skip_validation = ENV['VALIDATION_SETTING_PATH'].nil?
|
10
|
+
config.validation_setting_path = ENV['VALIDATION_SETTING_PATH']
|
11
|
+
config.format_type = :json
|
12
|
+
end
|
13
|
+
|
14
|
+
# Since `Fcoin::CLI.start` and `client.subscribe` can not be executed on the same thread.
|
15
|
+
class FcoinCLI
|
16
|
+
class << self
|
17
|
+
def start
|
18
|
+
case
|
19
|
+
when show_subscribe_command?
|
20
|
+
Fcoin::CLI.start
|
21
|
+
when subscribe?
|
22
|
+
subscribe
|
23
|
+
else
|
24
|
+
Fcoin::CLI.start
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def subscribe
|
31
|
+
params = parsed_argv.dup
|
32
|
+
block = Proc.new { |data| STDOUT.puts data }
|
33
|
+
case params[:topic]
|
34
|
+
when /ticker/
|
35
|
+
client.on_ticker(symbol: params[:symbol], &block)
|
36
|
+
when /depth/
|
37
|
+
client.on_depth(symbol: params[:symbol], level: params[:level], &block)
|
38
|
+
when /trade/
|
39
|
+
client.on_trade(symbol: params[:symbol], limit: params[:limit], &block)
|
40
|
+
when /candle/
|
41
|
+
client.on_candle(symbol: params[:symbol], resolution: params[:resolution], limit: params[:limit], &block)
|
42
|
+
when /topics/
|
43
|
+
client.on_topics(&block)
|
44
|
+
when /hello/
|
45
|
+
client.on_hello(&block)
|
46
|
+
end
|
47
|
+
client.subscribe
|
48
|
+
end
|
49
|
+
|
50
|
+
def parsed_argv
|
51
|
+
data = %w(subcom topic symbol level resolution limit).zip(Array.new(6)).to_h
|
52
|
+
ARGV.each_with_index do |argv, index|
|
53
|
+
case adjusted(argv)
|
54
|
+
when /subscribe/
|
55
|
+
data[:subcom] = argv
|
56
|
+
when /ticker|depth|trade|candle|topics|hello/
|
57
|
+
data[:topic] = argv
|
58
|
+
when /symbol/
|
59
|
+
data[:symbol] = ARGV[index + 1]
|
60
|
+
when /level/
|
61
|
+
data[:level] = ARGV[index + 1]
|
62
|
+
when /resolution/
|
63
|
+
data[:resolution] = ARGV[index + 1]
|
64
|
+
when /limit/
|
65
|
+
data[:limit] = ARGV[index + 1]
|
66
|
+
else
|
67
|
+
next
|
68
|
+
end
|
69
|
+
end
|
70
|
+
data
|
71
|
+
end
|
72
|
+
|
73
|
+
def subscribe?
|
74
|
+
subcom = ARGV.first
|
75
|
+
subcom == 'subscribe'
|
76
|
+
end
|
77
|
+
|
78
|
+
def show_subscribe_command?
|
79
|
+
subcom = ARGV.last
|
80
|
+
subcom == 'subscribe'
|
81
|
+
end
|
82
|
+
|
83
|
+
def adjusted(argv)
|
84
|
+
argv.gsub('-','')
|
85
|
+
end
|
86
|
+
|
87
|
+
def client
|
88
|
+
# In order to avoid the silent of validation error, skip_validation must be false
|
89
|
+
@client ||= Fcoin::RealTime::Client.new(skip_validation: false)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Instead of `Fcoin::CLI.start`
|
95
|
+
FcoinCLI.start
|
data/bin/setup
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# RealTime API CLI
|
2
|
+
|
3
|
+
In development, please use the `./bin/fcoin`.<br>
|
4
|
+
In Actual, please use the `bundle exec fcoin`.
|
5
|
+
|
6
|
+
## All
|
7
|
+
```
|
8
|
+
$ ./bin/fcoin
|
9
|
+
Commands:
|
10
|
+
fcoin account # Get Account Information
|
11
|
+
fcoin help [COMMAND] # Describe available commands or one specific command
|
12
|
+
fcoin locale # Locale Setting
|
13
|
+
fcoin market # Get Market Information
|
14
|
+
fcoin order # Operate Order
|
15
|
+
fcoin public # Get Public Information
|
16
|
+
fcoin subscribe # Subscribe topic
|
17
|
+
fcoin validation # Validation Setting
|
18
|
+
fcoin version # Print Version
|
19
|
+
|
20
|
+
```
|
21
|
+
|
22
|
+
__If you want to validate__
|
23
|
+
|
24
|
+
```bash
|
25
|
+
$ # For more settings
|
26
|
+
$ # @see https://github.com/yukihirop/fcoin_ruby_client#validation
|
27
|
+
$ ./bin/fcoin validation init --path ./config
|
28
|
+
create
|
29
|
+
create my_settings.yml
|
30
|
+
$ export VALIDATION_SETTING_PATH='/path/to/your/my_settings.yml'
|
31
|
+
```
|
32
|
+
|
33
|
+
## Subscribe
|
34
|
+
```bash
|
35
|
+
$ ./bin/fcoin subscribe
|
36
|
+
Commands:
|
37
|
+
fcoin subscribe candle --resolution=RESOLUTION --symbol=SYMBOL # Subscribe to candle information
|
38
|
+
fcoin subscribe depth --level=LEVEL --symbol=SYMBOL # Subscribe to depth information
|
39
|
+
fcoin subscribe hello # Subscribe to server time
|
40
|
+
fcoin subscribe help [COMMAND] # Describe subcommands or one specific subcommand
|
41
|
+
fcoin subscribe ticker --symbol=SYMBOL # Subscribe to ticker information
|
42
|
+
fcoin subscribe topics # Subscribe to topics
|
43
|
+
fcoin subscribe trade --symbol=SYMBOL # Subscribe to trade information
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
```bash
|
48
|
+
$ # Subscribe to ticker information
|
49
|
+
$ ./bin/fcoin subscribe ticker --symbol ethusdt
|
50
|
+
{"ticker":{"latest_price":417.64,"most_recent_trade_vol":0.2452,"max_buy_price":417.64,"max_buy_amount":0.0824,"min_sell_price":417.65,"min_sell_amount":0.1744,"trade_price_yesterday":399.39,"highest_price_today":420.01,"lowest_price_today":399.17,"symbol_base_vol_today":13500.553485427,"symbol_base_price_today":5568704.350213625},"type":"ticker.ethusdt","seq":105644599}
|
51
|
+
{"ticker":{"latest_price":417.64,"most_recent_trade_vol":0.2452,"max_buy_price":417.64,"max_buy_amount":0.0824,"min_sell_price":417.65,"min_sell_amount":0.1744,"trade_price_yesterday":399.39,"highest_price_today":420.01,"lowest_price_today":399.17,"symbol_base_vol_today":13500.553485427,"symbol_base_price_today":5568704.350213625},"type":"ticker.ethusdt","seq":105644607}
|
52
|
+
...
|
53
|
+
...
|
54
|
+
$ # Subscribe to depth information
|
55
|
+
$ ./bin/fcoin subscribe depth --symbol ethusdt --level L20
|
56
|
+
{"bids":[{"price":417.65,"amount":0.4365},{"price":417.6,"amount":8.282},{"price":417.57,"amount":9.5453},{"price":417.56,"amount":0.0404},{"price":417.55,"amount":0.0064},{"price":417.54,"amount":0.0016},{"price":417.53,"amount":0.0016},{"price":417.5,"amount":2.5845},{"price":417.48,"amount":0.0092},{"price":417.42,"amount":0.02},{"price":417.3,"amount":0.005},{"price":417.1,"amount":0.005},{"price":417.07,"amount":0.0655},{"price":417.03,"amount":0.0039},{"price":417.01,"amount":2.538},{"price":417.0,"amount":0.6005},{"price":416.98,"amount":0.0528},{"price":416.97,"amount":3.0},{"price":416.93,"amount":0.3},{"price":416.9,"amount":0.005}],"asks":[{"price":417.68,"amount":0.0166},{"price":417.69,"amount":0.0016},{"price":417.7,"amount":0.9476},{"price":417.71,"amount":0.0128},{"price":417.72,"amount":0.1234},{"price":417.82,"amount":0.0023},{"price":417.83,"amount":0.0171},{"price":417.86,"amount":0.0141},{"price":417.88,"amount":0.02},{"price":417.9,"amount":0.0075},{"price":417.91,"amount":0.01},{"price":418.1,"amount":0.005},{"price":418.24,"amount":0.931},{"price":418.3,"amount":0.005},{"price":418.35,"amount":0.1},{"price":418.4,"amount":0.1},{"price":418.45,"amount":14.77605139},{"price":418.46,"amount":0.1033},{"price":418.49,"amount":0.0065},{"price":418.5,"amount":0.505}],"ts":1533358172008,"seq":105645076,"type":"depth.L20.ethusdt"}
|
57
|
+
{"bids":[{"price":417.65,"amount":0.4365},{"price":417.6,"amount":8.282},{"price":417.57,"amount":9.5453},{"price":417.56,"amount":0.0404},{"price":417.55,"amount":0.0064},{"price":417.54,"amount":0.0016},{"price":417.53,"amount":0.0016},{"price":417.5,"amount":2.5845},{"price":417.48,"amount":0.0092},{"price":417.42,"amount":0.02},{"price":417.3,"amount":0.005},{"price":417.1,"amount":0.005},{"price":417.07,"amount":0.0655},{"price":417.03,"amount":0.0039},{"price":417.01,"amount":2.438},{"price":417.0,"amount":0.6005},{"price":416.98,"amount":0.0528},{"price":416.97,"amount":3.0},{"price":416.93,"amount":0.3},{"price":416.9,"amount":0.005}],"asks":[{"price":417.68,"amount":0.0166},{"price":417.69,"amount":0.0016},{"price":417.7,"amount":0.9476},{"price":417.71,"amount":0.0128},{"price":417.72,"amount":0.1234},{"price":417.82,"amount":0.0023},{"price":417.83,"amount":0.0171},{"price":417.86,"amount":0.0141},{"price":417.88,"amount":0.02},{"price":417.9,"amount":0.0075},{"price":417.91,"amount":0.01},{"price":418.1,"amount":0.005},{"price":418.24,"amount":0.931},{"price":418.3,"amount":0.005},{"price":418.35,"amount":0.1},{"price":418.4,"amount":0.1},{"price":418.45,"amount":14.77605139},{"price":418.46,"amount":0.1033},{"price":418.49,"amount":0.0065},{"price":418.5,"amount":0.505}],"ts":1533358173008,"seq":105645077,"type":"depth.L20.ethusdt"}
|
58
|
+
...
|
59
|
+
...
|
60
|
+
$ # Subscribe to trade information
|
61
|
+
$ ./bin/fcoin subscribe trade --symbol ethusdt
|
62
|
+
{"amount":0.1891,"type":"trade.ethusdt","ts":1533358225453,"id":105645412000,"side":"sell","price":417.6}
|
63
|
+
{"amount":0.3944,"type":"trade.ethusdt","ts":1533358234398,"id":105645473000,"side":"sell","price":417.6}
|
64
|
+
...
|
65
|
+
...
|
66
|
+
$ # Subscribe to candle information
|
67
|
+
$ ./bin/fcoin subscribe candle --symbol ethusdt --resolution MN
|
68
|
+
{"open":430.1,"type":"candle.MN.ethusdt","close":417.61,"high":435.93,"quote_vol":51514255.299988344,"id":1533052800,"count":390173,"low":397.61,"seq":10564587100000,"base_vol":122629.972229052}
|
69
|
+
{"open":430.1,"type":"candle.MN.ethusdt","close":417.61,"high":435.93,"quote_vol":51516631.99998658,"id":1533052800,"count":390174,"low":397.61,"seq":10564590200000,"base_vol":122635.663424182}
|
70
|
+
...
|
71
|
+
...
|
72
|
+
$ # Subscribe to topics
|
73
|
+
$ ./bin/fcoin subscribe topics
|
74
|
+
{"id":"61daeff4-36e4-4423-a4e4-adb158accadf","type":"topics","topics":[]}
|
75
|
+
$ # Subscribe to server time
|
76
|
+
$ ./bin/fcoin subscribe hello
|
77
|
+
{"type":"hello","ts":1533358407476}
|
78
|
+
```
|