A Simple BASH Script to Query to Cryptocurrency

in #witness-category2 years ago (edited)

Improved version: BASH Script to Query and Monitor the Crypto Prices (Exchange Rate to Fiat)

image.png

Here is a quick BASH script that allows you to do something like this:

./ticker
e.g. ././ticker steem usd
./ticker steem usd
"1 steem = 0.21412699896499998 usd"
./ticker 2 steem gbp
"2 steem = 0.3794 gbp"
./ticker eth 2 btc
"26.331085755738364 eth = 2 btc"

#!/bin/bash

check_json=$(echo "{ }" | jq)
if [ "$check_json" != "{}" ]; then
        echo "jq not installed"
        exit 1
fi

if [ "$1" == "" ]; then
        echo "e.g. ./$0 steem usd"
fi

API="https://price.justyy.workers.dev/query/"

curl -s -X POST -d "$*" $API | jq .result[0]

This requires the jq to parse the JSON output from the Crypto API made by @justyy (myself) on cloudflare workers serverless technology.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Thank you for reading ^^^^^^^^^^^^^^^

NEW! Following my Trail (Upvote or/and Downvote)

Follow me for topics of Algorithms, Blockchain and Cloud.
I am @justyy - a Steem Witness
https://steemyy.com

My contributions

Steem/Swap to USDT Swap

I also made this Super Easy/Handy Service to Convert your STEEM or SBD to USDT (TRC-20)

Delegation Service

Voting Power Considered in Voting Schema and Important Update of Delegation Service!

  • Delegate 1000 to justyy: Link
  • Delegate 5000 to justyy: Link
  • Delegate 10000 to justyy: Link

Support me

If you like my work, please:

  1. Delegate SP: https://steemyy.com/sp-delegate-form/?delegatee=justyy
  2. Vote @justyy as Witness: https://steemyy.com/witness-voting/?witness=justyy&action=approve
  3. Set @justyy as Proxy: https://steemyy.com/witness-voting/?witness=justyy&action=proxy
    Alternatively, you can vote witness or set proxy here: https://steemit.com/~witnesses

Sort:  

Awesome! Are you able to explain a little about how the prices on your endpoint are calculated?

And, very stylish use of jq!

The API is at https://price.justyy.workers.dev/ basically I get prices from a few exchanges, and do the average.

Is it the same exchange set as the pricefeed repo (Bittrex, Poloniex and Binance) or a more extensive set?

It would be great to do our own volume-weighted prices from Steem's top 90% volume exchanges (as per "Option B" in my recent price feed post).

I'd be happy to help with implementing additional exchange APIs, just let me know :)

Sure, sounds like a good plan

This post has been featured in the latest edition of Witness Weekly...

Thanks for everything

Hello @pennsif! You are superb!


command: !thumbup is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!

Coin Marketplace

STEEM 0.21
TRX 0.14
JST 0.030
BTC 69812.20
ETH 3376.99
USDT 1.00
SBD 2.78