zaif_wrapper 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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.idea/inspectionProfiles/Project_Default.xml +6 -0
- data/.idea/vcs.xml +6 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +76 -0
- data/README.md +92 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/zaif_wrapper/client.rb +258 -0
- data/lib/zaif_wrapper/version.rb +3 -0
- data/lib/zaif_wrapper.rb +3 -0
- data/zaif_wrapper.gemspec +29 -0
- metadata +144 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: fca04b0cb5dfe64933455e0b3d5621b660f429a2fbd85f4fbbcf4343e6c64b31
|
|
4
|
+
data.tar.gz: 38d1951fd6b11338f7c094d6d1ea2a2e52422b505a76f0cb012fca3827e5f715
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f422e3ac8f0a14d21700c3964260bf826a4e9248b0dfbad40755d5cfbec2b8f50a189d543353d53f3dce37da25f917e61d75a4da269b533917faa0ac5fa4eec9
|
|
7
|
+
data.tar.gz: 10bf44494aea8ef677f970b5b0c70ef99525a4f4944fbb4f1ef215a59926390398824e3cedee5d813a5715fc02affa9aa94b84dddba878fd4ffeaff542f4ed77
|
data/.gitignore
ADDED
data/.idea/vcs.xml
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -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 akitaka0405@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,12 @@
|
|
|
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 zaif_wrapper.gemspec
|
|
6
|
+
gemspec
|
|
7
|
+
gem 'pry'
|
|
8
|
+
gem 'byebug'
|
|
9
|
+
gem 'coveralls', require: false
|
|
10
|
+
gem 'json'
|
|
11
|
+
gem 'json_expressions'
|
|
12
|
+
gem 'dotenv'
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
zaif_wrapper (0.1.0)
|
|
5
|
+
json
|
|
6
|
+
rest-client
|
|
7
|
+
websocket-client-simple
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
byebug (10.0.0)
|
|
13
|
+
coderay (1.1.2)
|
|
14
|
+
coveralls (0.8.21)
|
|
15
|
+
json (>= 1.8, < 3)
|
|
16
|
+
simplecov (~> 0.14.1)
|
|
17
|
+
term-ansicolor (~> 1.3)
|
|
18
|
+
thor (~> 0.19.4)
|
|
19
|
+
tins (~> 1.6)
|
|
20
|
+
docile (1.1.5)
|
|
21
|
+
domain_name (0.5.20170404)
|
|
22
|
+
unf (>= 0.0.5, < 1.0.0)
|
|
23
|
+
dotenv (2.2.1)
|
|
24
|
+
event_emitter (0.2.6)
|
|
25
|
+
http-cookie (1.0.3)
|
|
26
|
+
domain_name (~> 0.5)
|
|
27
|
+
json (2.1.0)
|
|
28
|
+
json_expressions (0.9.0)
|
|
29
|
+
method_source (0.9.0)
|
|
30
|
+
mime-types (3.1)
|
|
31
|
+
mime-types-data (~> 3.2015)
|
|
32
|
+
mime-types-data (3.2016.0521)
|
|
33
|
+
minitest (5.11.3)
|
|
34
|
+
netrc (0.11.0)
|
|
35
|
+
pry (0.11.3)
|
|
36
|
+
coderay (~> 1.1.0)
|
|
37
|
+
method_source (~> 0.9.0)
|
|
38
|
+
rake (10.5.0)
|
|
39
|
+
rest-client (2.0.2)
|
|
40
|
+
http-cookie (>= 1.0.2, < 2.0)
|
|
41
|
+
mime-types (>= 1.16, < 4.0)
|
|
42
|
+
netrc (~> 0.8)
|
|
43
|
+
simplecov (0.14.1)
|
|
44
|
+
docile (~> 1.1.0)
|
|
45
|
+
json (>= 1.8, < 3)
|
|
46
|
+
simplecov-html (~> 0.10.0)
|
|
47
|
+
simplecov-html (0.10.2)
|
|
48
|
+
term-ansicolor (1.6.0)
|
|
49
|
+
tins (~> 1.0)
|
|
50
|
+
thor (0.19.4)
|
|
51
|
+
tins (1.16.3)
|
|
52
|
+
unf (0.1.4)
|
|
53
|
+
unf_ext
|
|
54
|
+
unf_ext (0.0.7.5)
|
|
55
|
+
websocket (1.2.5)
|
|
56
|
+
websocket-client-simple (0.3.0)
|
|
57
|
+
event_emitter
|
|
58
|
+
websocket
|
|
59
|
+
|
|
60
|
+
PLATFORMS
|
|
61
|
+
ruby
|
|
62
|
+
|
|
63
|
+
DEPENDENCIES
|
|
64
|
+
bundler (~> 1.16)
|
|
65
|
+
byebug
|
|
66
|
+
coveralls
|
|
67
|
+
dotenv
|
|
68
|
+
json
|
|
69
|
+
json_expressions
|
|
70
|
+
minitest
|
|
71
|
+
pry
|
|
72
|
+
rake (~> 10.0)
|
|
73
|
+
zaif_wrapper!
|
|
74
|
+
|
|
75
|
+
BUNDLED WITH
|
|
76
|
+
1.16.1
|
data/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# ZaifWrapper
|
|
2
|
+
|
|
3
|
+
This is an unofficial Ruby wrapper for the Zaif exchange REST APIs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'zaif_wrapper'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install zaif_wrapper
|
|
20
|
+
|
|
21
|
+
#### REST Client
|
|
22
|
+
|
|
23
|
+
Require zaif_wrapper:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
require 'zaif_wrapper'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#### Public Client
|
|
30
|
+
```ruby
|
|
31
|
+
# If you only plan on touching public API endpoints.
|
|
32
|
+
client = Zaif_wrapper::Client::ZaifPublicApi.new
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Create various requests:
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
client.currencies('btc') # => [{ "name": "btc", "is_token": false }]
|
|
39
|
+
client.currency_pairs('btc_jpy')
|
|
40
|
+
client.last_price('btc_jpy')
|
|
41
|
+
client.depth('btc_jpy')
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### Private Client
|
|
45
|
+
```ruby
|
|
46
|
+
# If you only plan on touching Future API endpoints.
|
|
47
|
+
client = Zaif_wrapper::Client::ZaifPrivateApi.new(api_key, api_secret)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
client.currencies('btc') # => [{ "name": "btc", "is_token": false }]
|
|
52
|
+
client.currency_pairs('btc_jpy')
|
|
53
|
+
client.last_price('btc_jpy')
|
|
54
|
+
client.depth('btc_jpy')
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Future Client(No Test)
|
|
58
|
+
```ruby
|
|
59
|
+
# If you only plan on touching Future API endpoints.
|
|
60
|
+
client = Zaif_wrapper::Client::ZaifFutureApi.new
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### Future Client(No Test)
|
|
64
|
+
```ruby
|
|
65
|
+
# If you only plan on touching Future API endpoints.
|
|
66
|
+
client = Zaif_wrapper::Client::ZaifFutureApi.new
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### Leverage Client(No Test)
|
|
70
|
+
```ruby
|
|
71
|
+
# If you only plan on touching Leverage API endpoints.
|
|
72
|
+
client = Zaif_wrapper::Client::ZaifLeverageApi.new
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### WebSocket Client(No Test)
|
|
76
|
+
```ruby
|
|
77
|
+
# If you only plan on connecting WebSocket API endpoints.
|
|
78
|
+
client = Zaif_wrapper::Client::ZaifStreamApi.new
|
|
79
|
+
client.stream('btc_jpy')
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Contributing
|
|
83
|
+
|
|
84
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cobafan/zaif_wrapper.
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
88
|
+
|
|
89
|
+
## Donate
|
|
90
|
+
|
|
91
|
+
If This library is useful to you feel free to donate zaif with twitter chip.
|
|
92
|
+
* screen_name: cobafan
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "zaif_wrapper"
|
|
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/setup
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# require 'bundler/setup'
|
|
2
|
+
require 'rest-client'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'byebug'
|
|
5
|
+
require 'websocket-client-simple'
|
|
6
|
+
|
|
7
|
+
module ZaifWrapper
|
|
8
|
+
module Client
|
|
9
|
+
class ZaifPublicApi
|
|
10
|
+
REQUEST_URL_BASE = 'https://api.zaif.jp/api/1/'
|
|
11
|
+
METHODS = {
|
|
12
|
+
:currencies => 'currency_code',
|
|
13
|
+
:currency_pairs => 'currency_pair',
|
|
14
|
+
:last_price => 'currency_pair',
|
|
15
|
+
:ticker => 'currency_pair',
|
|
16
|
+
:trades => 'currency_pair',
|
|
17
|
+
:depth => 'currency_pair'
|
|
18
|
+
}.freeze
|
|
19
|
+
|
|
20
|
+
def request(path)
|
|
21
|
+
response = RestClient.get "#{REQUEST_URL_BASE}#{path}"
|
|
22
|
+
JSON.parse(response.body)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
METHODS.each do |method_name, params|
|
|
26
|
+
define_method(method_name) { |params|
|
|
27
|
+
path = "#{method_name.to_s}/#{params}"
|
|
28
|
+
request(path)
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class ZaifPrivateApi
|
|
34
|
+
REQUEST_URL_BASE = 'https://api.zaif.jp/tapi'
|
|
35
|
+
|
|
36
|
+
def initialize(api_key, api_secret)
|
|
37
|
+
@api_key = api_key
|
|
38
|
+
@api_secret = api_secret
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def request(method, params = {})
|
|
42
|
+
body = {
|
|
43
|
+
'method' => method,
|
|
44
|
+
'nonce' => get_nonce
|
|
45
|
+
}
|
|
46
|
+
signature_text = "method=#{method}&nonce=#{get_nonce}"
|
|
47
|
+
unless params.empty?
|
|
48
|
+
params.each { |param|
|
|
49
|
+
body.store(param[0], param[1])
|
|
50
|
+
signature_text = "#{signature_text}&#{param[0]}=#{param[1]}"
|
|
51
|
+
}
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
response = RestClient.post REQUEST_URL_BASE, body, {
|
|
55
|
+
content_type: :json,
|
|
56
|
+
accept: :json,
|
|
57
|
+
key: @api_key,
|
|
58
|
+
sign: create_signature(signature_text)
|
|
59
|
+
}
|
|
60
|
+
JSON.parse(response.body)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def get_info
|
|
64
|
+
request('get_info')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def get_info2
|
|
68
|
+
request('get_info2')
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def get_personal_info
|
|
72
|
+
request('get_personal_info')
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def get_id_info
|
|
76
|
+
request('get_id_info')
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def trade_history(params = {})
|
|
80
|
+
request('trade_history', params)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def active_orders(params = {})
|
|
84
|
+
request('active_orders', params)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def trade(params = {})
|
|
88
|
+
raise "Required parameters are missing" if params["currency_pair"].nil? || params["action"].nil? || params["price"].nil? || params["amount"].nil?
|
|
89
|
+
request('trade', params)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def cancel_order(params = {})
|
|
93
|
+
raise "Required parameters are missing" if params["order_id"].nil?
|
|
94
|
+
request('cancel_order', params)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def withdraw(params = {})
|
|
98
|
+
raise "Required parameters are missing" if params["currency"].nil? || params["address"].nil? || params["amount"].nil?
|
|
99
|
+
request('withdraw', params)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def deposit_history(params = {})
|
|
103
|
+
raise "Required parameters are missing" if params["currency"].nil?
|
|
104
|
+
request('deposit_history', params)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def withdraw_history(params = {})
|
|
108
|
+
raise "Required parameters are missing" if params["currency"].nil?
|
|
109
|
+
request('withdraw_history', params)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def get_nonce
|
|
113
|
+
Time.now.to_f.to_i
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def create_signature(body)
|
|
117
|
+
OpenSSL::HMAC::hexdigest(OpenSSL::Digest.new('sha512'), @api_secret, body.to_s)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
class ZaifFutureApi
|
|
122
|
+
REQUEST_URL_BASE = 'https://api.zaif.jp/fapi/1/'
|
|
123
|
+
|
|
124
|
+
def request(path)
|
|
125
|
+
response = RestClient.get "#{REQUEST_URL_BASE}#{path}"
|
|
126
|
+
JSON.parse(response.body)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
## /groups/#{group_id}
|
|
130
|
+
def groups(group_id)
|
|
131
|
+
path = "groups/#{group_id}"
|
|
132
|
+
request(path)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
## last_price/#{group_id}#{currency_pair}
|
|
136
|
+
def last_price(group_id, currency_pair)
|
|
137
|
+
path = "last_price/#{group_id}/#{currency_pair}"
|
|
138
|
+
request(path)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
## /ticker/#{group_id}/#{currency_pair}
|
|
142
|
+
def ticker(group_id, currency_pair)
|
|
143
|
+
path = "ticker/#{group_id}/#{currency_pair}"
|
|
144
|
+
request(path)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
## /trades/{group_id}/{currency_pair}
|
|
148
|
+
def trades(group_id, currency_pair)
|
|
149
|
+
path = "trades/#{group_id}/#{currency_pair}"
|
|
150
|
+
request(path)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
## /depth/{group_id}/{currency_pair}
|
|
154
|
+
def depth(group_id, currency_pair)
|
|
155
|
+
path = "depth/#{group_id}/#{currency_pair}"
|
|
156
|
+
request(path)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
class ZaifLeverageApi
|
|
161
|
+
REQUEST_URL_BASE = 'https://api.zaif.jp/tlapi'
|
|
162
|
+
|
|
163
|
+
def initialize(api_key, api_secret)
|
|
164
|
+
@api_key = api_key
|
|
165
|
+
@api_secret = api_secret
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def request(method, params = {})
|
|
169
|
+
body = {
|
|
170
|
+
'method' => method,
|
|
171
|
+
'nonce' => get_nonce
|
|
172
|
+
}
|
|
173
|
+
signature_text = "method=#{method}&nonce=#{get_nonce}"
|
|
174
|
+
unless params.empty?
|
|
175
|
+
params.each { |param|
|
|
176
|
+
body.store(param[0], param[1])
|
|
177
|
+
signature_text = "#{signature_text}&#{param[0]}=#{param[1]}"
|
|
178
|
+
}
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
response = RestClient.post REQUEST_URL_BASE, body, {
|
|
182
|
+
content_type: :json,
|
|
183
|
+
accept: :json,
|
|
184
|
+
key: @api_key,
|
|
185
|
+
sign: create_signature(signature_text)
|
|
186
|
+
}
|
|
187
|
+
JSON.parse(response.body)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def get_positions(params = {})
|
|
191
|
+
raise "Required parameters are missing" if params["type"].nil? || (params["type"] == 'futures' && params["group_id"].nil?)
|
|
192
|
+
request('get_positions', params)
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def position_history(params = {})
|
|
196
|
+
raise "Required parameters are missing" if params["type"].nil? || (params["type"] == 'futures' && params["group_id"].nil?)
|
|
197
|
+
request('position_history', params)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def active_positions(params = {})
|
|
201
|
+
raise "Required parameters are missing" if params["type"].nil? || (params["type"] == 'futures' && params["group_id"].nil?)
|
|
202
|
+
request('active_positions', params)
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def create_position(params = {})
|
|
206
|
+
raise "Required parameters are missing" if params["type"].nil? || (params["type"] == 'futures' && params["group_id"].nil?) || params["currency_pair"].nil? || params["action"].nil? || params["price"].nil? || params["amount"].nil? || params["leverage"].nil?
|
|
207
|
+
request('create_position', params)
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def change_position(params = {})
|
|
211
|
+
raise "Required parameters are missing" if params["type"].nil? || (params["type"] == 'futures' && params["group_id"].nil?) || params["leverage_id"].nil? || params["price"].nil?
|
|
212
|
+
request('change_position', params)
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def cancel_position(params = {})
|
|
216
|
+
raise "Required parameters are missing" if params["type"].nil? || (params["type"] == 'futures' && params["group_id"].nil?) || params["leverage_id"].nil?
|
|
217
|
+
request('cancel_position', params)
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def get_nonce
|
|
221
|
+
Time.now.to_f.to_i
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def create_signature(body)
|
|
225
|
+
OpenSSL::HMAC::hexdigest(OpenSSL::Digest.new('sha512'), @api_secret, body.to_s)
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
class ZaifStreamApi
|
|
230
|
+
REQUEST_URL_BASE = 'wss://ws.zaif.jp:'
|
|
231
|
+
|
|
232
|
+
def initialize(port = 8888)
|
|
233
|
+
@port = port
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
## wss://ws.zaif.jp/stream?currency_pair={currency_pair}
|
|
237
|
+
def stream(currency_pair, output_filename = nil)
|
|
238
|
+
f = if output_filename.nil?
|
|
239
|
+
STDOUT
|
|
240
|
+
else
|
|
241
|
+
File.open(output_filename, 'a')
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
ws = WebSocket::Client::Simple.connect "#{REQUEST_URL_BASE}#{@port}/stream?currency_pair=#{currency_pair}"
|
|
245
|
+
ws.on :message do |msg|
|
|
246
|
+
f.puts msg.data + "\n"
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
ws.on :close do |e|
|
|
250
|
+
f.close unless output_filename.nil?
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
loop do
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
end
|
data/lib/zaif_wrapper.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "zaif_wrapper/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "zaif_wrapper"
|
|
8
|
+
spec.version = ZaifWrapper::VERSION
|
|
9
|
+
spec.authors = ["cobafan"]
|
|
10
|
+
spec.email = ["akitaka0405@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Zaif Api Library}
|
|
13
|
+
spec.description = %q{I made this so that We can easily use Zaif's API}
|
|
14
|
+
spec.homepage = "https://github.com/cobafan/"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
|
|
18
|
+
spec.bindir = "exe"
|
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
spec.add_runtime_dependency 'rest-client'
|
|
23
|
+
spec.add_runtime_dependency 'json'
|
|
24
|
+
spec.add_runtime_dependency 'websocket-client-simple'
|
|
25
|
+
|
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
28
|
+
spec.add_development_dependency "minitest"
|
|
29
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: zaif_wrapper
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- cobafan
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-02-11 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rest-client
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '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'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: json
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: websocket-client-simple
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: bundler
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.16'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.16'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '10.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '10.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: minitest
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
description: I made this so that We can easily use Zaif's API
|
|
98
|
+
email:
|
|
99
|
+
- akitaka0405@gmail.com
|
|
100
|
+
executables: []
|
|
101
|
+
extensions: []
|
|
102
|
+
extra_rdoc_files: []
|
|
103
|
+
files:
|
|
104
|
+
- ".gitignore"
|
|
105
|
+
- ".idea/inspectionProfiles/Project_Default.xml"
|
|
106
|
+
- ".idea/vcs.xml"
|
|
107
|
+
- ".rspec"
|
|
108
|
+
- ".travis.yml"
|
|
109
|
+
- CODE_OF_CONDUCT.md
|
|
110
|
+
- Gemfile
|
|
111
|
+
- Gemfile.lock
|
|
112
|
+
- README.md
|
|
113
|
+
- Rakefile
|
|
114
|
+
- bin/console
|
|
115
|
+
- bin/setup
|
|
116
|
+
- lib/zaif_wrapper.rb
|
|
117
|
+
- lib/zaif_wrapper/client.rb
|
|
118
|
+
- lib/zaif_wrapper/version.rb
|
|
119
|
+
- zaif_wrapper.gemspec
|
|
120
|
+
homepage: https://github.com/cobafan/
|
|
121
|
+
licenses:
|
|
122
|
+
- MIT
|
|
123
|
+
metadata: {}
|
|
124
|
+
post_install_message:
|
|
125
|
+
rdoc_options: []
|
|
126
|
+
require_paths:
|
|
127
|
+
- lib
|
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
|
+
requirements:
|
|
130
|
+
- - ">="
|
|
131
|
+
- !ruby/object:Gem::Version
|
|
132
|
+
version: '0'
|
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
138
|
+
requirements: []
|
|
139
|
+
rubyforge_project:
|
|
140
|
+
rubygems_version: 2.7.3
|
|
141
|
+
signing_key:
|
|
142
|
+
specification_version: 4
|
|
143
|
+
summary: Zaif Api Library
|
|
144
|
+
test_files: []
|