Created
March 22, 2018 14:09
-
-
Save sheva29/ac64c02696633440225316066b15f7b3 to your computer and use it in GitHub Desktop.
This script looks at the number of occurrences for prices given a a crypto currency for 1 day, takes the first top 10, averages them and puts them in a new csv file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# script to be at the same level as input folder and output folder | |
INPUT_FOLDER='bittrex-bot/*' | |
OUTPUT_FOLDER='csv_output/' | |
OUTPUT_FILE_FORMAT=".csv" | |
for file in $INPUT_FOLDER | |
do | |
# file name | |
NAME=${file##*/} | |
number_of_lines=10 | |
# get currency TICKER | |
CURRENCY=${NAME%%-*} | |
#g get date | |
DATE=`cut -d "-" -f 2- <<< "$NAME"` | |
DATE=${DATE%%.*} # remove the ".csv" | |
# look at number of occurances | |
# cat $file | cut -d, -f1 | sort | uniq -c | sort -r | head -n 10 | awk '{$1=$1",";$(NF-1)=$(NF-1)}1' > $OUTPUT_FILE_NAME | |
# get list of prices and occurances through 1 day | |
PRICES=`cat $file | cut -d, -f1 | sort | uniq -c | sort -r | head -n $number_of_lines | awk '{$1=$1",";$(NF-1)=$(NF-1)}1' | cut -d, -f2` | |
price_sum=0 | |
echo "beginning of forloop" | |
for price in $PRICES | |
do | |
# we add the prices | |
price_sum=`bc <<< "scale=10; $price_sum+$price;"` | |
echo "price_total:" $price_sum | |
done | |
# we get the average | |
average=`bc <<< "scale=10; $price_sum/$number_of_lines;"` | |
echo "average: " $average | |
OUTPUT_FILE_NAME=$OUTPUT_FOLDER$CURRENCY$OUTPUT_FILE_FORMAT | |
#check if file exists | |
if [ -e $OUTPUT_FILE_NAME ] | |
then | |
# add average | |
echo $DATE ", " $average >> $OUTPUT_FILE_NAME | |
else | |
# add first header | |
echo "Date, Price_Average" >> $OUTPUT_FILE_NAME | |
# add first average | |
echo $DATE ", " $average >> $OUTPUT_FILE_NAME | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment