@@ -19,23 +19,7 @@ def defined(a_hash, key)
1919def good_params ( a_hash , fields )
2020 return false if a_hash . nil?
2121
22- fields . each do |field |
23- return false unless defined ( a_hash , field )
24- end
25- true
26- end
27-
28- def good_list ( check_fn , list )
29- list . each do |elem |
30- return false unless check_fn . call ( elem )
31- end
32- true
33- end
34-
35- def good_hash ( _check_fn , hash )
36- hash . each_value do |elem |
37- return false unless check_fn ( elem )
38- end
22+ fields . each { |field | return false unless defined ( a_hash , field ) }
3923 true
4024end
4125
@@ -51,9 +35,7 @@ def good_currency(currency)
5135 ] )
5236 return false unless good
5337
54- currency [ 'networks' ] . each do |level |
55- return false unless good_network ( level )
56- end
38+ currency [ 'networks' ] . each { |level | return false unless good_network ( level ) }
5739 true
5840 end
5941
@@ -85,9 +67,7 @@ def good_price_history(price_history)
8567 good = good_params ( price_history , %w[ currency history ] )
8668 return false unless good
8769
88- price_history [ 'history' ] . each do |point |
89- return false unless good_history_point ( point )
90- end
70+ price_history [ 'history' ] . each { |point | return false unless good_history_point ( point ) }
9171 true
9272 end
9373
@@ -104,16 +84,11 @@ def self.good_public_trade
10484 end
10585
10686 def good_orderbook ( orderbook )
107- good_orderbook = good_params ( orderbook ,
108- %w[ timestamp ask bid ] )
87+ good_orderbook = good_params ( orderbook , %w[ timestamp ask bid ] )
10988 return false unless good_orderbook
11089
111- orderbook [ 'ask' ] . each do |level |
112- return false unless good_orderbook_level ( level )
113- end
114- orderbook [ 'bid' ] . each do |level |
115- return false unless good_orderbook_level ( level )
116- end
90+ orderbook [ 'ask' ] . each { |level | return false unless good_orderbook_level ( level ) }
91+ orderbook [ 'bid' ] . each { |level | return false unless good_orderbook_level ( level ) }
11792 true
11893 end
11994
@@ -131,23 +106,22 @@ def good_order(order)
131106 quantity price quantity_cumulative created_at updated_at ] )
132107 end
133108
134- def self . good_trade
109+ def good_trade
135110 lambda { |trade |
136111 good_params ( trade , %w[ id orderId clientOrderId symbol side quantity
137112 price fee timestamp ] )
138113 }
139114 end
140115
141- def good_native_transaction ( native_transaction )
116+ def self . good_native_transaction ( native_transaction )
142117 good_params ( native_transaction , %w[ tx_id index currency amount ] )
143118 end
144119
145- def good_transaction ( transaction )
146- good = good_params ( transaction ,
147- %w[ id status type subtype created_at updated_at ] )
120+ def self . good_transaction ( transaction )
121+ good = good_params ( transaction , %w[ id status type subtype created_at updated_at ] )
148122 return false unless good
149123
150- return false if transaction . key? ( 'native' ) && !good_native_transaction ( transaction [ 'native' ] )
124+ return false if transaction . key? ( 'native' ) && !Checks . good_native_transaction ( transaction [ 'native' ] )
151125
152126 true
153127 end
@@ -182,12 +156,8 @@ def self.good_orderbook
182156 lambda { |orderbook |
183157 return false unless good_params ( orderbook , %w[ t s a b ] )
184158
185- orderbook [ 'a' ] . each do |level |
186- return false unless good_orderbook_level ( level )
187- end
188- orderbook [ 'b' ] . each do |level |
189- return false unless good_orderbook_level ( level )
190- end
159+ orderbook [ 'a' ] . each { |level | return false unless good_orderbook_level ( level ) }
160+ orderbook [ 'b' ] . each { |level | return false unless good_orderbook_level ( level ) }
191161 true
192162 }
193163 end
@@ -199,18 +169,30 @@ def self.good_orderbook_top
199169 def self . good_price_rate
200170 -> ( price_rate ) { good_params ( price_rate , %w[ t r ] ) }
201171 end
202- end
203172
204- class VeredictChecker # rubocop:disable Style/Documentation
205- def initialize
206- @veredict = true
173+ def self . good_report
174+ lambda { |report |
175+ good_params ( report ,
176+ %w[ id client_order_id symbol side status type time_in_force
177+ quantity price quantity_cumulative created_at updated_at ] )
178+ }
179+ end
180+
181+ def self . good_balance
182+ -> ( balance ) { good_params ( balance , %w[ currency available reserved ] ) }
183+ end
184+
185+ def self . good_commission
186+ -> ( commission ) { good_params ( commission , %w[ symbol take_rate make_rate ] ) }
207187 end
208188
209- def good_veredict?
210- @veredict
189+ def self . good_transaction
190+ -> ( transaction ) { Checks . good_transaction ( transaction ) }
211191 end
212192
213- def append ( veredict )
214- @veredict &&= veredict
193+ def self . print
194+ lambda { |reports |
195+ puts reports
196+ }
215197 end
216198end
0 commit comments