paxful_engine-rails 0.8.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfbab6d68b7693a8c295309e0823548df1c26288ad50b838d482629cc9f63ce6
4
- data.tar.gz: 25f5ef6962c35d9f13427118cf7c3b2b4dfad29e1a461ff442f3d9f0a693df15
3
+ metadata.gz: 6c112f8a170dd446c5c05ce42f20cdd52ed63ebe8b98951a320e38b9601bf577
4
+ data.tar.gz: bccd1d0933512ca6d1795a81899e17ab952862feada2a3a1df7c53715f57ace4
5
5
  SHA512:
6
- metadata.gz: 9f1ff5f0642c1da4d7106158bc26cc22ba4177f2f06ced7eb99456fcc9fe2f195aa21fe1e730fdb6020b8e6136be9c147b262d63920c18c5b0724bcc38b3179e
7
- data.tar.gz: d4468bc1f0af6c3ea7d94d5e8976fbbf7b4e94f471e9df9a4dd0436fb2a4a7853524dcbd144bd2ec058f29977c133a273d8e74f94922f8382d4c29cfc846c40a
6
+ metadata.gz: 97d70200f22188c960973dcab812f7c318b4dc982aad2b1c43024f3d5066a75068ca94ba7ed242eada559876ab7f33286975f39c2bccbc9180b88f45316a6789
7
+ data.tar.gz: d25c1c9b567b8fa181cc5fb2feb44540f6e74ffb5e86f815a90f55f17547a490c247e8abb79564ed67dddbfdc9ecf2ebfe4366f58bf2d7721008894f25d9092c
data/README.md CHANGED
@@ -91,10 +91,11 @@ From the host app:
91
91
  ### Development
92
92
 
93
93
  ```
94
- $ rails db:migrate
95
- $ rails db:migrate db:test:prepare
94
+ $ rails db:create db:migrate db:test:prepare
96
95
  ```
97
96
 
97
+ If you need to re-record cassettes, `cp .env{,.local}` and edit the values.
98
+
98
99
  ### Testing
99
100
 
100
101
  ```
@@ -6,5 +6,10 @@ module PaxfulEngine
6
6
  status == "successful" ? "text-success" : "text-danger"
7
7
  end
8
8
 
9
+ def format_datetime(datetime, timezone = "Asia/Manila")
10
+ return "-" if datetime.nil?
11
+ datetime.in_time_zone(timezone).strftime("%m/%d/%Y %I:%M%p")
12
+ end
13
+
9
14
  end
10
15
  end
@@ -1,23 +1,8 @@
1
1
  module PaxfulEngine
2
2
  class SyncOrderBookJob < ApplicationJob
3
3
 
4
- HOST = "https://paxful.com/api".freeze
5
-
6
4
  def perform
7
- client = PaxfulClient.new(
8
- host: HOST,
9
- key: PaxfulEngine.configuration.paxful_key,
10
- secret: PaxfulEngine.configuration.paxful_secret,
11
- )
12
-
13
- response = client.get_completed_trades
14
- return unless response.success?
15
-
16
- trades = response.parsed_body["data"]["trades"]
17
-
18
- trades.each do |payload|
19
- EnqueueCreateTradeJob.perform_async(payload)
20
- end
5
+ SyncOrderBook.()
21
6
  end
22
7
 
23
8
  end
@@ -29,5 +29,9 @@ module PaxfulEngine
29
29
  offer_type.downcase == "sell"
30
30
  end
31
31
 
32
+ def base_crypto_requested
33
+ BigDecimal(crypto_amount_requested) / 100_000_000
34
+ end
35
+
32
36
  end
33
37
  end
@@ -0,0 +1,35 @@
1
+ module PaxfulEngine
2
+ class SyncOrderBook
3
+
4
+ HOST = "https://paxful.com/api".freeze
5
+ DEFAULT_PAGE = 1.freeze
6
+
7
+ def self.call(page: DEFAULT_PAGE, max_page: nil)
8
+ response = client.get_completed_trades(page: page)
9
+ return unless response.success?
10
+
11
+ trades = response.parsed_body["data"]["trades"]
12
+ return if trades.empty?
13
+
14
+ unsynced_trades = trades.select do |payload|
15
+ Trade.where(trade_hash: payload["trade_hash"]).none?
16
+ end
17
+ unsynced_trades.each { |payload| EnqueueCreateTradeJob.perform_async(payload) }
18
+
19
+ return if unsynced_trades.none?
20
+ return if max_page == page
21
+
22
+ self.(page: page + 1, max_page: max_page)
23
+ end
24
+
25
+ def self.client
26
+ PaxfulClient.new(
27
+ host: HOST,
28
+ key: PaxfulEngine.configuration.paxful_key,
29
+ secret: PaxfulEngine.configuration.paxful_secret,
30
+ )
31
+ end
32
+ private_class_method :client
33
+
34
+ end
35
+ end
@@ -14,13 +14,12 @@
14
14
  <table class="table table-striped table-bordered">
15
15
  <thead>
16
16
  <tr>
17
- <th scope="col">Created</th>
18
- <th scope="col">Completed</th>
17
+ <th scope="col">Completed Date</th>
19
18
  <th scope="col">Trade hash</th>
19
+ <th scope="col">Fiat</th>
20
+ <th scope="col">Crypto</th>
20
21
  <th scope="col">Type</th>
21
22
  <th scope="col">Status</th>
22
- <th scope="col">Seller</th>
23
- <th scope="col">Buyer</th>
24
23
  <th scope="col"></th>
25
24
  </tr>
26
25
  </thead>
@@ -33,15 +32,14 @@
33
32
 
34
33
  <% @trades.each do |trade| %>
35
34
  <tr scope="row">
36
- <td> <%= trade.created_at.strftime("%m/%d/%Y %I:%M%p") %> </td>
37
- <td> <%= trade.completed_at&.strftime("%m/%d/%Y %I:%M%p") || "-" %> </td>
35
+ <td> <%= format_datetime(trade.completed_at) %> </td>
38
36
  <td> <%= trade.trade_hash %> </td>
37
+ <td> <%= number_to_currency(trade.fiat_amount_requested, unit: "#{trade.fiat_currency_code} ") %> </td>
38
+ <td> <%= trade.crypto_currency_code %> <%= trade.base_crypto_requested %> </td>
39
39
  <td> <%= trade.offer_type.upcase %> </td>
40
40
  <td>
41
41
  <span class="<%= highlight_status(trade) %>"> <%= trade.status.upcase %> </span>
42
42
  </td>
43
- <td> <%= trade.seller %> </td>
44
- <td> <%= trade.buyer %> </td>
45
43
  <td> <%= link_to "Check trade details", paxful_engine.trade_path(trade) %> </td>
46
44
  </tr>
47
45
  <% end %>
@@ -20,17 +20,26 @@
20
20
  </div>
21
21
  <div>
22
22
  <strong>Crypto Requested:</strong>
23
- <%= number_to_currency(@trade.crypto_amount_requested, unit: "#{@trade.crypto_currency_code} ") %>
24
- (in sats)
23
+ <%= @trade.crypto_currency_code %> <%= @trade.base_crypto_requested %>
24
+ (<%= number_to_currency(@trade.crypto_amount_requested, unit: "") %> in sats)
25
25
  </div>
26
26
  </div>
27
27
 
28
28
  <hr />
29
29
 
30
30
  <div>
31
- <div> <strong>Started at:</strong> <%= @trade.started_at.strftime("%m/%d/%Y %I:%M%p") %> </div>
32
- <div> <strong>Ended at:</strong> <%= @trade.ended_at.strftime("%m/%d/%Y %I:%M%p") %> </div>
33
- <div> <strong>Completed at:</strong> <%= @trade.completed_at&.strftime("%m/%d/%Y %I:%M%p") %> </div>
31
+ <div>
32
+ <strong>Started at:</strong>
33
+ <%= format_datetime(@trade.started_at) %>
34
+ </div>
35
+ <div>
36
+ <strong>Ended at:</strong>
37
+ <%= format_datetime(@trade.ended_at) %>
38
+ </div>
39
+ <div>
40
+ <strong>Completed at:</strong>
41
+ <%= format_datetime(@trade.completed_at) %>
42
+ </div>
34
43
  </div>
35
44
 
36
45
  <hr />
@@ -1,3 +1,3 @@
1
1
  module PaxfulEngine
2
- VERSION = '0.8.1'
2
+ VERSION = '1.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paxful_engine-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Chavez
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-10 00:00:00.000000000 Z
11
+ date: 2020-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_config
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.0
33
+ version: '1.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.3.0
40
+ version: '1.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -186,6 +186,7 @@ files:
186
186
  - app/models/paxful_engine/application_record.rb
187
187
  - app/models/paxful_engine/trade.rb
188
188
  - app/services/paxful_engine/create_trade.rb
189
+ - app/services/paxful_engine/sync_order_book.rb
189
190
  - app/views/layouts/paxful_engine/application.html.erb
190
191
  - app/views/paxful_engine/trades/index.html.erb
191
192
  - app/views/paxful_engine/trades/show.html.erb
@@ -202,7 +203,7 @@ licenses:
202
203
  - MIT
203
204
  metadata:
204
205
  allowed_push_host: https://rubygems.org
205
- post_install_message:
206
+ post_install_message:
206
207
  rdoc_options: []
207
208
  require_paths:
208
209
  - lib
@@ -217,9 +218,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
218
  - !ruby/object:Gem::Version
218
219
  version: '0'
219
220
  requirements: []
220
- rubyforge_project:
221
- rubygems_version: 2.7.6
222
- signing_key:
221
+ rubygems_version: 3.1.4
222
+ signing_key:
223
223
  specification_version: 4
224
224
  summary: Mountable engine that fetches completed paxful trades.
225
225
  test_files: []