bitflyer_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c1f455705221035a42e262c141bd872b41247df
4
+ data.tar.gz: 6dc90bfdcfebeb1b514ee21949a80d471e59594c
5
+ SHA512:
6
+ metadata.gz: 2e989e772876b58ee04f093328535d4f498f7d23090ca83e623b35c9cc004e47c25a2d3ed1da1fc9562798ea2cb7ecd7ed51d8bb5f57a85b233da9a358d11663
7
+ data.tar.gz: 5f8100a4e218acafc3d249097d020ff256809e3a137c06962632a863f2411140887c8533543d1ca5332c643d0814928aa16458d5fb6a696d7a0ef55608dbca6f
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,31 @@
1
+ # See for detail: https://github.com/bbatsov/rubocop/blob/master/config/default.yml
2
+ AllCops:
3
+ TargetRubyVersion: 2.4
4
+ DisabledByDefault: true
5
+
6
+ Bundler/OrderedGems:
7
+ Enabled: true
8
+
9
+ Style/EmptyLines:
10
+ Enabled: true
11
+
12
+ Style/TrailingBlankLines:
13
+ Enabled: true
14
+
15
+ Style/TrailingWhitespace:
16
+ Enabled: true
17
+
18
+ Style/MethodDefParentheses:
19
+ Enabled: true
20
+
21
+ Style/StringLiterals:
22
+ EnforcedStyle: double_quotes
23
+
24
+ Style/StringLiteralsInInterpolation:
25
+ EnforcedStyle: single_quotes
26
+
27
+ Style/SymbolArray:
28
+ EnforcedStyle: percent
29
+
30
+ Style/WordArray:
31
+ EnforcedStyle: percent
@@ -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 cohki0305@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 bitflyer_api.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bitflyer_api (0.1.0)
5
+ activesupport
6
+ faraday
7
+ faraday_middleware
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (5.1.4)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (~> 0.7)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ ast (2.3.0)
18
+ coderay (1.1.1)
19
+ concurrent-ruby (1.0.5)
20
+ diff-lcs (1.3)
21
+ faraday (0.13.1)
22
+ multipart-post (>= 1.2, < 3)
23
+ faraday_middleware (0.12.2)
24
+ faraday (>= 0.7.4, < 1.0)
25
+ i18n (0.9.1)
26
+ concurrent-ruby (~> 1.0)
27
+ method_source (0.9.0)
28
+ minitest (5.10.3)
29
+ multipart-post (2.0.0)
30
+ parallel (1.12.0)
31
+ parser (2.4.0.0)
32
+ ast (~> 2.2)
33
+ powerpack (0.1.1)
34
+ pry (0.11.2)
35
+ coderay (~> 1.1.0)
36
+ method_source (~> 0.9.0)
37
+ rainbow (2.2.2)
38
+ rake
39
+ rake (10.5.0)
40
+ rspec (3.7.0)
41
+ rspec-core (~> 3.7.0)
42
+ rspec-expectations (~> 3.7.0)
43
+ rspec-mocks (~> 3.7.0)
44
+ rspec-core (3.7.0)
45
+ rspec-support (~> 3.7.0)
46
+ rspec-expectations (3.7.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.7.0)
49
+ rspec-mocks (3.7.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.7.0)
52
+ rspec-support (3.7.0)
53
+ rubocop (0.51.0)
54
+ parallel (~> 1.10)
55
+ parser (>= 2.3.3.1, < 3.0)
56
+ powerpack (~> 0.1)
57
+ rainbow (>= 2.2.2, < 3.0)
58
+ ruby-progressbar (~> 1.7)
59
+ unicode-display_width (~> 1.0, >= 1.0.1)
60
+ ruby-progressbar (1.9.0)
61
+ thread_safe (0.3.6)
62
+ tzinfo (1.2.4)
63
+ thread_safe (~> 0.1)
64
+ unicode-display_width (1.3.0)
65
+ vcr (3.0.3)
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ bitflyer_api!
72
+ bundler (~> 1.15)
73
+ pry
74
+ rake (~> 10.0)
75
+ rspec (~> 3.0)
76
+ rubocop (~> 0.51.0)
77
+ vcr
78
+
79
+ BUNDLED WITH
80
+ 1.15.4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 t-kaneko
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # BitflyerApi
2
+
3
+ `bitflyer_api` is Ruby api wrapper for [Bitflyer lightning](https://lightning.bitflyer.jp/docs)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bitflyer_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bitflyer_api
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require "bitflyer_api"
25
+
26
+ BitflyerApi.config do |config|
27
+ config.key = YOUR_API_KEY
28
+ config.secret = YOUR_API_SECRET
29
+ end
30
+
31
+ client = BitflyerApi.client
32
+ client.my_addresses
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mc-chinju/bitflyer_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bitflyer_api"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "bitflyer_api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bitflyer_api"
8
+ spec.version = BitflyerApi::VERSION
9
+ spec.authors = ["mc-chinju", "cohki0305"]
10
+ spec.email = ["takeiteasy.enjoyeverything@gmail.com"]
11
+
12
+ spec.summary = %q{Bitflyer api wrapper}
13
+ spec.description = %q{Bitflyer api wrapper. see https://lightning.bitflyer.jp/docs}
14
+ spec.homepage = "https://github.com/mc-chinju/bitflyer-api"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "rubocop", "~> 0.51.0"
28
+ spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "vcr"
30
+
31
+ spec.add_runtime_dependency "activesupport"
32
+ spec.add_runtime_dependency "faraday"
33
+ spec.add_runtime_dependency "faraday_middleware"
34
+ end
@@ -0,0 +1,27 @@
1
+ require "bitflyer_api/http/connection"
2
+ require "bitflyer_api/methods/public"
3
+ require "bitflyer_api/methods/private/account_statement"
4
+ require "bitflyer_api/methods/private/api"
5
+ require "bitflyer_api/methods/private/assets"
6
+ require "bitflyer_api/methods/private/trade"
7
+
8
+ module BitflyerApi
9
+ class Client
10
+ include BitflyerApi::Methods::Public
11
+ include BitflyerApi::Methods::Private::AccountStatement
12
+ include BitflyerApi::Methods::Private::API
13
+ include BitflyerApi::Methods::Private::Assets
14
+ include BitflyerApi::Methods::Private::Trade
15
+
16
+ attr_accessor :conn
17
+
18
+ def initialize(key, secret)
19
+ @conn = BitflyerApi::HTTP::Connection.new(key, secret)
20
+ end
21
+
22
+ private
23
+ def prepare_query(options)
24
+ options.delete_if { |_, v| v.nil? }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module BitflyerApi
2
+ module Configuration
3
+
4
+ CONFIGURABLE_ATTRIBUTES = %i(key secret)
5
+ attr_accessor *CONFIGURABLE_ATTRIBUTES
6
+
7
+ def configure
8
+ yield self
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ require "bitflyer_api/http/middleware"
2
+ require "faraday"
3
+ require "faraday_middleware"
4
+
5
+ module BitflyerApi
6
+ module HTTP
7
+ class Connection
8
+ extend Forwardable
9
+ def_delegators :@conn, :get, :post
10
+
11
+ def initialize(key, secret)
12
+ @conn = Faraday.new(url: "https://api.bitflyer.jp") do |conn|
13
+ conn.request :json
14
+ conn.response :json
15
+ conn.use BitflyerApi::HTTP::Middleware, key, secret
16
+ conn.adapter Faraday.default_adapter
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,40 @@
1
+ require "faraday"
2
+ require "openssl"
3
+
4
+ module BitflyerApi
5
+ module HTTP
6
+ class Middleware < Faraday::Middleware
7
+ attr_accessor :key, :secret
8
+
9
+ def initialize(app, key, secret)
10
+ super(app)
11
+ @key = key
12
+ @secret = secret
13
+ end
14
+
15
+ def call(env)
16
+ return @app.call(env) if key.nil? || secret.nil?
17
+
18
+ env[:request_headers]["ACCESS-KEY"] = key if key
19
+ env[:request_headers]["ACCESS-TIMESTAMP"] = timestamp
20
+ env[:request_headers]["ACCESS-SIGN"] = signature(env, secret)
21
+ @app.call env
22
+ end
23
+
24
+ private
25
+
26
+ def signature(env, secret)
27
+ method = env[:method].to_s.upcase
28
+ query = env[:url].query.present? ? "?" + env[:url].query : ""
29
+ path = env[:url].path + query
30
+ body = env[:body] || ""
31
+
32
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), secret, "#{timestamp}#{method}#{path}#{body}")
33
+ end
34
+
35
+ def timestamp
36
+ Time.now.to_i.to_s
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,67 @@
1
+ module BitflyerApi::Methods::Private
2
+ module AccountStatement
3
+ def my_addresses
4
+ res = conn.get("/v1/me/getaddresses")
5
+ res.body
6
+ end
7
+
8
+ def my_coin_ins(count: 100, before: nil, after: nil)
9
+ query = prepare_query(
10
+ count: count,
11
+ before: before,
12
+ after: after
13
+ )
14
+
15
+ res = conn.get("/v1/me/getcoinins", query)
16
+ res.body
17
+ end
18
+
19
+ def my_coin_outs(count: 100, before: nil, after: nil)
20
+ query = prepare_query(
21
+ count: count,
22
+ before: before,
23
+ after: after
24
+ )
25
+
26
+ res = conn.get("/v1/me/getcoinouts", query)
27
+ res.body
28
+ end
29
+
30
+ def my_deposits(count: 100, before: nil, after: nil)
31
+ query = prepare_query(
32
+ count: count,
33
+ before: before,
34
+ after: after
35
+ )
36
+
37
+ res = conn.get("/v1/me/getdeposits", query)
38
+ res.body
39
+ end
40
+
41
+ def my_withdrawals(count: 100, before: nil, after: nil)
42
+ query = prepare_query(
43
+ count: count,
44
+ before: before,
45
+ after: after
46
+ )
47
+
48
+ res = conn.get("/v1/me/getwithdrawals", query)
49
+ res.body
50
+ end
51
+
52
+ def my_bank_accounts(count: 100, before: nil, after: nil)
53
+ query = prepare_query(
54
+ count: count,
55
+ before: before,
56
+ after: after
57
+ )
58
+
59
+ res = conn.get("/v1/me/getbankaccounts", query)
60
+ res.body
61
+ end
62
+
63
+ # TODO
64
+ # def withdraw
65
+ # end
66
+ end
67
+ end
@@ -0,0 +1,8 @@
1
+ module BitflyerApi::Methods::Private
2
+ module API
3
+ def my_permissions
4
+ res = conn.get("/v1/me/getpermissions")
5
+ res.body
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ module BitflyerApi::Methods::Private
2
+ module Assets
3
+ def my_balance
4
+ res = conn.get("/v1/me/getbalance")
5
+ res.body
6
+ end
7
+
8
+ def my_collateral
9
+ res = conn.get("/v1/me/getcollateral")
10
+ res.body
11
+ end
12
+
13
+ def my_collateral_accounts
14
+ res = conn.get("/v1/me/getcollateralaccounts")
15
+ res.body
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,277 @@
1
+ module BitflyerApi::Methods::Private
2
+ module Trade
3
+ def my_send_child_order(product_code:, child_order_type:, side:, price: nil, size:,
4
+ minute_to_expire: 43200, time_in_force: "GTC")
5
+
6
+ body = "{
7
+ 'product_code': \"#{product_code}\",
8
+ 'child_order_type': \"#{child_order_type}\",
9
+ 'side': \"#{side}\",
10
+ 'price': #{price},
11
+ 'size': #{size},
12
+ 'minute_to_expire': #{minute_to_expire},
13
+ 'time_in_force': \"#{time_in_force}\"
14
+ }"
15
+
16
+ res = conn.post do |req|
17
+ req.url "/v1/me/sendchildorder"
18
+ req.body = body
19
+ end
20
+
21
+ res.body
22
+ end
23
+
24
+ # TODO: merge child_order_id and child_order_acceptance_id
25
+ def my_cancel_child_order(product_code:, child_order_id: nil, child_order_acceptance_id: nil)
26
+ return unless child_order_id || child_order_acceptance_id
27
+
28
+ body =
29
+ if child_order_id
30
+ "{
31
+ 'product_code': \"#{product_code}\",
32
+ 'child_order_id': \"#{child_order_id}\"
33
+ }"
34
+ elsif child_order_acceptance_id
35
+ "{
36
+ 'product_code': \"#{product_code}\",
37
+ 'child_order_acceptance_id': \"#{child_order_acceptance_id}\"
38
+ }"
39
+ end
40
+
41
+ res = conn.post do |req|
42
+ req.url "/v1/me/cancelchildorder"
43
+ req.body = body
44
+ end
45
+
46
+ res.body
47
+ end
48
+
49
+ def my_cancel_all_child_orders(product_code:)
50
+ body = "{
51
+ 'product_code': \"#{product_code}\"
52
+ }"
53
+
54
+ res = conn.post do |req|
55
+ req.url "/v1/me/cancelallchildorders"
56
+ req.body = body
57
+ end
58
+
59
+ res.body
60
+ end
61
+
62
+ def my_child_orders(product_code:, count: 100, before: nil, after: nil, child_order_state: nil, child_order_id: nil, child_order_acceptance_id: nil, parent_order_id: nil)
63
+ query = prepare_query(
64
+ product_code: product_code,
65
+ count: count,
66
+ before: before,
67
+ after: after,
68
+ child_order_state: child_order_state,
69
+ child_order_id: child_order_id,
70
+ child_order_acceptance_id: child_order_acceptance_id,
71
+ parent_order_id: parent_order_id
72
+ )
73
+
74
+ res = conn.get("/v1/me/getchildorders", query)
75
+ res.body
76
+ end
77
+
78
+ def my_send_parent_order(
79
+ order_method: "SIMPLE",
80
+ minute_to_expire: 43200,
81
+ time_in_force: "GTC",
82
+ product_code:,
83
+ first_condition_type:,
84
+ second_condition_type:,
85
+ third_condition_type: nil,
86
+ first_side:,
87
+ second_side:,
88
+ third_side: nil,
89
+ size:,
90
+ first_price: nil,
91
+ second_price: nil,
92
+ third_price: nil,
93
+ first_trigger_price: nil,
94
+ second_trigger_price: nil,
95
+ third_trigger_price: nil,
96
+ offset: nil
97
+ )
98
+
99
+ body =
100
+ case order_method
101
+ when "IFD"
102
+ "{
103
+ 'order_method': \"#{order_method}\",
104
+ 'minute_to_expire': #{minute_to_expire},
105
+ 'time_in_force': \"#{time_in_force}\",
106
+ 'parameters': [{
107
+ 'product_code': \"#{product_code}\",
108
+ 'condition_type': \"#{first_condition_type}\",
109
+ 'side': \"#{first_side}\",
110
+ 'price': #{first_price},
111
+ 'trigger_price': #{first_trigger_price},
112
+ 'size': #{size}
113
+ },
114
+ {
115
+ 'product_code': \"#{product_code}\",
116
+ 'condition_type': \"#{second_condition_type}\",
117
+ 'side': \"#{second_side}\",
118
+ 'price': #{second_price},
119
+ 'trigger_price': #{second_trigger_price},
120
+ 'size': #{size}
121
+ }]
122
+ }"
123
+ when "OCO"
124
+ "{
125
+ 'order_method': \"#{order_method}\",
126
+ 'minute_to_expire': #{minute_to_expire},
127
+ 'time_in_force': \"#{time_in_force}\",
128
+ 'parameters': [{
129
+ 'product_code': \"#{product_code}\",
130
+ 'condition_type': \"#{first_condition_type}\",
131
+ 'side': \"#{first_side}\",
132
+ 'price': #{first_price},
133
+ 'trigger_price': #{first_trigger_price},
134
+ 'size': #{size}
135
+ },
136
+ {
137
+ 'product_code': \"#{order_method}\",
138
+ 'condition_type': \"#{second_condition_type}\",
139
+ 'side': \"#{second_side}\",
140
+ 'price': #{second_price},
141
+ 'trigger_price': #{second_trigger_price},
142
+ 'size': #{size}
143
+ }]
144
+ }"
145
+ when "IFDOCO"
146
+ "{
147
+ 'order_method': \'#{order_method}\',
148
+ 'minute_to_expire': #{minute_to_expire},
149
+ 'time_in_force': \"#{time_in_force}\",
150
+ 'parameters': [{
151
+ 'product_code': \"#{product_code}\",
152
+ 'condition_type': \"#{first_condition_type}\",
153
+ 'side': \"#{first_side}\",
154
+ 'price': #{first_price},
155
+ 'trigger_price': #{first_trigger_price},
156
+ 'size': #{size}
157
+ },
158
+ {
159
+ 'product_code': \"#{product_code}\",
160
+ 'condition_type': \"#{second_condition_type}\",
161
+ 'side': \"#{second_side}\",
162
+ 'price': #{second_price},
163
+ 'trigger_price': #{second_trigger_price},
164
+ 'size': #{size}
165
+ },
166
+ {
167
+ 'product_code': \"#{product_code}\",
168
+ 'condition_type': \"#{third_condition_type}\",
169
+ 'side': \"#{third_side}\",
170
+ 'price': #{third_price},
171
+ 'trigger_price': #{third_trigger_price},
172
+ 'size': #{size}
173
+ }]
174
+ }"
175
+
176
+ else # SIMPLE
177
+ end
178
+
179
+ res = conn.post do |req|
180
+ req.url "/v1/me/sendparentorder"
181
+ req.body = body
182
+ end
183
+
184
+ res.body
185
+ end
186
+
187
+ def my_parent_orders(product_code:, count: 100, before: nil, after: nil, parent_order_state: nil)
188
+ query = prepare_query(
189
+ product_code: product_code,
190
+ count: count,
191
+ before: before,
192
+ after: after,
193
+ parent_order_state: parent_order_state
194
+ )
195
+
196
+ res = conn.get("/v1/me/getparentorders", query)
197
+ res.body
198
+ end
199
+
200
+ def my_parent_order(parent_order_id: nil, parent_order_acceptance_id: nil)
201
+ return unless parent_order_id || parent_order_acceptance_id
202
+
203
+ query =
204
+ if parent_order_id
205
+ {parent_order_id: parent_order_id}
206
+ else
207
+ {parent_order_acceptance_id: parent_order_acceptance_id}
208
+ end
209
+
210
+ res = conn.get("/v1/me/getparentorder", query)
211
+ res.body
212
+ end
213
+
214
+ def my_cancel_parent_order(product_code:, parent_order_id: nil, parent_order_acceptance_id: nil)
215
+ return unless parent_order_id || parent_order_acceptance_id
216
+
217
+ body =
218
+ if parent_order_id
219
+ "{
220
+ 'product_code': \"#{product_code}\",
221
+ 'parent_order_id': \"#{parent_order_id}\",
222
+ }"
223
+ elsif parent_order_acceptance_id
224
+ "{
225
+ 'product_code': \"#{product_code}\",
226
+ 'parent_order_acceptance_id': \"#{parent_order_acceptance_id}\",
227
+ }"
228
+ end
229
+
230
+ res = conn.post do |req|
231
+ req.url "/v1/me/cancelparentorder"
232
+ req.body = body
233
+ end
234
+
235
+ res.body
236
+ end
237
+
238
+ def my_executions(product_code:, count: 100, before: nil, after: nil, child_order_id: nil, child_order_acceptance_id: nil)
239
+ query = prepare_query(
240
+ product_code: product_code,
241
+ count: count,
242
+ before: before,
243
+ after: after,
244
+ child_order_id: child_order_id,
245
+ child_order_acceptance_id: child_order_acceptance_id
246
+ )
247
+
248
+ res = conn.get("/v1/me/getexecutions", query)
249
+ res.body
250
+ end
251
+
252
+ def my_positions(product_code:)
253
+ query = prepare_query(product_code: product_code)
254
+
255
+ res = conn.get("/v1/me/getpositions", query)
256
+ res.body
257
+ end
258
+
259
+ def my_collateral_history(count: 100, before: nil, after: nil)
260
+ query = prepare_query(
261
+ count: count,
262
+ before: before,
263
+ after: after
264
+ )
265
+
266
+ res = conn.get("/v1/me/getcollateralhistory", query)
267
+ res.body
268
+ end
269
+
270
+ def my_trading_commission(product_code:)
271
+ query = prepare_query(product_code: product_code)
272
+
273
+ res = conn.get("/v1/me/gettradingcommission", query)
274
+ res.body
275
+ end
276
+ end
277
+ end
@@ -0,0 +1,46 @@
1
+ module BitflyerApi
2
+ module Methods
3
+ module Public
4
+ def market
5
+ res = conn.get("/v1/markets")
6
+ res.body
7
+ end
8
+
9
+ def board(product_code:)
10
+ query = prepare_query(product_code: product_code)
11
+ res = conn.get("/v1/board", query)
12
+ res.body
13
+ end
14
+
15
+ def ticker(product_code:)
16
+ query = prepare_query(product_code: product_code)
17
+ res = conn.get("/v1/ticker", query)
18
+ res.body
19
+ end
20
+
21
+ def executions(product_code:, count: 100, before: nil, after: nil)
22
+ query = prepare_query(
23
+ product_code: product_code,
24
+ count: count,
25
+ before: before,
26
+ after: after,
27
+ )
28
+
29
+ res = conn.get("/v1/executions", query)
30
+ res.body
31
+ end
32
+
33
+ def health
34
+ res = conn.get("/v1/gethealth")
35
+ res.body
36
+ end
37
+
38
+ def chat(from_date: nil)
39
+ query = prepare_query(from_date: from_date)
40
+
41
+ res = conn.get("/v1/getchats", query)
42
+ res.body
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module BitflyerApi
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,13 @@
1
+ require "bitflyer_api/version"
2
+ require "bitflyer_api/configuration"
3
+ require "bitflyer_api/client"
4
+ require "active_support"
5
+ require "active_support/core_ext"
6
+
7
+ module BitflyerApi
8
+ extend BitflyerApi::Configuration
9
+
10
+ def self.client
11
+ BitflyerApi::Client.new(key, secret)
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitflyer_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mc-chinju
8
+ - cohki0305
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-11-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.15'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.15'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rubocop
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 0.51.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 0.51.0
70
+ - !ruby/object:Gem::Dependency
71
+ name: pry
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: vcr
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: activesupport
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: faraday
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: faraday_middleware
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ description: Bitflyer api wrapper. see https://lightning.bitflyer.jp/docs
141
+ email:
142
+ - takeiteasy.enjoyeverything@gmail.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - CODE_OF_CONDUCT.md
151
+ - Gemfile
152
+ - Gemfile.lock
153
+ - LICENSE
154
+ - README.md
155
+ - Rakefile
156
+ - bin/console
157
+ - bin/setup
158
+ - bitflyer_api.gemspec
159
+ - lib/bitflyer_api.rb
160
+ - lib/bitflyer_api/client.rb
161
+ - lib/bitflyer_api/configuration.rb
162
+ - lib/bitflyer_api/http/connection.rb
163
+ - lib/bitflyer_api/http/middleware.rb
164
+ - lib/bitflyer_api/methods/private/account_statement.rb
165
+ - lib/bitflyer_api/methods/private/api.rb
166
+ - lib/bitflyer_api/methods/private/assets.rb
167
+ - lib/bitflyer_api/methods/private/trade.rb
168
+ - lib/bitflyer_api/methods/public.rb
169
+ - lib/bitflyer_api/version.rb
170
+ homepage: https://github.com/mc-chinju/bitflyer-api
171
+ licenses:
172
+ - MIT
173
+ metadata: {}
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubyforge_project:
190
+ rubygems_version: 2.6.13
191
+ signing_key:
192
+ specification_version: 4
193
+ summary: Bitflyer api wrapper
194
+ test_files: []