bitget.rb 0.3.1 → 0.5.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 +4 -4
- data/README.md +17 -2
- data/bitget.rb.gemspec +1 -1
- data/lib/Bitget/V2/Client.rb +1824 -33
- data/lib/Bitget/VERSiON.rb +1 -1
- data/lib/bitget.rb +0 -4
- data/test/V2/client_logging_test.rb +92 -0
- data/test/V2/client_test.rb +1110 -14
- data/test/client_test.rb +176 -31
- data/test/helper.rb +3 -24
- metadata +4 -4
- data/lib/Hash/to_parameter_string.rb +0 -26
data/test/client_test.rb
CHANGED
|
@@ -4,49 +4,194 @@ require_relative '../lib/Bitget/Client'
|
|
|
4
4
|
describe Bitget::Client do
|
|
5
5
|
let(:client) do
|
|
6
6
|
Bitget::Client.new(
|
|
7
|
-
api_key:
|
|
8
|
-
api_secret:
|
|
9
|
-
api_passphrase:
|
|
7
|
+
api_key: ENV.fetch('BITGET_API_KEY', '<API_KEY>'),
|
|
8
|
+
api_secret: ENV.fetch('BITGET_API_SECRET', '<API_SECRET>'),
|
|
9
|
+
api_passphrase: ENV.fetch('BITGET_API_PASSPHRASE', '<API_PASSPHRASE>')
|
|
10
10
|
)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
# Market
|
|
14
|
+
|
|
15
|
+
%w[
|
|
16
|
+
spot_public_coins
|
|
17
|
+
spot_public_symbols
|
|
18
|
+
spot_market_vip_free_rate
|
|
19
|
+
spot_market_tickers
|
|
20
|
+
spot_market_merge_depth
|
|
21
|
+
spot_market_orderbook
|
|
22
|
+
spot_market_candles
|
|
23
|
+
spot_market_history_candles
|
|
24
|
+
spot_market_fills
|
|
25
|
+
spot_market_fills_history
|
|
26
|
+
].each do |method|
|
|
27
|
+
describe "##{method}" do
|
|
28
|
+
it "delegates to V2::Client" do
|
|
29
|
+
mock_v2_client = Minitest::Mock.new
|
|
30
|
+
client.instance_variable_set(:@v2_client, mock_v2_client)
|
|
31
|
+
|
|
32
|
+
args = case method
|
|
33
|
+
when 'spot_market_merge_depth', 'spot_market_orderbook'
|
|
34
|
+
{symbol: 'BTCUSDT'}
|
|
35
|
+
when 'spot_market_candles', 'spot_market_history_candles'
|
|
36
|
+
{symbol: 'BTCUSDT', granularity: '1min'}
|
|
37
|
+
when 'spot_market_fills', 'spot_market_fills_history'
|
|
38
|
+
{symbol: 'BTCUSDT'}
|
|
39
|
+
else
|
|
40
|
+
{}
|
|
22
41
|
end
|
|
42
|
+
|
|
43
|
+
mock_v2_client.expect(method.to_sym, nil, [args])
|
|
44
|
+
client.send(method, **args)
|
|
45
|
+
mock_v2_client.verify
|
|
23
46
|
end
|
|
24
47
|
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Trade
|
|
25
51
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
52
|
+
%w[
|
|
53
|
+
spot_trade_place_order
|
|
54
|
+
spot_trade_cancel_replace_order
|
|
55
|
+
spot_trade_batch_cancel_replace_order
|
|
56
|
+
spot_trade_cancel_order
|
|
57
|
+
spot_trade_batch_orders
|
|
58
|
+
spot_trade_batch_cancel_order
|
|
59
|
+
spot_trade_cancel_symbol_order
|
|
60
|
+
spot_trade_order_info
|
|
61
|
+
spot_trade_unfilled_orders
|
|
62
|
+
spot_trade_history_orders
|
|
63
|
+
spot_trade_fills
|
|
64
|
+
].each do |method|
|
|
65
|
+
describe "##{method}" do
|
|
66
|
+
it "delegates to V2::Client" do
|
|
67
|
+
mock_v2_client = Minitest::Mock.new
|
|
68
|
+
client.instance_variable_set(:@v2_client, mock_v2_client)
|
|
69
|
+
|
|
70
|
+
args = case method
|
|
71
|
+
when 'spot_trade_place_order'
|
|
72
|
+
{
|
|
73
|
+
symbol: 'BTCUSDT',
|
|
74
|
+
side: 'buy',
|
|
75
|
+
order_type: 'limit',
|
|
76
|
+
force: 'normal',
|
|
77
|
+
size: '0.001',
|
|
78
|
+
price: '30000'
|
|
79
|
+
}
|
|
80
|
+
when /cancel|modify|info/
|
|
81
|
+
{symbol: 'BTCUSDT', order_id: '123456'}
|
|
82
|
+
when /batch/
|
|
83
|
+
{symbol: 'BTCUSDT', order_ids: ['123', '456']}
|
|
84
|
+
else
|
|
85
|
+
{symbol: 'BTCUSDT'}
|
|
34
86
|
end
|
|
87
|
+
|
|
88
|
+
mock_v2_client.expect(method.to_sym, nil, [args])
|
|
89
|
+
client.send(method, **args)
|
|
90
|
+
mock_v2_client.verify
|
|
35
91
|
end
|
|
36
92
|
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Trigger
|
|
96
|
+
|
|
97
|
+
%w[
|
|
98
|
+
spot_trade_place_plan_order
|
|
99
|
+
spot_trade_modify_plan_order
|
|
100
|
+
spot_trade_cancel_plan_order
|
|
101
|
+
spot_trade_current_plan_order
|
|
102
|
+
spot_trade_plan_sub_order
|
|
103
|
+
spot_trade_history_plan_order
|
|
104
|
+
spot_trade_batch_cancel_plan_order
|
|
105
|
+
].each do |method|
|
|
106
|
+
describe "##{method}" do
|
|
107
|
+
it "delegates to V2::Client" do
|
|
108
|
+
mock_v2_client = Minitest::Mock.new
|
|
109
|
+
client.instance_variable_set(:@v2_client, mock_v2_client)
|
|
37
110
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
111
|
+
args = case method
|
|
112
|
+
when 'spot_trade_place_plan_order'
|
|
113
|
+
{
|
|
114
|
+
symbol: 'BTCUSDT',
|
|
115
|
+
side: 'buy',
|
|
116
|
+
order_type: 'limit',
|
|
117
|
+
size: '0.001',
|
|
118
|
+
trigger_price: '31000',
|
|
119
|
+
execute_price: '30000'
|
|
120
|
+
}
|
|
121
|
+
when 'spot_trade_modify_plan_order'
|
|
122
|
+
{
|
|
123
|
+
order_id: '123456',
|
|
124
|
+
trigger_price: '31000',
|
|
125
|
+
execute_price: '30000',
|
|
126
|
+
size: '0.001'
|
|
127
|
+
}
|
|
128
|
+
when 'spot_trade_cancel_plan_order'
|
|
129
|
+
{order_id: '123456'}
|
|
130
|
+
when 'spot_trade_plan_sub_order'
|
|
131
|
+
{order_id: '123456'}
|
|
132
|
+
when 'spot_trade_batch_cancel_plan_order'
|
|
133
|
+
{symbol: 'BTCUSDT', order_ids: ['123', '456']}
|
|
134
|
+
else
|
|
135
|
+
{symbol: 'BTCUSDT'}
|
|
49
136
|
end
|
|
137
|
+
|
|
138
|
+
mock_v2_client.expect(method.to_sym, nil, [args])
|
|
139
|
+
client.send(method, **args)
|
|
140
|
+
mock_v2_client.verify
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Account
|
|
146
|
+
|
|
147
|
+
%w[
|
|
148
|
+
spot_account_info
|
|
149
|
+
spot_account_assets
|
|
150
|
+
spot_account_subaccount_assets
|
|
151
|
+
spot_account_bills
|
|
152
|
+
spot_account_sub_main_trans_record
|
|
153
|
+
spot_account_transfer_records
|
|
154
|
+
spot_account_switch_deduct
|
|
155
|
+
spot_account_deduct_info
|
|
156
|
+
spot_wallet_modify_deposit_account
|
|
157
|
+
spot_wallet_transfer
|
|
158
|
+
spot_wallet_transfer_coin_info
|
|
159
|
+
spot_wallet_subaccount_transfer
|
|
160
|
+
spot_wallet_withdrawal
|
|
161
|
+
spot_wallet_cancel_withdrawal
|
|
162
|
+
spot_wallet_deposit_address
|
|
163
|
+
spot_wallet_subaccount_deposit_address
|
|
164
|
+
spot_wallet_subaccount_deposit_records
|
|
165
|
+
spot_wallet_withdrawal_records
|
|
166
|
+
spot_wallet_deposit_records
|
|
167
|
+
].each do |method|
|
|
168
|
+
describe "##{method}" do
|
|
169
|
+
it "delegates to V2::Client" do
|
|
170
|
+
mock_v2_client = Minitest::Mock.new
|
|
171
|
+
client.instance_variable_set(:@v2_client, mock_v2_client)
|
|
172
|
+
|
|
173
|
+
args = case method
|
|
174
|
+
when 'spot_wallet_withdrawal'
|
|
175
|
+
{
|
|
176
|
+
coin: 'USDT',
|
|
177
|
+
chain: 'TRC20',
|
|
178
|
+
address: '0x1234567890abcdef',
|
|
179
|
+
amount: '100'
|
|
180
|
+
}
|
|
181
|
+
when /transfer/
|
|
182
|
+
{
|
|
183
|
+
coin: 'USDT',
|
|
184
|
+
amount: '100'
|
|
185
|
+
}
|
|
186
|
+
when /subaccount/
|
|
187
|
+
{subaccount_id: '123456'}
|
|
188
|
+
else
|
|
189
|
+
{}
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
mock_v2_client.expect(method.to_sym, nil, [args])
|
|
193
|
+
client.send(method, **args)
|
|
194
|
+
mock_v2_client.verify
|
|
50
195
|
end
|
|
51
196
|
end
|
|
52
197
|
end
|
data/test/helper.rb
CHANGED
|
@@ -1,34 +1,13 @@
|
|
|
1
1
|
require 'minitest/autorun'
|
|
2
2
|
require 'minitest-spec-context'
|
|
3
3
|
require 'minitest/spec'
|
|
4
|
-
require 'ostruct'
|
|
5
4
|
require 'vcr'
|
|
6
5
|
|
|
7
6
|
VCR.configure do |config|
|
|
8
7
|
config.cassette_library_dir = File.expand_path('../fixtures/vcr_cassettes', __FILE__)
|
|
9
8
|
config.hook_into :webmock
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def api_key
|
|
13
|
-
if ENV['BITGET_API_KEY']
|
|
14
|
-
ENV['BITGET_API_KEY']
|
|
15
|
-
else
|
|
16
|
-
'api_key0'
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def api_secret
|
|
21
|
-
if ENV['BITGET_API_SECRET']
|
|
22
|
-
ENV['BITGET_API_SECRET']
|
|
23
|
-
else
|
|
24
|
-
'api_secret0'
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
9
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
else
|
|
32
|
-
'api_passphrase0'
|
|
33
|
-
end
|
|
10
|
+
config.filter_sensitive_data('<API_KEY>'){ENV['BITGET_API_KEY']}
|
|
11
|
+
config.filter_sensitive_data('<API_SECRET>'){ENV['BITGET_API_SECRET'] }
|
|
12
|
+
config.filter_sensitive_data('<API_PASSPHRASE>'){ENV['BITGET_API_PASSPHRASE']}
|
|
34
13
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bitget.rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2025-
|
|
10
|
+
date: 2025-05-26 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: http.rb
|
|
@@ -36,12 +36,12 @@ files:
|
|
|
36
36
|
- lib/Bitget/Error.rb
|
|
37
37
|
- lib/Bitget/V2/Client.rb
|
|
38
38
|
- lib/Bitget/VERSiON.rb
|
|
39
|
-
- lib/Hash/to_parameter_string.rb
|
|
40
39
|
- lib/Hash/x_www_form_urlencode.rb
|
|
41
40
|
- lib/String/url_encode.rb
|
|
42
41
|
- lib/Thoran/Hash/XWwwFormUrlencode/x_www_form_urlencode.rb
|
|
43
42
|
- lib/Thoran/String/UrlEncode/url_encode.rb
|
|
44
43
|
- lib/bitget.rb
|
|
44
|
+
- test/V2/client_logging_test.rb
|
|
45
45
|
- test/V2/client_test.rb
|
|
46
46
|
- test/client_test.rb
|
|
47
47
|
- test/helper.rb
|
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
64
64
|
- !ruby/object:Gem::Version
|
|
65
65
|
version: '0'
|
|
66
66
|
requirements: []
|
|
67
|
-
rubygems_version: 3.6.
|
|
67
|
+
rubygems_version: 3.6.9
|
|
68
68
|
specification_version: 4
|
|
69
69
|
summary: Access the Bitget API with Ruby.
|
|
70
70
|
test_files: []
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# Hash#to_parameter_string
|
|
2
|
-
|
|
3
|
-
# 20120610
|
|
4
|
-
# 1.0.2
|
|
5
|
-
|
|
6
|
-
# Changes since 0:
|
|
7
|
-
# 1. I changed it from a class method to an instance method and hence removed references to any arguments and substituted self for those arguments.
|
|
8
|
-
# 0/1
|
|
9
|
-
# 2. I forget about needing String#url_encode, which for now I'll paste in here.
|
|
10
|
-
# 1/2
|
|
11
|
-
# 3. - String#url_encode.
|
|
12
|
-
# 4. + require 'String/url_encode'.
|
|
13
|
-
|
|
14
|
-
require 'String/url_encode'
|
|
15
|
-
|
|
16
|
-
class Hash
|
|
17
|
-
|
|
18
|
-
def to_parameter_string
|
|
19
|
-
parameters_string_parts = []
|
|
20
|
-
self.each do |k,v|
|
|
21
|
-
parameters_string_parts << (k.to_s + '=' + v.url_encode) unless v.nil?
|
|
22
|
-
end
|
|
23
|
-
parameters_string_parts.join('&')
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
end
|