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()))
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)
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
from client import FtxClient import configparser import schedule import os import datetime as dt import time import csv import math DATA_PATH = 'data.csv' config = configparser.ConfigParser() config.read('config.ini') client = FtxClient(api_key=config['ftx']['api'], api_secret=config['ftx']['secret'], subaccount_name='Lending') coins = ['USD', 'USDT'] headers = ['datetime'] + [c + ' APR' for c in coins] + [c + ' APY' for c in coins] def convert_to_apr(hourly_rate): return round(hourly_rate * 24 * 365, 3) def convert_to_apy(hourly_rate): return round((1 + (hourly_rate * 24))**365, 3)
# -*- coding: utf-8 -*- """ Created on Sat Feb 22 16:47:10 2020 @author: Aayushi Shah """ from client import FtxClient, FtxWebsocketClient YOUR_API_KEY = 'YOUR_API_KEY' YOUR_API_SECRET = 'YOUR_API_SECRET' # Initialise a new client called 'rest' rest = FtxClient(api_key=YOUR_API_KEY, api_secret=YOUR_API_SECRET) # Mention the market of interest market_name = 'BCH-PERP' # Bitcoin Cash Perpetual Futures # Get orderbook for that market rest_orderbook = rest.get_orderbook(market_name) # Initialise a new client called 'socket' socket = FtxWebsocketClient() # Get orderbook for that market socket_orderbook = socket.get_orderbook(market_name) # Prints the orderbook on REST and on Socket print(f'Order book on REST\n{rest_orderbook}') print(f'Order book on Socket\n{socket_orderbook}') # Places market order
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)
else: resp = clientFTX.place_order(market=market, side="sell", price=None, type="market", size=size / 100) print(resp) else: return answer = discord.Embed( title="Processing trade signal", description= f"""Time to make it happen.\n\n`Server` : **{message.guild.name}**\n`Action` : **{action}**\n`Price` : **"{price}"**"\n`Market` : **"{market}"**""", colour=0x1a7794) await message.channel.send(embed=answer) if __name__ == '__main__': clientFTX = FtxClient('API_PUBLIC', 'API_SECRET', subaccount_name="Bot") ts = int(time.time() * 1000) request = Request('GET', FtxClient._ENDPOINT) prepared = request.prepare() signature_payload = f'{ts}{prepared.method}{prepared.path_url}'.encode() signature = hmac.new('API_SECRET'.encode(), signature_payload, 'sha256').hexdigest() request.headers['FTX-KEY'] = 'API_PUBLIC' request.headers['FTX-SIGN'] = signature response = request.headers['FTX-TS'] = str(ts) client.run('___')