6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/watchcow/rate.rb', line 6
def call coin=nil
results = []
coin_list = coin.nil? ? Watchcow::ContractInfo.current_contracts : Watchcow::ContractInfo.current_contracts.select{|k, v| k == coin.upcase}
coin_list.each do |coin, contract_types|
contract_types.each do |t|
dm_symbol = {symbol: "#{coin}_#{t}"}
spot_symbol = {symbol: "#{coin.downcase}usdt"}
begin
dm_result = Watchcow::MarketDepth.call(params: dm_symbol, k: :future)
spot_result = Watchcow::MarketDepth.call(params: spot_symbol, k: :spot)
dm_result = JSON.parse dm_result
days_remain =
n = 1
rescue
n += 1
redo if n <= 3
end
result = cals dm_result, spot_result, coin, t
results.push(result)
end
end
results_cq = results.select{|x| x[:coin].include?('cq')}
results_nq = results.select{|x| x[:coin].include?('nq')}
results_cw = results.select{|x| x[:coin].include?('cw')}
results_nw = results.select{|x| x[:coin].include?('nw')}
{
cq_list: results_cq.sort{|x,y| y[:expected_margin] <=> x[:expected_margin]},
nq_list: results_nq.sort{|x,y| y[:expected_margin] <=> x[:expected_margin]},
cw_list: results_cw.sort{|x,y| y[:expected_margin] <=> x[:expected_margin]},
nw_list: results_nw.sort{|x,y| y[:expected_margin] <=> x[:expected_margin]}
}
end
|