fisco 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a03149d13be421156e6eedb20e843c27c2b332cb
4
+ data.tar.gz: f47e02912a72960b62d1f125ad6d7774a5a9e32e
5
+ SHA512:
6
+ metadata.gz: 90d5ab76c14267ab98e51a3012e56a13e39f7a225772aa77984222644ac4fa419b8ac9b90777d2f43ce1e6663610bb9e6bd18fc13a9106560b2f7554a728d4a2
7
+ data.tar.gz: 374d2e059407ca938f5f6b9fd8014751da555a4c3ce5e3da35ffb28f61e86c8f40eb557a4390cc1f9fd215512a702f9a3002332bfcc871171fec5f6c58c5f9fa
Binary file
@@ -0,0 +1,21 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ *~
14
+ *.sh
15
+ pkg/*
16
+ doc/*
17
+ Gemfile.lock
18
+ *.gem
19
+ bin
20
+ docs/_build
21
+ config.rb
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.16.0
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at shun.1ulce@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in fisco.gemspec
6
+ gemspec
@@ -0,0 +1,40 @@
1
+ # Fisco
2
+
3
+ Fisco API wrapper for ruby.
4
+ inspired by gem 'zaif'(https://github.com/palon7/zaif-ruby/fork) by palon7. Thanks a lot.
5
+ nothing any new feature from zaif gem above. just use on fisco.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'fisco'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fisco
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'fisco'
25
+
26
+ client = Fisco::Client.new(:api_key => FISCO_KEY, :api_secret => FISCO_SECRET)
27
+ client.bid("btc", 30760, 0.0001)
28
+ client.ask("btc", 30320, 0.0001)
29
+
30
+ client.get_info
31
+ => {"funds"=>{"jpy"=>0.0, "btc"=>0.0, "mona"=>0.0}, "deposit"=>{"btc"=>0.0, "jpy"=>0.0, "mona"=>0.0}, "rights"=>{"info"=>1, "trade"=>1, "withdraw"=>1, "personal_info"=>0, "id_info"=>0}, "trade_count"=>0, "open_orders"=>0, "server_time"=>1512732490}
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it ( https://github.com/1ulce/fisco/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create a new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fisco/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fisco"
8
+ spec.version = Fisco::VERSION
9
+ spec.authors = ["1ulce"]
10
+ spec.email = ["shun.1ulce@gmail.com"]
11
+ spec.summary = %q{Fisco API wrapper.}
12
+ spec.description = %q{Fisco API wrapper for bitcoin trade.}
13
+ spec.homepage = "https://github.com/1ulce/fisco"
14
+
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
@@ -0,0 +1,231 @@
1
+ # coding: utf-8
2
+ require 'pp'
3
+ require 'json'
4
+ require 'openssl'
5
+ require 'uri'
6
+ require 'net/http'
7
+ require 'time'
8
+
9
+ require "fisco/version"
10
+
11
+ module Fisco
12
+ class Client
13
+ def initialize(opt = {})
14
+ @cool_down = opt[:cool_down] || true
15
+ @cool_down_time = opt[:cool_down_time] || 2
16
+ @cert_path = opt[:cert_path] || nil
17
+ @api_key = opt[:api_key] || nil
18
+ @api_secret = opt[:api_secret] || nil
19
+ @fisco_public_url = "https://api.fcce.jp/api/1/"
20
+ @fisco_trade_url = "https://api.fcce.jp/tapi"
21
+ end
22
+
23
+ def set_api_key(api_key, api_secret)
24
+ @api_key = api_key
25
+ @api_secret = api_secret
26
+ end
27
+
28
+ #
29
+ # Public API
30
+ #
31
+
32
+ # Get last price of *currency_code* / *counter_currency_code*.
33
+ # @param [String] currency_code Base currency code
34
+ # @param [String] counter_currency_code Counter currency code
35
+ def get_last_price(currency_code, counter_currency_code = "jpy")
36
+ json = get_ssl(@fisco_public_url + "last_price/" + currency_code + "_" + counter_currency_code)
37
+ return json["last_price"]
38
+ end
39
+
40
+ # Get ticker of *currency_code* / *counter_currency_code*.
41
+ # @param [String] currency_code Base currency code
42
+ # @param [String] counter_currency_code Counter currency code
43
+ def get_ticker(currency_code, counter_currency_code = "jpy")
44
+ json = get_ssl(@fisco_public_url + "ticker/" + currency_code + "_" + counter_currency_code)
45
+ return json
46
+ end
47
+
48
+ # Get trades of *currency_code* / *counter_currency_code*.
49
+ # @param [String] currency_code Base currency code
50
+ # @param [String] counter_currency_code Counter currency code
51
+ def get_trades(currency_code, counter_currency_code = "jpy")
52
+ json = get_ssl(@fisco_public_url + "trades/" + currency_code + "_" + counter_currency_code)
53
+ return json
54
+ end
55
+
56
+ # Get depth of *currency_code* / *counter_currency_code*.
57
+ # @param [String] currency_code Base currency code
58
+ # @param [String] counter_currency_code Counter currency code
59
+ def get_depth(currency_code, counter_currency_code = "jpy")
60
+ json = get_ssl(@fisco_public_url + "depth/" + currency_code + "_" + counter_currency_code)
61
+ return json
62
+ end
63
+
64
+ #
65
+ # Trade API
66
+ #
67
+
68
+ # Get user infomation.
69
+ # Need api key.
70
+ # @return [Hash] Infomation of user.
71
+ def get_info
72
+ json = post_ssl(@fisco_trade_url, "get_info", {})
73
+ return json
74
+ end
75
+
76
+ # Get your trade history.
77
+ # Avalible options: from. count, from_id, end_id, order, since, end, currency_pair
78
+ # Need api key.
79
+ # @param [Hash]
80
+ def get_my_trades(option = {})
81
+ json = post_ssl(@fisco_trade_url, "trade_history", option)
82
+ # Convert to datetime
83
+ json.each do|k, v|
84
+ v["datetime"] = Time.at(v["timestamp"].to_i)
85
+ end
86
+
87
+ return json
88
+ end
89
+
90
+ # Get your active orders.
91
+ # Avalible options: currency_pair
92
+ # Need api key.
93
+ def get_active_orders(option = {})
94
+ json = post_ssl(@fisco_trade_url, "active_orders", option)
95
+ # Convert to datetime
96
+ json.each do|k, v|
97
+ v["datetime"] = Time.at(v["timestamp"].to_i)
98
+ end
99
+
100
+ return json
101
+ end
102
+ # Issue trade.
103
+ # Need api key.
104
+ def trade(currency_code, price, amount, action, limit = nil, counter_currency_code = "jpy")
105
+ currency_pair = currency_code + "_" + counter_currency_code
106
+ params = {:currency_pair => currency_pair, :action => action, :price => price, :amount => amount}
107
+ params.store(:limit, limit) if limit
108
+ json = post_ssl(@fisco_trade_url, "trade", params)
109
+ return json
110
+ end
111
+
112
+ # Issue bid order.
113
+ # Need api key.
114
+ def bid(currency_code, price, amount, limit = nil, counter_currency_code = "jpy")
115
+ return trade(currency_code, price, amount, "bid", limit, counter_currency_code)
116
+ end
117
+
118
+ # Issue ask order.
119
+ # Need api key.
120
+ def ask(currency_code, price, amount, limit = nil, counter_currency_code = "jpy")
121
+ return trade(currency_code, price, amount, "ask", limit, counter_currency_code)
122
+ end
123
+
124
+ # Cancel order.
125
+ # Need api key.
126
+ def cancel(order_id)
127
+ json = post_ssl(@fisco_trade_url, "cancel_order", {:order_id => order_id})
128
+ return json
129
+ end
130
+
131
+ # Withdraw funds.
132
+ # Need api key.
133
+ def withdraw(currency_code, address, amount, option = {})
134
+ option["currency"] = currency_code
135
+ option["address"] = address
136
+ option["amount"] = amount
137
+ json = post_ssl(@fisco_trade_url, "withdraw", option)
138
+ return json
139
+ end
140
+
141
+ #
142
+ # Class private method
143
+ #
144
+
145
+ private
146
+
147
+ def check_key
148
+ if @api_key.nil? or @api_secret.nil?
149
+ raise "You need to set a API key and secret"
150
+ end
151
+ end
152
+
153
+ # Connect to address via https, and return json reponse.
154
+ def get_ssl(address)
155
+ uri = URI.parse(address)
156
+ begin
157
+ https = Net::HTTP.new(uri.host, uri.port)
158
+ https.use_ssl = true
159
+ https.open_timeout = 5
160
+ https.read_timeout = 15
161
+ https.verify_mode = OpenSSL::SSL::VERIFY_PEER
162
+ https.verify_depth = 5
163
+
164
+ https.start {|w|
165
+ response = w.get(uri.request_uri)
166
+ case response
167
+ when Net::HTTPSuccess
168
+ json = JSON.parse(response.body)
169
+ raise JSONException, response.body if json == nil
170
+ raise APIErrorException, json["error"] if json.is_a?(Hash) && json.has_key?("error")
171
+ get_cool_down
172
+ return json
173
+ else
174
+ raise ConnectionFailedException, "Failed to connect to fisco."
175
+ end
176
+ }
177
+ rescue
178
+ raise
179
+ end
180
+ end
181
+
182
+ # Connect to address via https, and return json reponse.
183
+ def post_ssl(address, method, data)
184
+ check_key
185
+ uri = URI.parse(address)
186
+ data["method"] = method
187
+ data["nonce"] = get_nonce
188
+ begin
189
+ req = Net::HTTP::Post.new(uri)
190
+ req.set_form_data(data)
191
+ req["Key"] = @api_key
192
+ req["Sign"] = OpenSSL::HMAC::hexdigest(OpenSSL::Digest.new('sha512'), @api_secret, req.body)
193
+
194
+
195
+ https = Net::HTTP.new(uri.host, uri.port)
196
+ https.use_ssl = true
197
+ https.open_timeout = 5
198
+ https.read_timeout = 15
199
+ https.verify_mode = OpenSSL::SSL::VERIFY_PEER
200
+ https.verify_depth = 5
201
+
202
+ https.start {|w|
203
+ response = w.request(req)
204
+ case response
205
+ when Net::HTTPSuccess
206
+ json = JSON.parse(response.body)
207
+ raise JSONException, response.body if json == nil
208
+ raise APIErrorException, json["error"] if json.is_a?(Hash) && json["success"] == 0
209
+ get_cool_down
210
+ return json["return"]
211
+ else
212
+ raise ConnectionFailedException, "Failed to connect to fisco: " + response.value
213
+ end
214
+ }
215
+ rescue
216
+ raise
217
+ end
218
+ end
219
+
220
+ def get_nonce
221
+ time = Time.now.to_f
222
+ return time.to_i
223
+ end
224
+
225
+ def get_cool_down
226
+ if @cool_down
227
+ sleep(@cool_down_time)
228
+ end
229
+ end
230
+ end
231
+ end
@@ -0,0 +1,3 @@
1
+ module Fisco
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fisco
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - 1ulce
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Fisco API wrapper for bitcoin trade.
56
+ email:
57
+ - shun.1ulce@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".DS_Store"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - fisco.gemspec
73
+ - lib/fisco.rb
74
+ - lib/fisco/version.rb
75
+ homepage: https://github.com/1ulce/fisco
76
+ licenses: []
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.5.1
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Fisco API wrapper.
98
+ test_files: []