paxful_engine-rails 0.8.0 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35b73b52c9292bc8440a16c5782d38f4a54be438f351c2c843887709d1561f24
4
- data.tar.gz: dda35af7b33c326dccc2c56debf738ed65042b5d27eb55d7081599fb65ed41eb
3
+ metadata.gz: d3159a0488268a8e71de8b1f6692b7bded1cc237f8ba3a1e60da23b2ce9523e1
4
+ data.tar.gz: 528ea4f3abed5646fc83b30482f416bb6a8a3b8afa02025e59e52c2b9841e104
5
5
  SHA512:
6
- metadata.gz: d92645049bc6ec45b265d0e1575a959bf385dad892e3118bd2e46f38778a2df92d5843bc31847f3cb38d52949e1bb4722c03e06322f9501f978170ce515fd44a
7
- data.tar.gz: 63213435b8c2ec813a332804845a939ed31d1fc30e4791b32eb38483a7aafe81a198e2e7ed2d59d39370e2755e06e37a29df5a6f8ea0558ae792f3a7c923ebbe
6
+ metadata.gz: e190fa283c6cc58a736169715aedf981f155b082f6299205a4043d51a3f089bf8d9e8d210142501e0d85dfc50f0bf608a2cfe87253e867b00a2f333ce05a9b51
7
+ data.tar.gz: 57334072919f7f8b55942318df624ac1100b7d6398745a328521fe998325270cf45f002fcfc854e1c3cc9043cf8a5ee4e03f774e0f4a3701b9f8abd49501de4f
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
  ```
@@ -5,7 +5,7 @@ module PaxfulEngine
5
5
  @trades = Trade.order(completed_at: :desc, created_at: :desc)
6
6
 
7
7
  if params[:q] != "all"
8
- @trades = @trades.where.not(completed_at: :nil)
8
+ @trades = @trades.where.not(completed_at: nil)
9
9
  end
10
10
  end
11
11
 
@@ -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.0'
2
+ VERSION = '1.1.0'
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.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Chavez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-10 00:00:00.000000000 Z
11
+ date: 2020-12-04 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.1'
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.1'
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