aga-money 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/money/base.rb +2 -1
- data/lib/money/resources/arbitrage.rb +5 -1
- data/lib/money/resources/helpers/controls/gain.rb +12 -7
- data/lib/money/resources/helpers/controls/validator.rb +16 -2
- data/lib/money/resources/helpers/request_app.rb +34 -0
- data/lib/money/version.rb +1 -1
- data/lib/money.rb +4 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb930bdcaebb946f5c5f841103ca4ce0ee1748872ba8ea89793cfe41099fdb17
|
4
|
+
data.tar.gz: ff712f49838f5fd642c7e5d6148f1b0af121df9ab2bd22f3a2b2be2a95afd762
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01606bcb91ba2f5f17fef8a33dbd0ac71e7a0e839504a440798f6579aed744f4dfba3ce3405b856678e82a031d90ae8fc6b12652943d9f861f01aadb7d8bba5a
|
7
|
+
data.tar.gz: 0d1cd32b61a213d202198afeb721fd411a85dc516ceb77ba677b552bff22dbca02ffbb4ec7d339f5f1ad78d5ea04c5d0941e1b4bccb8ac1deb253abc746d3dc7
|
data/lib/money/base.rb
CHANGED
@@ -3,9 +3,10 @@
|
|
3
3
|
module Money
|
4
4
|
class Base
|
5
5
|
class << self
|
6
|
-
attr_accessor :app_info
|
6
|
+
attr_accessor :app_info, :path_prefix
|
7
7
|
end
|
8
8
|
|
9
9
|
self.app_info = ::ENV['APP_INFO'] || "#{::Money::NAME} V#{::Money.version}"
|
10
|
+
self.path_prefix = 'http://localhost:3000/api/v1/'
|
10
11
|
end
|
11
12
|
end
|
@@ -36,7 +36,9 @@ module Money
|
|
36
36
|
|
37
37
|
liquidity = validator(pairs).liquidity
|
38
38
|
|
39
|
-
validator(liquidity).gain
|
39
|
+
gain = validator(liquidity).gain
|
40
|
+
|
41
|
+
validator(gain).exist
|
40
42
|
end
|
41
43
|
|
42
44
|
def response(data)
|
@@ -49,5 +51,7 @@ module Money
|
|
49
51
|
|
50
52
|
payload
|
51
53
|
end
|
54
|
+
|
55
|
+
attr_accessor :start
|
52
56
|
end
|
53
57
|
end
|
@@ -10,6 +10,8 @@ module Money
|
|
10
10
|
MIN_NUMBER = 0.0000000001
|
11
11
|
MAX_PERC = 0.1
|
12
12
|
|
13
|
+
SET_PERC = 1.0
|
14
|
+
|
13
15
|
def initialize(pairs)
|
14
16
|
@pairs = pairs
|
15
17
|
end
|
@@ -26,15 +28,17 @@ module Money
|
|
26
28
|
price = detection.dig(:payload, :price)
|
27
29
|
return {} if price.nil?
|
28
30
|
|
31
|
+
return {} if percentage(detection).round(3) < SET_PERC
|
32
|
+
|
29
33
|
percentage(detection).round(3) >= computation_percentage(price).round(3)
|
30
34
|
end
|
31
35
|
|
32
|
-
# rubocop: disable
|
36
|
+
# rubocop: disable Lint/MissingCopEnableDirective
|
33
37
|
def discriminate_pairs
|
34
38
|
return nil if @pairs.nil?
|
35
39
|
|
36
|
-
max = @pairs&.
|
37
|
-
min = @pairs&.
|
40
|
+
max = @pairs&.max_by { |pair| pair[:price] }
|
41
|
+
min = @pairs&.min_by { |pair| pair[:price] }
|
38
42
|
|
39
43
|
detection = select_max_pairs(max: max, min: min)
|
40
44
|
gain = compare(detection)
|
@@ -52,15 +56,16 @@ module Money
|
|
52
56
|
end
|
53
57
|
|
54
58
|
def select_exchange_names(data)
|
55
|
-
data&.
|
59
|
+
data&.sort_by { |e| e[:price] }
|
56
60
|
end
|
57
61
|
|
58
62
|
def select_max_pairs(max:, min:)
|
59
|
-
data =
|
63
|
+
data = [min, max]
|
64
|
+
|
60
65
|
exchanges = select_exchange_names(data)
|
61
|
-
diff = max - min
|
66
|
+
diff = max[:price] - min[:price]
|
62
67
|
|
63
|
-
{ payload: { max_diff: diff, exchanges: exchanges, price: min } }
|
68
|
+
{ payload: { max_diff: diff, exchanges: exchanges, price: min[:price] } }
|
64
69
|
end
|
65
70
|
end
|
66
71
|
end
|
@@ -16,7 +16,9 @@ module Money
|
|
16
16
|
@data = data
|
17
17
|
end
|
18
18
|
|
19
|
+
# rubocop: disable Metrics/MethodLength, Lint/MissingCopEnableDirective
|
19
20
|
def gain
|
21
|
+
cryptos = []
|
20
22
|
@data&.map do |item|
|
21
23
|
exchanges = item[:exchanges]
|
22
24
|
@gainer = Money::Helpers::Controls::Gain.new(exchanges)
|
@@ -27,10 +29,10 @@ module Money
|
|
27
29
|
item[:exchanges] = potential.dig(:payload, :exchanges)
|
28
30
|
item.each { |i| i.delete(:price) }
|
29
31
|
|
30
|
-
item
|
32
|
+
cryptos << item
|
31
33
|
end&.compact
|
32
34
|
|
33
|
-
|
35
|
+
cryptos
|
34
36
|
end
|
35
37
|
|
36
38
|
def liquidity
|
@@ -40,6 +42,18 @@ module Money
|
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
45
|
+
def exist
|
46
|
+
cryptos = []
|
47
|
+
@data&.map do |item|
|
48
|
+
request = Money::Helpers::RequestApp.new.operation_exist(item)
|
49
|
+
next if request[:response]['exist'] == true
|
50
|
+
|
51
|
+
cryptos << item
|
52
|
+
end&.compact
|
53
|
+
|
54
|
+
cryptos
|
55
|
+
end
|
56
|
+
|
43
57
|
def pairs
|
44
58
|
@data&.map do |item|
|
45
59
|
filtered = item[:exchanges].select { |cmc_item| EXCHANGES.include?(cmc_item[:exchange]) }
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
module Money
|
8
|
+
module Helpers
|
9
|
+
class RequestApp
|
10
|
+
def operation_exist(payload)
|
11
|
+
url = build_url('operations/exist')
|
12
|
+
builder_request(url: url, payload: payload)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def build_url(path, params = {})
|
18
|
+
URI.parse("#{Money::Base.path_prefix}#{path}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def builder_request(url:, payload:)
|
22
|
+
http = Net::HTTP.new(url.host, url.port)
|
23
|
+
request = Net::HTTP::Get.new(url)
|
24
|
+
request['Authorization'] = 'Bearer 5c16c565fbd9f128063019f2828be964'
|
25
|
+
request['Content-Type'] = 'application/json'
|
26
|
+
request.body = JSON.dump(payload)
|
27
|
+
|
28
|
+
response = http.request(request)
|
29
|
+
{ response: JSON.parse(response.body), status: response.code.to_i == 200 }
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/money/version.rb
CHANGED
data/lib/money.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aga-money
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Baldazzi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -237,6 +237,7 @@ files:
|
|
237
237
|
- lib/money/resources/helpers/controls/validator.rb
|
238
238
|
- lib/money/resources/helpers/format.rb
|
239
239
|
- lib/money/resources/helpers/http_request.rb
|
240
|
+
- lib/money/resources/helpers/request_app.rb
|
240
241
|
- lib/money/resources/new.rb
|
241
242
|
- lib/money/resources/top.rb
|
242
243
|
- lib/money/version.rb
|
@@ -262,5 +263,5 @@ requirements: []
|
|
262
263
|
rubygems_version: 3.3.24
|
263
264
|
signing_key:
|
264
265
|
specification_version: 4
|
265
|
-
summary: aga-money0.0.
|
266
|
+
summary: aga-money0.0.3
|
266
267
|
test_files: []
|