bitmart 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bitmart.gemspec +27 -0
- data/lib/bitmart/api_account.rb +126 -0
- data/lib/bitmart/api_contract.rb +266 -0
- data/lib/bitmart/api_spot.rb +279 -0
- data/lib/bitmart/api_system.rb +37 -0
- data/lib/bitmart/version.rb +3 -0
- data/lib/bitmart.rb +40 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7d877f216e13c3b105328760cc54116b73ff063ed6df11eac597c357e27b8b47
|
4
|
+
data.tar.gz: 7222244da908ebce0b0e070b75b124e55f6a4f436dcfef6897b09450fd317c71
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3cf68b258d1da75414a3ad5c6a943a6df8e24c739224fb6abc04b22ee3781b9c3c17ca2337a293652a8a8311c35af1e8161f784db58ddbe3fee11432dee20fdc
|
7
|
+
data.tar.gz: 98a06eb96f45e2209050849e06ff74d0ef3af7c36512d6cc935574369a0ecd377bdd29300e02a9d5051a5e29444000dd21f731a0aac72d60bc0f780811a76794
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bitmart (0.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
faraday (1.8.0)
|
11
|
+
faraday-em_http (~> 1.0)
|
12
|
+
faraday-em_synchrony (~> 1.0)
|
13
|
+
faraday-excon (~> 1.1)
|
14
|
+
faraday-httpclient (~> 1.0.1)
|
15
|
+
faraday-net_http (~> 1.0)
|
16
|
+
faraday-net_http_persistent (~> 1.1)
|
17
|
+
faraday-patron (~> 1.0)
|
18
|
+
faraday-rack (~> 1.0)
|
19
|
+
multipart-post (>= 1.2, < 3)
|
20
|
+
ruby2_keywords (>= 0.0.4)
|
21
|
+
faraday-em_http (1.0.0)
|
22
|
+
faraday-em_synchrony (1.0.0)
|
23
|
+
faraday-excon (1.1.0)
|
24
|
+
faraday-httpclient (1.0.1)
|
25
|
+
faraday-net_http (1.0.1)
|
26
|
+
faraday-net_http_persistent (1.2.0)
|
27
|
+
faraday-patron (1.0.0)
|
28
|
+
faraday-rack (1.0.0)
|
29
|
+
multipart-post (2.1.1)
|
30
|
+
oj (3.13.10)
|
31
|
+
rake (12.3.3)
|
32
|
+
rspec (3.10.0)
|
33
|
+
rspec-core (~> 3.10.0)
|
34
|
+
rspec-expectations (~> 3.10.0)
|
35
|
+
rspec-mocks (~> 3.10.0)
|
36
|
+
rspec-core (3.10.1)
|
37
|
+
rspec-support (~> 3.10.0)
|
38
|
+
rspec-expectations (3.10.1)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.10.0)
|
41
|
+
rspec-mocks (3.10.2)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.10.0)
|
44
|
+
rspec-support (3.10.3)
|
45
|
+
ruby2_keywords (0.0.5)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
bitmart!
|
52
|
+
faraday
|
53
|
+
oj
|
54
|
+
rake (~> 12.0)
|
55
|
+
rspec (~> 3.0)
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Michael Bastos
|
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,40 @@
|
|
1
|
+
# Bitmart
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bitmart`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'bitmart'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install bitmart
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bitmart.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bitmart"
|
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
data/bitmart.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'lib/bitmart/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "bitmart"
|
5
|
+
spec.version = Bitmart::VERSION
|
6
|
+
spec.authors = ["Michael Bastos"]
|
7
|
+
spec.email = ["bastosmichael@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "Ruby client for the BitMart API"
|
10
|
+
spec.description = "Ruby client for the BitMart Cloud API - http://developer-pro.bitmart.com. Features include Providing exchange quick trading API, Easier withdrawal, Efficiency, higher speeds, and lower latencies, Priority in development and maintenance, Dedicated and responsive technical support & Provide webSocket apis calls"
|
11
|
+
spec.homepage = "https://github.com/bastosmichael/bitmart-ruby-sdk-api"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/bastosmichael/bitmart-ruby-sdk-api"
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/bastosmichael/bitmart-ruby-sdk-api"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module Bitmart
|
2
|
+
module API
|
3
|
+
module V1
|
4
|
+
class Account
|
5
|
+
API_ENDPOINT = 'https://api-cloud.bitmart.com/account/v1'.freeze
|
6
|
+
|
7
|
+
attr_reader :api_key
|
8
|
+
attr_reader :api_sign
|
9
|
+
attr_reader :api_memo
|
10
|
+
|
11
|
+
def initialize(api_key = nil, api_signature = nil, api_memo = nil)
|
12
|
+
@api_key = api_key
|
13
|
+
@api_sign = api_sign
|
14
|
+
@api_memo = api_memo
|
15
|
+
end
|
16
|
+
|
17
|
+
# GET https://api-cloud.bitmart.com/account/v1/currencies
|
18
|
+
def get_currencies
|
19
|
+
request(
|
20
|
+
http_method: :get,
|
21
|
+
endpoint: "currencies"
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
# GET https://api-cloud.bitmart.com/account/v1/wallet
|
26
|
+
def get_wallet(accountType)
|
27
|
+
params = {
|
28
|
+
'account_type': accountType
|
29
|
+
}
|
30
|
+
request(
|
31
|
+
http_method: :get,
|
32
|
+
endpoint: "wallet",
|
33
|
+
params: params
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
# GET https://api-cloud.bitmart.com/account/v1/deposit/address
|
38
|
+
def get_deposit_address(currency)
|
39
|
+
params = {
|
40
|
+
'currency': currency
|
41
|
+
}
|
42
|
+
request(
|
43
|
+
http_method: :get,
|
44
|
+
endpoint: "wallet",
|
45
|
+
params: params
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
# GET https://api-cloud.bitmart.com/account/v1/withdraw/charge
|
50
|
+
def get_withdraw_charge(currency)
|
51
|
+
params = {
|
52
|
+
'currency': currency
|
53
|
+
}
|
54
|
+
request(
|
55
|
+
http_method: :get,
|
56
|
+
endpoint: "withdraw/charge",
|
57
|
+
params: params
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
# POST https://api-cloud.bitmart.com/account/v1/withdraw/apply
|
62
|
+
def post_withdraw_apply(currency, amount, destination, address, address_memo)
|
63
|
+
params = {
|
64
|
+
'currency': currency,
|
65
|
+
'amount': amount,
|
66
|
+
'destination': destination,
|
67
|
+
'address': address,
|
68
|
+
'address_memo': address_memo
|
69
|
+
}
|
70
|
+
request(
|
71
|
+
http_method: :post,
|
72
|
+
endpoint: "withdraw/apply",
|
73
|
+
params: params
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
# GET https://api-cloud.bitmart.com/account/v1/deposit-withdraw/history
|
78
|
+
def get_deposit_withdraw_history(currency, operationType, offset, limit)
|
79
|
+
params = {
|
80
|
+
'currency': currency,
|
81
|
+
'operation_type': operationType,
|
82
|
+
'offset': offset,
|
83
|
+
'limit': limit
|
84
|
+
}
|
85
|
+
request(
|
86
|
+
http_method: :get,
|
87
|
+
endpoint: "deposit-withdraw/history",
|
88
|
+
params: params
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
# GET https://api-cloud.bitmart.com/account/v1/deposit-withdraw/detail
|
93
|
+
def get_deposit_withdraw_detail(id)
|
94
|
+
params = {
|
95
|
+
'id': id
|
96
|
+
}
|
97
|
+
request(
|
98
|
+
http_method: :get,
|
99
|
+
endpoint: "deposit-withdraw/detail",
|
100
|
+
params: params
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def client
|
107
|
+
@_client ||= Faraday.new(API_ENDPOINT) do |client|
|
108
|
+
client.request :url_encoded
|
109
|
+
client.adapter Faraday.default_adapter
|
110
|
+
timestamp = Time.now.getutc.to_i.to_s
|
111
|
+
signature = [timestamp,"#",api_memo,"#",client.params.to_s].join if api_memo&.present?
|
112
|
+
signed = OpenSSL::HMAC.hexdigest("SHA256", signature, api_sign) if signature
|
113
|
+
client.headers['X-BM-KEY'] = api_key if api_key&.present?
|
114
|
+
client.headers['X-BM-SIGN'] = signed if signed&.present?
|
115
|
+
client.headers['X-BM-TIMESTAMP'] = timestamp
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def request(http_method:, endpoint:, params: {})
|
120
|
+
response = client.public_send(http_method, endpoint, params)
|
121
|
+
Oj.load(response.body)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,266 @@
|
|
1
|
+
module Bitmart
|
2
|
+
module API
|
3
|
+
module V1
|
4
|
+
class Contract
|
5
|
+
API_ENDPOINT = 'https://api-cloud.bitmart.com/contract/v1'.freeze
|
6
|
+
|
7
|
+
attr_reader :api_key
|
8
|
+
attr_reader :api_sign
|
9
|
+
attr_reader :api_memo
|
10
|
+
|
11
|
+
def initialize(api_key = nil, api_signature = nil, api_memo = nil)
|
12
|
+
@api_key = api_key
|
13
|
+
@api_sign = api_sign
|
14
|
+
@api_memo = api_memo
|
15
|
+
end
|
16
|
+
|
17
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/contracts
|
18
|
+
def get_contracts
|
19
|
+
params = {'exchange': 'bitmart'}
|
20
|
+
request(
|
21
|
+
http_method: :get,
|
22
|
+
endpoint: "ifcontract/contracts",
|
23
|
+
params: params
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/pnls
|
28
|
+
def get_pnls(contractId)
|
29
|
+
params = {'contractID': contractId}
|
30
|
+
request(
|
31
|
+
http_method: :get,
|
32
|
+
endpoint: "ifcontract/pnls",
|
33
|
+
params: params
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/indexes
|
38
|
+
def get_indexes
|
39
|
+
request(
|
40
|
+
http_method: :get,
|
41
|
+
endpoint: "ifcontract/indexes",
|
42
|
+
params: params
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/tickers
|
47
|
+
def get_tickers(contractId)
|
48
|
+
params = {}
|
49
|
+
params = {'contractID': contractId} if contractId
|
50
|
+
request(
|
51
|
+
http_method: :get,
|
52
|
+
endpoint: "ifcontract/tickers",
|
53
|
+
params: params
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/quote
|
58
|
+
def get_quote(contractId, startTime, endTime, unit, resolution)
|
59
|
+
params = {'contractID': contractId, 'startTime': startTime, 'endTime': endTime, 'unit': unit, 'resolution': resolution}
|
60
|
+
request(
|
61
|
+
http_method: :get,
|
62
|
+
endpoint: "ifcontract/quote",
|
63
|
+
params: params
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/indexquote
|
68
|
+
def get_index_quote(indexId, startTime, endTime, unit, resolution)
|
69
|
+
params = {'indexID': indexId, 'startTime': startTime, 'endTime': endTime, 'unit': unit, 'resolution': resolution}
|
70
|
+
request(
|
71
|
+
http_method: :get,
|
72
|
+
endpoint: "ifcontract/indexquote",
|
73
|
+
params: params
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/trades
|
78
|
+
def get_trades(contractId)
|
79
|
+
params = {'contractID': contractId}
|
80
|
+
request(
|
81
|
+
http_method: :get,
|
82
|
+
endpoint: "ifcontract/trades",
|
83
|
+
params: params
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/depth
|
88
|
+
def get_depth(contractId, count)
|
89
|
+
params = {'contractID': contractId}
|
90
|
+
param['count'] = count if count
|
91
|
+
request(
|
92
|
+
http_method: :get,
|
93
|
+
endpoint: "ifcontract/depth",
|
94
|
+
params: params
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/fundingrate
|
99
|
+
def get_funding_rate(contractId)
|
100
|
+
params = {'contractID': contractId}
|
101
|
+
request(
|
102
|
+
http_method: :get,
|
103
|
+
endpoint: "ifcontract/fundingrate",
|
104
|
+
params: params
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Order API
|
109
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/userOrders
|
110
|
+
def get_user_orders(contractId, status, offset = nil, size = nil)
|
111
|
+
params = {'contractID': contractId, 'status': status}
|
112
|
+
if offset && size
|
113
|
+
params['offset'] = offset
|
114
|
+
params['size'] = size
|
115
|
+
end
|
116
|
+
request(
|
117
|
+
http_method: :get,
|
118
|
+
endpoint: "ifcontract/userOrders",
|
119
|
+
params: params
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/userOrderInfo
|
124
|
+
def get_user_order_info(contractId, orderId)
|
125
|
+
params = {'contractID': contractId, 'orderID': orderId}
|
126
|
+
request(
|
127
|
+
http_method: :get,
|
128
|
+
endpoint: "ifcontract/userOrderInfo",
|
129
|
+
params: params
|
130
|
+
)
|
131
|
+
end
|
132
|
+
|
133
|
+
# POST https://api-cloud.bitmart.com/contract/v1/ifcontract/submitOrder
|
134
|
+
def post_submit_order(contractId, category, way, openType, leverage, customId, price, vol)
|
135
|
+
params = {
|
136
|
+
'contract_id': contractId,
|
137
|
+
'category': category,
|
138
|
+
'way': way,
|
139
|
+
'open_type': openType,
|
140
|
+
'leverage': leverage,
|
141
|
+
'custom_id': customId,
|
142
|
+
'price': price,
|
143
|
+
'vol': vol
|
144
|
+
}
|
145
|
+
request(
|
146
|
+
http_method: :post,
|
147
|
+
endpoint: "ifcontract/submitOrder",
|
148
|
+
params: params
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
# POST https://api-cloud.bitmart.com/contract/v1/ifcontract/batchOrders
|
153
|
+
def post_submit_batch_order(orders)
|
154
|
+
params = {'orders': orders}
|
155
|
+
request(
|
156
|
+
http_method: :get,
|
157
|
+
endpoint: "ifcontract/batchOrders",
|
158
|
+
params: params
|
159
|
+
)
|
160
|
+
end
|
161
|
+
|
162
|
+
# POST https://api-cloud.bitmart.com/contract/v1/ifcontract/cancelOrders
|
163
|
+
def post_cancel_order(contractId, orders)
|
164
|
+
params = {'contractID': contractId, 'orders': orders}
|
165
|
+
request(
|
166
|
+
http_method: :get,
|
167
|
+
endpoint: "ifcontract/cancelOrders",
|
168
|
+
params: params
|
169
|
+
)
|
170
|
+
end
|
171
|
+
|
172
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/userTrades
|
173
|
+
def get_user_trades(contractId, offset, size)
|
174
|
+
params = {'contractID': contractId}
|
175
|
+
params['offset'] = offset if offset
|
176
|
+
params['size'] = size if size
|
177
|
+
request(
|
178
|
+
http_method: :get,
|
179
|
+
endpoint: "ifcontract/userTrades",
|
180
|
+
params: params
|
181
|
+
)
|
182
|
+
end
|
183
|
+
|
184
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/orderTrades
|
185
|
+
def get_order_trades(contractId, orderId)
|
186
|
+
params = {'contractID': contractId, 'orderID': orderId}
|
187
|
+
request(
|
188
|
+
http_method: :get,
|
189
|
+
endpoint: "ifcontract/orderTrades",
|
190
|
+
params: params
|
191
|
+
)
|
192
|
+
end
|
193
|
+
|
194
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/accounts
|
195
|
+
def get_accounts(coinCode)
|
196
|
+
params = {'coinCode': coinCode}
|
197
|
+
request(
|
198
|
+
http_method: :get,
|
199
|
+
endpoint: "ifcontract/userOrders",
|
200
|
+
params: params
|
201
|
+
)
|
202
|
+
end
|
203
|
+
|
204
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/userPositions
|
205
|
+
def get_user_positions(contractId)
|
206
|
+
params = {'contractID': contractId}
|
207
|
+
request(
|
208
|
+
http_method: :get,
|
209
|
+
endpoint: "ifcontract/userPositions",
|
210
|
+
params: params
|
211
|
+
)
|
212
|
+
end
|
213
|
+
|
214
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/userLiqRecords
|
215
|
+
def get_user_liq_records(contractId, orderId)
|
216
|
+
params = {'contractID': contractId, 'orderID': orderId}
|
217
|
+
request(
|
218
|
+
http_method: :get,
|
219
|
+
endpoint: "ifcontract/userLiqRecords",
|
220
|
+
params: params
|
221
|
+
)
|
222
|
+
end
|
223
|
+
|
224
|
+
# GET https://api-cloud.bitmart.com/contract/v1/ifcontract/positionFee
|
225
|
+
def get_position_fee(contractId, positionId)
|
226
|
+
params = {'contractID': contractId, 'positionID': positionId}
|
227
|
+
request(
|
228
|
+
http_method: :get,
|
229
|
+
endpoint: "ifcontract/positionFee",
|
230
|
+
params: params
|
231
|
+
)
|
232
|
+
end
|
233
|
+
|
234
|
+
# POST https://api-cloud.bitmart.com/contract/v1/ifcontract/marginOper
|
235
|
+
def post_margin_oper(contractId, positionId, vol, operType)
|
236
|
+
params = {'contract_id': contractId, 'position_id': positionId, 'vol': vol, 'oper_type': operType}
|
237
|
+
request(
|
238
|
+
http_method: :post,
|
239
|
+
endpoint: "ifcontract/marginOper",
|
240
|
+
params: params
|
241
|
+
)
|
242
|
+
end
|
243
|
+
|
244
|
+
private
|
245
|
+
|
246
|
+
def client
|
247
|
+
@_client ||= Faraday.new(API_ENDPOINT) do |client|
|
248
|
+
client.request :url_encoded
|
249
|
+
client.adapter Faraday.default_adapter
|
250
|
+
timestamp = Time.now.getutc.to_i.to_s
|
251
|
+
signature = [timestamp,"#",api_memo,"#",client.params.to_s].join if api_memo&.present?
|
252
|
+
signed = OpenSSL::HMAC.hexdigest("SHA256", signature, api_sign) if signature
|
253
|
+
client.headers['X-BM-KEY'] = api_key if api_key&.present?
|
254
|
+
client.headers['X-BM-SIGN'] = signed if signed&.present?
|
255
|
+
client.headers['X-BM-TIMESTAMP'] = timestamp
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
def request(http_method:, endpoint:, params: {})
|
260
|
+
response = client.public_send(http_method, endpoint, params)
|
261
|
+
Oj.load(response.body)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
@@ -0,0 +1,279 @@
|
|
1
|
+
module Bitmart
|
2
|
+
module API
|
3
|
+
module V1
|
4
|
+
class Spot
|
5
|
+
API_ENDPOINT = 'https://api-cloud.bitmart.com/spot/v1'.freeze
|
6
|
+
|
7
|
+
attr_reader :api_key
|
8
|
+
attr_reader :api_sign
|
9
|
+
attr_reader :api_memo
|
10
|
+
|
11
|
+
def initialize(api_key = nil, api_signature = nil, api_memo = nil)
|
12
|
+
@api_key = api_key
|
13
|
+
@api_sign = api_sign
|
14
|
+
@api_memo = api_memo
|
15
|
+
end
|
16
|
+
|
17
|
+
# basic API
|
18
|
+
# GET https://api-cloud.bitmart.com/spot/v1/currencies
|
19
|
+
def get_currencies
|
20
|
+
request(
|
21
|
+
http_method: :get,
|
22
|
+
endpoint: "currencies"
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
# GET https://api-cloud.bitmart.com/spot/v1/symbols
|
27
|
+
def get_symbols
|
28
|
+
request(
|
29
|
+
http_method: :get,
|
30
|
+
endpoint: "symbols"
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
# GET https://api-cloud.bitmart.com/spot/v1/symbols/details
|
35
|
+
def get_symbol_detail
|
36
|
+
request(
|
37
|
+
http_method: :get,
|
38
|
+
endpoint: "symboles/details"
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
# GET https://api-cloud.bitmart.com/spot/v1/ticker
|
43
|
+
def get_ticker
|
44
|
+
request(
|
45
|
+
http_method: :get,
|
46
|
+
endpoint: "ticker"
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_symbol_ticker(symbol)
|
51
|
+
params = {'symbol': symbol}
|
52
|
+
request(
|
53
|
+
http_method: :get,
|
54
|
+
endpoint: "ticker",
|
55
|
+
params: params
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
# GET https://api-cloud.bitmart.com/spot/v1/steps
|
60
|
+
def get_steps
|
61
|
+
request(
|
62
|
+
http_method: :get,
|
63
|
+
endpoint: "steps"
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
# GET https://api-cloud.bitmart.com/spot/v1/symbols/kline
|
68
|
+
def get_symbol_kline(symbol, fromTime, toTime, step = 1)
|
69
|
+
params = {
|
70
|
+
'symbol': symbol,
|
71
|
+
'from': fromTime,
|
72
|
+
'to': toTime,
|
73
|
+
'step': step
|
74
|
+
}
|
75
|
+
request(
|
76
|
+
http_method: :get,
|
77
|
+
endpoint: "symboles/kline",
|
78
|
+
params: params
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
# GET https://api-cloud.bitmart.com/spot/v1/symbols/book
|
83
|
+
def get_symbol_book(symbol, precision, size)
|
84
|
+
params = {
|
85
|
+
'symbol': symbol
|
86
|
+
}
|
87
|
+
param['precision'] = precision if precision
|
88
|
+
param['size'] = size if size
|
89
|
+
request(
|
90
|
+
http_method: :get,
|
91
|
+
endpoint: "symbols/book",
|
92
|
+
params: params
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
# GET https://api-cloud.bitmart.com/spot/v1/symbols/trades
|
97
|
+
def get_symbol_trades(symbol)
|
98
|
+
params = {
|
99
|
+
'symbol': symbol
|
100
|
+
}
|
101
|
+
request(
|
102
|
+
http_method: :get,
|
103
|
+
endpoint: "symbols/trades",
|
104
|
+
params: params
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
# trade API
|
109
|
+
|
110
|
+
# GET https://api-cloud.bitmart.com/spot/v1/wallet
|
111
|
+
def get_wallet
|
112
|
+
request(
|
113
|
+
http_method: :get,
|
114
|
+
endpoint: "wallet"
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
# POST https://api-cloud.bitmart.com/spot/v1/submit_order
|
119
|
+
def post_submit_limit_buy_order(symbol, size='', price='')
|
120
|
+
params = {
|
121
|
+
'symbol': symbol,
|
122
|
+
'side': 'buy',
|
123
|
+
'type': 'limit',
|
124
|
+
'size': size,
|
125
|
+
'price': price
|
126
|
+
}
|
127
|
+
request(
|
128
|
+
http_method: :post,
|
129
|
+
endpoint: "submit_order",
|
130
|
+
params: params
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
def post_submit_limit_sell_order(symbol, size='', price='')
|
135
|
+
params = {
|
136
|
+
'symbol': symbol,
|
137
|
+
'side': 'sell',
|
138
|
+
'type': 'limit',
|
139
|
+
'size': size,
|
140
|
+
'price': price
|
141
|
+
}
|
142
|
+
request(
|
143
|
+
http_method: :post,
|
144
|
+
endpoint: "submit_order",
|
145
|
+
params: params
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
149
|
+
def post_submit_market_sell_order(symbol, size='')
|
150
|
+
params = {
|
151
|
+
'symbol': symbol,
|
152
|
+
'side': 'sell',
|
153
|
+
'type': 'market',
|
154
|
+
'size': size
|
155
|
+
}
|
156
|
+
request(
|
157
|
+
http_method: :post,
|
158
|
+
endpoint: "submit_order",
|
159
|
+
params: params
|
160
|
+
)
|
161
|
+
end
|
162
|
+
|
163
|
+
def post_submit_market_buy_order(symbol, notional='')
|
164
|
+
params = {
|
165
|
+
'symbol': symbol,
|
166
|
+
'side': 'buy',
|
167
|
+
'type': 'market',
|
168
|
+
'notional': notional
|
169
|
+
}
|
170
|
+
request(
|
171
|
+
http_method: :post,
|
172
|
+
endpoint: "submit_order",
|
173
|
+
params: params
|
174
|
+
)
|
175
|
+
end
|
176
|
+
|
177
|
+
# POST https://api-cloud.bitmart.com/spot/v2/cancel_order
|
178
|
+
def post_cancel_order(symbol, orderId)
|
179
|
+
params = {
|
180
|
+
'symbol': symbol,
|
181
|
+
'order_id': orderId
|
182
|
+
}
|
183
|
+
request(
|
184
|
+
http_method: :post,
|
185
|
+
endpoint: "cancel_order",
|
186
|
+
params: params
|
187
|
+
)
|
188
|
+
end
|
189
|
+
|
190
|
+
# POST https://api-cloud.bitmart.com/spot/v1/cancel_orders
|
191
|
+
def post_cancel_orders(symbol, side)
|
192
|
+
params = {
|
193
|
+
'symbol': symbol,
|
194
|
+
'side': side
|
195
|
+
}
|
196
|
+
request(
|
197
|
+
http_method: :post,
|
198
|
+
endpoint: "cancel_orders",
|
199
|
+
params: params
|
200
|
+
)
|
201
|
+
end
|
202
|
+
|
203
|
+
# GET https://api-cloud.bitmart.com/spot/v1/order_detail
|
204
|
+
def get_user_order_detail(symbol, orderId)
|
205
|
+
params = {
|
206
|
+
'symbol': symbol,
|
207
|
+
'order_id': orderId
|
208
|
+
}
|
209
|
+
request(
|
210
|
+
http_method: :get,
|
211
|
+
endpoint: "order_detail",
|
212
|
+
params: params
|
213
|
+
)
|
214
|
+
end
|
215
|
+
|
216
|
+
# GET https://api-cloud.bitmart.com/spot/v1/orders
|
217
|
+
def get_user_orders(symbol, offset, limit, status)
|
218
|
+
params = {
|
219
|
+
'symbol': symbol,
|
220
|
+
'offset': offset,
|
221
|
+
'limit': limit,
|
222
|
+
'status': status
|
223
|
+
}
|
224
|
+
request(
|
225
|
+
http_method: :get,
|
226
|
+
endpoint: "orders",
|
227
|
+
params: params
|
228
|
+
)
|
229
|
+
end
|
230
|
+
|
231
|
+
# GET https://api-cloud.bitmart.com/spot/v1/trades
|
232
|
+
def get_user_order_trades(symbol, orderId)
|
233
|
+
params = {
|
234
|
+
'symbol': symbol,
|
235
|
+
'order_id': orderId
|
236
|
+
}
|
237
|
+
request(
|
238
|
+
http_method: :get,
|
239
|
+
endpoint: "trades",
|
240
|
+
params: params
|
241
|
+
)
|
242
|
+
end
|
243
|
+
|
244
|
+
def get_user_trades(symbol, offset, limit)
|
245
|
+
params = {
|
246
|
+
'symbol': symbol,
|
247
|
+
'offset': offset,
|
248
|
+
'limit': limit
|
249
|
+
}
|
250
|
+
request(
|
251
|
+
http_method: :get,
|
252
|
+
endpoint: "trades",
|
253
|
+
params: params
|
254
|
+
)
|
255
|
+
end
|
256
|
+
|
257
|
+
private
|
258
|
+
|
259
|
+
def client
|
260
|
+
@_client ||= Faraday.new(API_ENDPOINT) do |client|
|
261
|
+
client.request :url_encoded
|
262
|
+
client.adapter Faraday.default_adapter
|
263
|
+
timestamp = Time.now.getutc.to_i.to_s
|
264
|
+
signature = [timestamp,"#",api_memo,"#",client.params.to_s].join if api_memo&.present?
|
265
|
+
signed = OpenSSL::HMAC.hexdigest("SHA256", signature, api_sign) if signature
|
266
|
+
client.headers['X-BM-KEY'] = api_key if api_key&.present?
|
267
|
+
client.headers['X-BM-SIGN'] = signed if signed&.present?
|
268
|
+
client.headers['X-BM-TIMESTAMP'] = timestamp
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
def request(http_method:, endpoint:, params: {})
|
273
|
+
response = client.public_send(http_method, endpoint, params)
|
274
|
+
Oj.load(response.body)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Bitmart
|
2
|
+
module API
|
3
|
+
class System
|
4
|
+
API_ENDPOINT = 'https://api-cloud.bitmart.com/system'.freeze
|
5
|
+
|
6
|
+
# get system time
|
7
|
+
def get_system_time
|
8
|
+
request(
|
9
|
+
http_method: :get,
|
10
|
+
endpoint: "time"
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
# get system service
|
15
|
+
def get_system_service
|
16
|
+
request(
|
17
|
+
http_method: :get,
|
18
|
+
endpoint: "service"
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def client
|
25
|
+
@_client ||= Faraday.new(API_ENDPOINT) do |client|
|
26
|
+
client.request :url_encoded
|
27
|
+
client.adapter Faraday.default_adapter
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def request(http_method:, endpoint:, params: {})
|
32
|
+
response = client.public_send(http_method, endpoint, params)
|
33
|
+
Oj.load(response.body)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/bitmart.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "oj"
|
3
|
+
require "bitmart/version"
|
4
|
+
require "bitmart/api_account"
|
5
|
+
require "bitmart/api_contract"
|
6
|
+
require "bitmart/api_spot"
|
7
|
+
require "bitmart/api_system"
|
8
|
+
|
9
|
+
module Bitmart
|
10
|
+
class Error < StandardError; end
|
11
|
+
class Client
|
12
|
+
attr_reader :api_key
|
13
|
+
attr_reader :api_sign
|
14
|
+
attr_reader :api_memo
|
15
|
+
|
16
|
+
def initialize(api_key = nil, api_signature = nil, api_memo = nil)
|
17
|
+
@api_key = api_key
|
18
|
+
@api_sign = api_sign
|
19
|
+
@api_memo = api_memo
|
20
|
+
end
|
21
|
+
|
22
|
+
def client
|
23
|
+
@_client ||= Faraday.new(API_ENDPOINT) do |client|
|
24
|
+
client.request :url_encoded
|
25
|
+
client.adapter Faraday.default_adapter
|
26
|
+
timestamp = Time.now.getutc.to_i.to_s
|
27
|
+
signature = [timestamp,"#",api_memo,"#",client.params.to_s].join if api_memo&.present?
|
28
|
+
signed = OpenSSL::HMAC.hexdigest("SHA256", signature, api_sign) if signature
|
29
|
+
client.headers['X-BM-KEY'] = api_key if api_key&.present?
|
30
|
+
client.headers['X-BM-SIGN'] = signed if signed&.present?
|
31
|
+
client.headers['X-BM-TIMESTAMP'] = timestamp
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def request(http_method:, endpoint:, params: {})
|
36
|
+
response = client.public_send(http_method, endpoint, params)
|
37
|
+
Oj.load(response.body)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bitmart
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Bastos
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby client for the BitMart Cloud API - http://developer-pro.bitmart.com.
|
14
|
+
Features include Providing exchange quick trading API, Easier withdrawal, Efficiency,
|
15
|
+
higher speeds, and lower latencies, Priority in development and maintenance, Dedicated
|
16
|
+
and responsive technical support & Provide webSocket apis calls
|
17
|
+
email:
|
18
|
+
- bastosmichael@gmail.com
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- ".gitignore"
|
24
|
+
- ".rspec"
|
25
|
+
- ".travis.yml"
|
26
|
+
- Gemfile
|
27
|
+
- Gemfile.lock
|
28
|
+
- LICENSE.txt
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- bin/console
|
32
|
+
- bin/setup
|
33
|
+
- bitmart.gemspec
|
34
|
+
- lib/bitmart.rb
|
35
|
+
- lib/bitmart/api_account.rb
|
36
|
+
- lib/bitmart/api_contract.rb
|
37
|
+
- lib/bitmart/api_spot.rb
|
38
|
+
- lib/bitmart/api_system.rb
|
39
|
+
- lib/bitmart/version.rb
|
40
|
+
homepage: https://github.com/bastosmichael/bitmart-ruby-sdk-api
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata:
|
44
|
+
homepage_uri: https://github.com/bastosmichael/bitmart-ruby-sdk-api
|
45
|
+
source_code_uri: https://github.com/bastosmichael/bitmart-ruby-sdk-api
|
46
|
+
changelog_uri: https://github.com/bastosmichael/bitmart-ruby-sdk-api
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.3.0
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubygems_version: 3.1.2
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Ruby client for the BitMart API
|
66
|
+
test_files: []
|