Adds ICP price support from binance for MetaPurse
This commit is contained in:
parent
75cfd7c4c0
commit
042c07f026
@ -4,4 +4,8 @@ class Metapurse < ActiveRecord::Base
|
||||
icpswap_pool_data_raw = `dfx --identity anonymous canister --network=ic call ggzvv-5qaaa-aaaag-qck7a-cai getAllPools`
|
||||
end
|
||||
|
||||
def icp_usd
|
||||
JSON.parse(`curl -s https://www.binance.com/api/v3/avgPrice?symbol=ICPUSDT`)["price"].to_f
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -22,12 +22,19 @@
|
||||
= number_with_delimiter(amount = record.split[1].gsub(",","").to_f) rescue nil
|
||||
- icp_canister_id = "ryjl3-tyaaa-aaaaa-aaaba-cai"
|
||||
-# = icpswap_pool_data_raw.split("record {").select{|pool| !pool.scan(canister_id).empty? && !pool.scan(icp_canister_id).empty? }[0]
|
||||
= icpswap_pool_data_raw.split("record {").select{|pool| !pool.scan(canister_id).empty? && !pool.scan(icp_canister_id).empty? }[0].scan(/token0Symbol = \"(.*)\"; /)[0][0] rescue nil
|
||||
- value = icpswap_pool_data_raw.split("record {").select{|pool| !pool.scan(canister_id).empty? && !pool.scan(icp_canister_id).empty? }[0].scan(/token0Price = [+-]?([1-9]\d*|0)(\.\d+)?/).join.to_f rescue nil
|
||||
= "$#{value.round(2)}"
|
||||
- value_amount = (value * amount).round(2) rescue 0
|
||||
$#{number_with_delimiter(value_amount)} USD
|
||||
- total_value += value_amount rescue 0
|
||||
- if canister_id == icp_canister_id
|
||||
ICP
|
||||
- value = @metapurse.icp_usd
|
||||
- value_amount = (value * amount).round(2) rescue 0
|
||||
$#{number_with_delimiter(value_amount)} USD
|
||||
- total_value += value_amount rescue 0
|
||||
- else
|
||||
= icpswap_pool_data_raw.split("record {").select{|pool| !pool.scan(canister_id).empty? && !pool.scan(icp_canister_id).empty? }[0].scan(/token0Symbol = \"(.*)\"; /)[0][0] rescue nil
|
||||
- value = icpswap_pool_data_raw.split("record {").select{|pool| !pool.scan(canister_id).empty? && !pool.scan(icp_canister_id).empty? }[0].scan(/token0Price = [+-]?([1-9]\d*|0)(\.\d+)?/).join.to_f rescue nil
|
||||
= "$#{value.round(2)}"
|
||||
- value_amount = (value * amount).round(2) rescue 0
|
||||
$#{number_with_delimiter(value_amount)} USD
|
||||
- total_value += value_amount rescue 0
|
||||
%p
|
||||
%b Total:
|
||||
$#{number_with_delimiter(total_value.round(2))} USD
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user