huginn_xeggex_agent 0.1.0 → 0.1.10
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/lib/huginn_xeggex_agent/xeggex_agent.rb +88 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfe97772b2cd14cb0c48d80c586df25c9cc5b93535c64fef3b78ef77309b93bc
|
4
|
+
data.tar.gz: b827070ab649cde0e5272bb3cdf2f86195fdaeb8ff8da0b9c4d52227013128a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91a3f89cb949669df8a9ef6f0e7dc426591614ec0eba9364575afe087473d72507fa940c33cfc3292d457f53a70a926cb2dcc695e692afee2b2261edc932a331
|
7
|
+
data.tar.gz: 5de23d22c86db7d5aa3be84ece99aceb1b11b1180ff407c99d1461e913bc65482e491723ba338ac23443f79588259c982d5eaa92aeb72dbacb9467dee20d6ce8
|
@@ -17,6 +17,12 @@ module Agents
|
|
17
17
|
|
18
18
|
`api_secret` is needed for endpoints with auth.
|
19
19
|
|
20
|
+
`symbol` is needed for queries like get_orders, for example CLO/BTC
|
21
|
+
|
22
|
+
`status` is needed for queries like get_orders and limited to active, filled and cancelled.
|
23
|
+
|
24
|
+
`limit` is needed for queries like get_orders.
|
25
|
+
|
20
26
|
`expected_receive_period_in_days` is used to determine if the Agent is working. Set it to the maximum number of days
|
21
27
|
that you anticipate passing without this Agent receiving an incoming Event.
|
22
28
|
MD
|
@@ -41,27 +47,47 @@ module Agents
|
|
41
47
|
'type' => 'check_balance',
|
42
48
|
'api_token' => '',
|
43
49
|
'api_secret' => '',
|
50
|
+
'symbol' => '',
|
51
|
+
'status' => 'filled',
|
52
|
+
'limit' => '10',
|
44
53
|
'debug' => 'false',
|
45
54
|
'expected_receive_period_in_days' => '2',
|
46
55
|
}
|
47
56
|
end
|
48
57
|
|
49
|
-
form_configurable :type, type: :array, values: ['check_balance']
|
58
|
+
form_configurable :type, type: :array, values: ['check_balance', 'check_orders']
|
50
59
|
form_configurable :api_key, type: :string
|
51
60
|
form_configurable :api_secret, type: :string
|
61
|
+
form_configurable :symbol, type: :string
|
62
|
+
form_configurable :status, type: :array, values: ['active', 'filled', 'cancelled']
|
63
|
+
form_configurable :limit, type: :string
|
52
64
|
form_configurable :debug, type: :boolean
|
53
65
|
form_configurable :expected_receive_period_in_days, type: :string
|
54
66
|
def validate_options
|
55
|
-
errors.add(:base, "type has invalid value: should be 'check_balance'") if interpolated['type'].present? && !%w(check_balance).include?(interpolated['type'])
|
67
|
+
errors.add(:base, "type has invalid value: should be 'check_balance' 'check_orders'") if interpolated['type'].present? && !%w(check_balance check_orders).include?(interpolated['type'])
|
68
|
+
|
69
|
+
errors.add(:base, "status has invalid value: should be 'active' 'filled' 'cancelled'") if interpolated['type'].present? && !%w(active filled cancelled).include?(interpolated['status'])
|
56
70
|
|
57
|
-
unless options['api_key'].present? || !['check_balance'].include?(options['type'])
|
71
|
+
unless options['api_key'].present? || !['check_balance', 'check_orders'].include?(options['type'])
|
58
72
|
errors.add(:base, "api_key is a required field")
|
59
73
|
end
|
60
74
|
|
61
|
-
unless options['api_secret'].present? || !['check_balance'].include?(options['type'])
|
75
|
+
unless options['api_secret'].present? || !['check_balance', 'check_orders'].include?(options['type'])
|
62
76
|
errors.add(:base, "api_secret is a required field")
|
63
77
|
end
|
64
78
|
|
79
|
+
unless options['symbol'].present? || !['check_orders'].include?(options['type'])
|
80
|
+
errors.add(:base, "symbol is a required field")
|
81
|
+
end
|
82
|
+
|
83
|
+
unless options['status'].present? || !['check_orders'].include?(options['type'])
|
84
|
+
errors.add(:base, "status is a required field")
|
85
|
+
end
|
86
|
+
|
87
|
+
unless options['limit'].present? || !['check_orders'].include?(options['type'])
|
88
|
+
errors.add(:base, "limit is a required field")
|
89
|
+
end
|
90
|
+
|
65
91
|
if options.has_key?('debug') && boolify(options['debug']).nil?
|
66
92
|
errors.add(:base, "if provided, debug must be true or false")
|
67
93
|
end
|
@@ -96,13 +122,68 @@ module Agents
|
|
96
122
|
log "request status : #{code}"
|
97
123
|
|
98
124
|
if interpolated['debug'] == 'true'
|
99
|
-
log "request status : #{code}"
|
100
125
|
log "body"
|
101
126
|
log body
|
102
127
|
end
|
103
128
|
|
104
129
|
end
|
105
130
|
|
131
|
+
def check_orders(xeggex_url_endpoint)
|
132
|
+
|
133
|
+
uri = URI.parse(xeggex_url_endpoint + '/getorders?symbol=' + interpolated['symbol'] + '&status=' + interpolated['status'] + '&limit=' + interpolated['limit'] + '&skip=0')
|
134
|
+
request = Net::HTTP::Get.new(uri)
|
135
|
+
request.basic_auth("#{interpolated['api_key']}", "#{interpolated['api_secret']}")
|
136
|
+
request["Accept"] = "application/json"
|
137
|
+
|
138
|
+
req_options = {
|
139
|
+
use_ssl: uri.scheme == "https",
|
140
|
+
}
|
141
|
+
|
142
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
143
|
+
http.request(request)
|
144
|
+
end
|
145
|
+
|
146
|
+
log_curl_output(response.code,response.body)
|
147
|
+
|
148
|
+
payload = JSON.parse(response.body)
|
149
|
+
payload_memory = payload.dup
|
150
|
+
if payload != memory['last_status']
|
151
|
+
payload.each do |order|
|
152
|
+
found = false
|
153
|
+
if interpolated['debug'] == 'true'
|
154
|
+
log "order"
|
155
|
+
log order
|
156
|
+
end
|
157
|
+
if !memory['last_status'].nil? and memory['last_status'].present?
|
158
|
+
if interpolated['debug'] == 'true'
|
159
|
+
log "memory"
|
160
|
+
log memory['last_status']
|
161
|
+
end
|
162
|
+
last_status = memory['last_status']
|
163
|
+
last_status.each do |orderbis|
|
164
|
+
if order == orderbis
|
165
|
+
found = true
|
166
|
+
end
|
167
|
+
if interpolated['debug'] == 'true'
|
168
|
+
log "orderbis"
|
169
|
+
log orderbis
|
170
|
+
log "found is #{found}!"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
if found == false
|
175
|
+
create_event payload: order
|
176
|
+
end
|
177
|
+
end
|
178
|
+
else
|
179
|
+
if interpolated['debug'] == 'true'
|
180
|
+
log "nothing to compare"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
memory['last_status'] = payload_memory
|
184
|
+
|
185
|
+
end
|
186
|
+
|
106
187
|
def check_balance(xeggex_url_endpoint)
|
107
188
|
|
108
189
|
uri = URI.parse(xeggex_url_endpoint + '/balances')
|
@@ -166,6 +247,8 @@ module Agents
|
|
166
247
|
case interpolated['type']
|
167
248
|
when "check_balance"
|
168
249
|
check_balance(xeggex_url_endpoint)
|
250
|
+
when "check_orders"
|
251
|
+
check_orders(xeggex_url_endpoint)
|
169
252
|
else
|
170
253
|
log "Error: type has an invalid value (#{type})"
|
171
254
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: huginn_xeggex_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Germain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|