Esempio n. 1
0
class ftx_tracker():
    def __init__(self):

        #FTX API details
        self.key = os.getenv("KEY")
        self.secret = os.getenv("SECRET")

        #Database details
        self.db = os.getenv("db")
        self.host = os.getenv("host")
        self.user = os.getenv("user")
        self.password = os.getenv("password")
        self.table_name = os.getenv("table_name")

        #Client/API connection
        self.client = FtxClient(api_key=self.key, api_secret=self.secret)

        #Getting total usd and adding to database
        self.create_table()

        total_usd = self.get_account()
        self.add_data(total_usd)
        # self.show_data()

    def get_account(self):
        data = self.client.get_balances()
        usd = sum([balance["usdValue"] for balance in data])

        return usd

    def create_table(self):
        with s3.connect(host=self.host,
                        database=self.db,
                        user=self.user,
                        password=self.password) as conn:
            cursor = conn.cursor()
            cursor.execute(
                "CREATE TABLE IF NOT EXISTS {} (timestamp INTEGER, balance INTEGER)"
                .format(self.table_name))
            conn.commit()

    def add_data(self, usd):
        with s3.connect(host=self.host,
                        database=self.db,
                        user=self.user,
                        password=self.password) as conn:
            cursor = conn.cursor()
            cursor.execute("INSERT INTO {} VALUES({}, {})".format(
                self.table_name, int(time.time()), usd))
            conn.commit()

    def show_data(self):
        with s3.connect(host=self.host,
                        database=self.db,
                        user=self.user,
                        password=self.password) as conn:
            cursor = conn.cursor()
            cursor.execute("SELECT * FROM {}".format(self.table_name))
            print(len(cursor.fetchall()))
Esempio n. 2
0
def checkAvlSRM(restBot: FtxClient):
    bal = restBot.get_balances()
    srmAvailable = dict.fromkeys(["SRM", "SRM_LOCKED", "MSRM", "MSRM_LOCKED"])
    for i in bal:
        if (i['coin'] == "SRM" and float(i["free"]) >= 0.00000001):
            srmAvailable["SRM"] = float(i["free"])
        elif (i['coin'] == "SRM_LOCKED" and float(i["free"]) >= 0.00000001):
            srmAvailable["SRM_LOCKED"] = float(i["free"])
        elif (i['coin'] == "MSRM" and float(i["free"]) >= 0.00000001):
            srmAvailable["MSRM"] = float(i["free"])
        elif (i['coin'] == "MSRM_LOCKED" and float(i["free"]) >= 0.00000001):
            srmAvailable["MSRM_LOCKED"] = float(i["free"])
    return srmAvailable
Esempio n. 3
0
def main():
    print(
        "----------------------------------------------------------------------------------------------------"
    )
    print(
        "Please Note: This program will stake ALL of your available SRM/LSRM/MSRM/LMSRM."
    )
    print(
        "So maybe you want to make a subaccount just for the staking purpose, in case you're using SRM as collateral."
    )
    print(
        "And please make sure you DID NOT enable the withdrawal ability of your API key."
    )
    print(
        "----------------------------------------------------------------------------------------------------"
    )
    apiKey = input("Enter your api Key: ")
    apiSecret = input("Enter your api Secret: ")
    subName = input(
        "Enter your subaccount name(if any), or just press enter: ")
    restBot = FtxClient(apiKey, apiSecret, subName)
    bal = None
    try:
        bal = restBot.get_balances()
    except Exception as e:
        print(e)
        print("Please check your API key and secret.")
    while True:
        srmAvailable = checkAvlSRM(restBot)
        if (srmAvailable["SRM"] != None):
            print("Staking", srmAvailable["SRM"], "SRM")
            restBot.stake_request("SRM", srmAvailable["SRM"])
        if (srmAvailable["SRM_LOCKED"] != None):
            print("Staking", srmAvailable["SRM_LOCKED"], "SRM_LOCKED")
            restBot.stake_request("SRM_LOCKED", srmAvailable["SRM_LOCKED"])
        if (srmAvailable["MSRM"] != None):
            print("Staking", srmAvailable["MSRM"], "MSRM")
            restBot.stake_request("MSRM", srmAvailable["MSRM"])
        if (srmAvailable["MSRM_LOCKED"] != None):
            print("Staking", srmAvailable["MSRM_LOCKED"], "MSRM_LOCKED")
            restBot.stake_request("MSRM_LOCKED", srmAvailable["MSRM_LOCKED"])
        print("Stake complete, waiting for the next hour...")
        sleep(3600)