Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong XMRBTC price for all price nodes #53

Closed
magma552 opened this issue Sep 18, 2024 · 0 comments
Closed

Wrong XMRBTC price for all price nodes #53

magma552 opened this issue Sep 18, 2024 · 0 comments

Comments

@magma552
Copy link

All price nodes seams to indicate wrong price:

Fetching prices for currency: XMR
Price: 0.00285145 | Server: http://devinpndvdwll4wiqcyq5e7itezmarg7rzicrvf6brzkwxdm374kmmyd.onion/getAllMarketPrices
Price: 0.00285145 | Server: http://runbtcpn7gmbj5rgqeyfyvepqokrijem6rbw7o5wgqbguimuoxrmcdyd.onion/getAllMarketPrices
Price: 0.00285145 | Server: http://devinpndvdwll4wiqcyq5e7itezmarg7rzicrvf6brzkwxdm374kmmyd.onion/getAllMarketPrices
Price: 0.00285145 | Server: http://ro7nv73awqs3ga2qtqeqawrjpbxwarsazznszvr6whv7tes5ehffopid.onion/getAllMarketPrices
Price: 0.00287300 | Server: https://api.kraken.com/0/public/Ticker?pair=XMRXBT
Price: 0.002869   | Server: https://api.kucoin.com/api/v1/market/stats?symbol=XMR-BTC
Price: 0.0028529  | Server: https://api-pub.bitfinex.com/v2/ticker/tXMRBTC
Price: 0.002869   | Server: https://api.poloniex.com/markets/XMR_BTC/ticker24h

The situation has persisted for several minutes.

I have used the script below (based on scripts provided here #28 and here #49

#!/bin/bash

# List of URLs to fetch data from
URLS=("http://devinpndvdwll4wiqcyq5e7itezmarg7rzicrvf6brzkwxdm374kmmyd.onion/getAllMarketPrices" 
      "http://runbtcpn7gmbj5rgqeyfyvepqokrijem6rbw7o5wgqbguimuoxrmcdyd.onion/getAllMarketPrices"
      "http://devinpndvdwll4wiqcyq5e7itezmarg7rzicrvf6brzkwxdm374kmmyd.onion/getAllMarketPrices"
      "http://ro7nv73awqs3ga2qtqeqawrjpbxwarsazznszvr6whv7tes5ehffopid.onion/getAllMarketPrices"
      "https://api.kraken.com/0/public/Ticker?pair=XMRXBT"
      "https://api.kucoin.com/api/v1/market/stats?symbol=XMR-BTC"
      "https://api-pub.bitfinex.com/v2/ticker/tXMRBTC"
      "https://api.poloniex.com/markets/XMR_BTC/ticker24h")

# Specify the currency code you want to compare
CURRENCY_CODE="XMR"

while true; do
  prices=()
  temp_files=()

  # Fetch data from each URL in parallel
  for url in "${URLS[@]}"; do
    temp_file=$(mktemp)
    temp_files+=("$temp_file")
    
    # Use torsocks for .onion URLs, regular curl for others
    if [[ "$url" == *.onion* ]]; then
      torsocks curl -s $url > "$temp_file" &
    else
      curl -s $url > "$temp_file" &
    fi
  done

  # Wait for all background jobs to finish
  wait

  echo "Fetching prices for currency: $CURRENCY_CODE"

  # Extract prices from temporary files
  for i in "${!temp_files[@]}"; do
    temp_file="${temp_files[$i]}"
    url="${URLS[$i]}"
    
    if [[ "$url" == *"kraken"* ]]; then
      price=$(cat "$temp_file" | jq -r '.result.XXMRXXBT.c[0]')
    elif [[ "$url" == *"kucoin"* ]]; then
      price=$(cat "$temp_file" | jq -r '.data.last')
    elif [[ "$url" == *"bitfinex"* ]]; then
      price=$(cat "$temp_file" | jq -r '.[6]')
    elif [[ "$url" == *"poloniex"* ]]; then
      price=$(cat "$temp_file" | jq -r '.markPrice')
    else
      price=$(cat "$temp_file" | jq -r ".data[] | select(.currencyCode == \"$CURRENCY_CODE\") | .price")
    fi

    prices+=("$price")
    printf "Price: %-10s | Server: %s\n" "$price" "$url"
    rm "$temp_file"
  done

  # Find minimum and maximum prices
  minPrice=${prices[0]}
  maxPrice=${prices[0]}
  for price in "${prices[@]}"; do
    if (( $(echo "$price < $minPrice" | bc -l) )); then
      minPrice=$price
    fi

    if (( $(echo "$price > $maxPrice" | bc -l) )); then
      maxPrice=$price
    fi
  done

  # Calculate the percentage difference
  difference=$(echo "scale=5; ($maxPrice - $minPrice) / $minPrice * 100" | bc)
  echo "Difference: $difference%"

  # Wait for 5 seconds before the next iteration
  sleep 5
done
@magma552 magma552 closed this as completed Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant