Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

8
Bash script for sia docker: Adjust pricing relative to siacoin value AND/OR storage used
Post Body

This is a bash script I made to automatically adjust the pricing for storing, collateral, up and download of a sia host running in docker. It should work with both the official nebulouslabs/sia and the siacentral/sia containers.

Use cron to run periodically on your host.

The script will pull the current siacoin value in USDT, extract storage usage from 'siac host' and adjust the prices according to what you set.

Please evaluate the script beforehand as I am not a skilled developer but a mere smooth brained bash script ape. I am not responsible if you loose money using this.

Feel free to modify and redistribute.

KNOWN ISSUES: CURRENTLY ONLY WORKS WITH ONE DATA FOLDER

#!/bin/bash

# Version 0.3 - 19.05.2021
# This script adjusts pricing for sia hosts running in a docker container in relation to used storage and price of siacoin/USDT.
# To disable price adjustments for storage usage set this variable to yes: OVERRIDEUSG
# To disable price adjustments for siacoin price/USDT set this variable to yes: OVERRIDEPRICE then set BASEPRICE to desired storage price in SC/Tb/Mnoth
# Currently only works with one storage folder in 'siac host'.
# Price adjustments are not linear but use cubic functions.
# You can uncomment some lines in the Debug output area to get additional information.

# Required packages: bc and jq

BASEPRICE=2            # SC/Tb/Month - Base price how much you want to charge for storage
OVERRIDEPRICE="no"     # Set to "yes" to disable adjusting for siacoin price
OVERRIDEUSG="no"       # Set to "yes" to disable adjusting for storage usage

MINSTORPRICEFAC=0.25   # Factor - How far from BASEPRICE do you want to lower your Storage price if usage is low
MAXSTORPRICEFAC=10     # Factor - How far from BASEPRICE do you want to raise your Storage price if usage is high
USGTARGETFAC=0.75      # Factor - Your targeted storage usage. At this point the pricing will equal BASEPRICE

STORFAC=1              # Factor - How much SC/Tb/Month of BASEPRICE for storing - best leave at 1
COLLFAC=2              # Factor - How much SC/Tb/Month of BASEPRICE for collateral - set between 1.5 and 3
DOWNFAC=0.4            # Factor - How much SC/Tb/Month of BASEPRICE for renter downloading - set according to your upload speed - higher if you have slow upload
UPLDFAC=0.1            # Factor - How much SC/Tb/Month of BASEPRICE for renter uploading - set according to your download speed - higher if you have slow download

SCALE=2                # How many decimals to use when calculating price
CONTNAME=sia           # name of the docker container running siac


#########################
# Get siacoin price #

if [ $OVERRIDEPRICE == "yes" ]; then
    SIAPRICE=1

else
    SIAPRICE=$(curl -m 60 -X GET \
    "https://api.coingecko.com/api/v3/simple/price?ids=siacoin&vs_currencies=usd&include_market_cap=false&include_24hr_vol=false&include_24hr_change=false&include_last_updated_at=false" \
    -H  "accept: application/json" | jq .siacoin.usd)

fi


#########################
# Get storage usage #

if [ $OVERRIDEUSG == "yes" ]; then
    USGCURRENTFAC=$USGTARGETFAC

else
    USGCURRENTFAC=$(echo "$(docker exec sia siac host | tail -1 | cut -c'30-40') / 100" | bc -l)

fi



#########################
# Adjust for usage #

if (( $(echo "$USGCURRENTFAC < $USGTARGETFAC" | bc -l) )); then
    USGADJUSTFAC=$(echo "1   ( ( 1 - $MINSTORPRICEFAC ) * ( $USGCURRENTFAC / $USGTARGETFAC - 1 )^3 )" | bc -l)

else
    USGADJUSTFAC=$(echo "1   ( ( $MAXSTORPRICEFAC - 1 ) * ( ( $USGCURRENTFAC - $USGTARGETFAC ) / ( 1 - $USGTARGETFAC ) )^3 )" | bc -l)

fi


#########################
# Calculate Prices #

    STORPRICE=`echo "scale=$SCALE; $BASEPRICE*$STORFAC*$USGADJUSTFAC/$SIAPRICE" | bc -l`
    COLLPRICE=`echo "scale=$SCALE; $BASEPRICE*$COLLFAC*$USGADJUSTFAC/$SIAPRICE" | bc -l`
    DOWNPRICE=`echo "scale=$SCALE; $BASEPRICE*$DOWNFAC*$USGADJUSTFAC/$SIAPRICE" | bc -l`
    UPLDPRICE=`echo "scale=$SCALE; $BASEPRICE*$UPLDFAC*$USGADJUSTFAC/$SIAPRICE" | bc -l`


########################
# Debug output #

#printf "\nSiacoin: $SIAPRICE $\n"
#printf "Usage: $USGCURRENTFAC\n"
#printf "Adjustment factor: $USGADJUSTFAC\n"
printf "Storing: $STORPRICE SC\nCollateral: $COLLPRICE SC\nDownload: $DOWNPRICE SC\nUpload: $UPLDPRICE SC\n\n"


########################
# Set siac host config #

docker exec \
   -e STORPRICE \
   -e COLLPRICE \
   -e DOWNPRICE \
   -e UPLDPRICE \
$CONTNAME sh -c " \
   siac host config minstorageprice ${STORPRICE}SC && \
   siac host config collateral ${COLLPRICE}SC && \
   siac host config mindownloadbandwidthprice ${DOWNPRICE}SC && \
   siac host config minuploadbandwidthprice ${UPLDPRICE}SC"

Edit: Found and fixed errors in functions to adjust for storage usage.

Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
47,033
Link Karma
3,471
Comment Karma
42,875
Profile updated: 5 days ago
Posts updated: 3 days ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago