コード例 #1
0
ファイル: ftxtools.py プロジェクト: pymargot/margot
    def __init__(self, api_key, api_secret, subaccount, debug) -> None:

        self.client = ftx.FtxClient(api_key=api_key,
                                    api_secret=api_secret,
                                    subaccount_name=subaccount)

        for token in self.client.list_lts():
            lt = LeveragedToken(token)
            self.leveraged_tokens.append(lt)

        for future in self.client.get_futures():
            lt_list = [
                lt for lt in self.leveraged_tokens
                if lt.underlying == future['name']
            ]

            f = Future(future)
            f.set_lt_list(lt_list)
            self.futures.append(f)

        self.perps = [future for future in self.futures if future.perpetual]

        self.debug = debug
コード例 #2
0
import ftx
import requests
import config

api_endpoint = "https://ftx.com/api/markets/RAY-PERP/orderbook?depth=100"

client = ftx.FtxClient(api_key=config.API_KEY, api_secret=config.API_SECRET)

order_id_bid = 0
order_id_ask = 0
empty_bid = False
empty_ask = False
current_price_bid = 0
current_price_ask = 0


def process(json_data, count):
    global client
    global current_price_bid
    global current_price_ask
    global order_id_bid
    global order_id_ask
    global empty_bid
    global empty_ask

    min_k = 0
    max_k = 0
    k = 0
    k_target = 0
    max_target_found = False
    min_price_target_found = False
コード例 #3
0
import ftx
import pandas as pd
import numpy as np

myClient = ftx.FtxClient()


class Markets:
    def __init__(self):

        # Get all the perps

        self.futures = pd.DataFrame(myClient.list_futures())
        self.markets = pd.DataFrame(myClient.list_markets())
        self.futures_list = self.futures.name.tolist()

        # Just get the perps for now:

        self.only_perps = []

        [self.only_perps.append(f) for f in self.futures_list if 'PERP' in f]

    def get_liquidity(self, tolerable_slippage):

        # Get the liquidity

        tickers = self.only_perps

        pct = tolerable_slippage  # tolerable slippage %

        pct = pct / 100
コード例 #4
0
    def handle(self, *args, **options):

        platform = options['platform']
        logger.debug(f'Pulling data for {platform}')

        if platform not in ['kucoin', 'ftx']:
            logger.debug('Currently only ftx and kucoin are supported.')
            return

        current_datetime = timezone.now()

        if platform == 'ftx':
            # Init the API client
            client = ftx.FtxClient(api_key=settings.FTX_API_KEY,
                                   api_secret=settings.FTX_API_SECRET)

            lending_rates = client._get('spot_margin/lending_rates')

            logger.debug(f'Insert lending rates: {lending_rates}')

            # Bulk insert the new data
            model_instances = [
                LendingRate(platform=platform,
                            coin=res['coin'],
                            dt=current_datetime,
                            previous=res['previous'],
                            estimate=res['estimate']) for res in lending_rates
            ]
            LendingRate.objects.bulk_create(model_instances)
        elif platform == 'kucoin':
            # Init the Kucoin client
            market_client = kucoin_client.MarginData()
            currencies = ['USDT', 'USDC', 'BTC', 'ETH']
            terms = [7, 14, 28]
            lending_rates = []
            for currency in currencies:
                for term in terms:
                    # lending_market = market_client.get_lending_market(currency, term=term)
                    lending_market = market_client.get_margin_data(currency)
                    lending_market = [
                        f for f in lending_market if f['term'] == term
                    ]
                    count_els = len(lending_market)
                    if count_els == 0:
                        logger.debug(
                            f'No offers for {currency} ({term} days).Skip..')
                        continue
                    total_size = sum(
                        [float(l['size']) for l in lending_market])
                    mean_rate = sum(
                        [float(l['dailyIntRate'])
                         for l in lending_market]) / count_els
                    mean_hourly_rate = daily_to_hourly(mean_rate)
                    logger.debug(
                        f'For {currency} ({term} days) mean rate is {mean_rate}'
                    )
                    weighted_rate = sum([
                        float(l['dailyIntRate']) * float(l['size'])
                        for l in lending_market
                    ]) / total_size
                    weighted_hourly_rate = daily_to_hourly(weighted_rate)

                    lending_rate = {
                        'coin': currency,
                        'dt': current_datetime,
                        'previous': weighted_hourly_rate,
                        'estimate': weighted_hourly_rate,
                        'term': term
                    }
                    lending_rates.append(lending_rate)
            # Bulk insert the new data
            model_instances = [
                LendingRate(platform=platform,
                            coin=res['coin'],
                            dt=current_datetime,
                            previous=res['previous'],
                            estimate=res['estimate'],
                            term=res['term']) for res in lending_rates
            ]
            LendingRate.objects.bulk_create(model_instances)
コード例 #5
0
def lambda_handler(event, context):
    client = ftx.FtxClient(api_key=APIKEY, api_secret=APISECRET)
    result = client.get_lending_rates()
    #print(result)
    # AAVE
    AAVErates = json.dumps(result[2])
    AAVE = json.loads(AAVErates)
    AAVEestimate = (AAVE['estimate']) * 1000000
    AAVEprevious = (AAVE['previous']) * 1000000
    AAVEstre = str(AAVEestimate) + '%'
    AAVEstrp = str(AAVEprevious) + '%'

    # BTC
    BTCrates = json.dumps(result[62])
    BTC = json.loads(BTCrates)
    BTCestimate = (BTC['estimate']) * 1000000
    BTCprevious = (BTC['previous']) * 1000000
    BTCstre = str(BTCestimate) + '%'
    BTCstrp = str(BTCprevious) + '%'

    # CEL
    CELrates = json.dumps(result[27])
    CEL = json.loads(CELrates)
    CELestimate = (CEL['estimate']) * 1000000
    CELprevious = (CEL['previous']) * 1000000
    CELstre = str(CELestimate) + '%'
    CELstrp = str(CELprevious) + '%'

    # ETH
    ETHrates = json.dumps(result[33])
    ETH = json.loads(ETHrates)
    ETHestimate = (ETH['estimate']) * 1000000
    ETHprevious = (ETH['previous']) * 1000000
    ETHstre = str(ETHestimate) + '%'
    ETHstrp = str(ETHprevious) + '%'

    # EUR
    EURrates = json.dumps(result[35])
    EUR = json.loads(EURrates)
    EURestimate = (EUR['estimate']) * 1000000
    EURprevious = (EUR['previous']) * 1000000
    EURstre = str(EURestimate) + '%'
    EURstrp = str(EURprevious) + '%'

    # GBP
    GBPrates = json.dumps(result[37])
    GBP = json.loads(GBPrates)
    GBPestimate = (GBP['estimate']) * 1000000
    GBPprevious = (GBP['previous']) * 1000000
    GBPstre = str(GBPestimate) + '%'
    GBPstrp = str(GBPprevious) + '%'

    # LINK
    LINKrates = json.dumps(result[49])
    LINK = json.loads(LINKrates)
    LINKestimate = (LINK['estimate']) * 1000000
    LINKprevious = (LINK['previous']) * 1000000
    LINKstre = str(LINKestimate) + '%'
    LINKstrp = str(LINKprevious) + '%'

    # PAXG
    PAXGrates = json.dumps(result[62])
    PAXG = json.loads(PAXGrates)
    PAXGestimate = (PAXG['estimate']) * 1000000
    PAXGprevious = (PAXG['previous']) * 1000000
    PAXGstre = str(PAXGestimate) + '%'
    PAXGstrp = str(PAXGprevious) + '%'

    # TOMO
    TOMOrates = json.dumps(result[75])
    TOMO = json.loads(TOMOrates)
    TOMOestimate = (TOMO['estimate']) * 1000000
    TOMOprevious = (TOMO['previous']) * 1000000
    TOMOstre = str(TOMOestimate) + '%'
    TOMOstrp = str(TOMOprevious) + '%'

    # USD
    USDrates = json.dumps(result[83])
    USD = json.loads(USDrates)
    USDestimate = (USD['estimate']) * 1000000
    USDprevious = (USD['previous']) * 1000000
    USDstre = str(USDestimate) + '%'
    USDstrp = str(USDprevious) + '%'

    # USDT
    USDTrates = json.dumps(result[84])
    USDT = json.loads(USDTrates)
    USDTestimate = (USDT['estimate']) * 1000000
    USDTprevious = (USDT['previous']) * 1000000
    USDTstre = str(USDTestimate) + '%'
    USDTstrp = str(USDTprevious) + '%'

    # YFI
    YFIrates = json.dumps(result[89])
    YFI = json.loads(YFIrates)
    YFIestimate = (YFI['estimate']) * 1000000
    YFIprevious = (YFI['previous']) * 1000000
    YFIstre = str(YFIestimate) + '%'
    YFIstrp = str(YFIprevious) + '%'

    # WBTC
    WBTCrates = json.dumps(result[86])
    WBTC = json.loads(WBTCrates)
    WBTCestimate = (WBTC['estimate']) * 1000000
    WBTCprevious = (WBTC['previous']) * 1000000
    WBTCstre = str(WBTCestimate) + '%'
    WBTCstrp = str(WBTCprevious) + '%'

    msg = ('\nAAVE estimate ' + AAVEstre + '\nAAVE previous ' + AAVEstrp +
           '\nBTC estimate ' + BTCstre + '\nBTC previous ' + BTCstrp +
           '\nCEL estimate ' + CELstre + '\nCEL previous ' + CELstrp +
           '\nETH estimate ' + ETHstre + '\nETH previous ' + ETHstrp +
           '\nEUR estimate ' + EURstre + '\nEUR previous ' + EURstrp +
           '\nGBP estimate ' + GBPstre + '\nGBP previous ' + GBPstrp +
           '\nLINK estimate ' + LINKstre + '\nLINK previous ' + LINKstrp +
           '\nPAXG estimate ' + PAXGstre + '\nPAXG previous ' + PAXGstrp +
           '\nTOMO estimate ' + TOMOstre + '\nTOMO previous ' + TOMOstrp +
           '\nUSD estimate ' + USDstre + '\nUSD previous ' + USDstrp +
           '\nUSDT estimate ' + USDTstre + '\nUSDT previous ' + USDTstrp +
           '\nYFI estimate ' + YFIstre + '\nYFI previous ' + YFIstrp +
           '\nWBTC estimate ' + WBTCstre + '\nWBTC previous ' + WBTCstrp)
    mailer_func(fromaddress, toaddress, msg, status, DATEDB, AAVEestimate,
                BTCestimate, CELestimate, ETHestimate, EURestimate,
                GBPestimate, LINKestimate, PAXGestimate, TOMOestimate,
                USDestimate, USDTestimate, YFIestimate, WBTCestimate)
コード例 #6
0
    except:
        pass


def read_setting():
    with open("setting.json") as json_file:
        return json.load(json_file)


config = read_setting()
LOGFILE = config["LOGFILE"]


client = ftx.FtxClient(
    api_key=config["apiKey"],
    api_secret=config["secret"],
    subaccount_name=config["sub_account"],
)

main_job = Grid_trader(
    client,
    config["symbol"],
    config["grid_level"],
    config["lower_price"],
    config["upper_price"],
    config["amount"],
)
main_job.place_order_init()
while True:
    try:
        print(f"Loop in: {datetime.datetime.now()}, order list size {len(main_job.order_list)}")
コード例 #7
0
ファイル: Main.py プロジェクト: wei1769/FTX-Oxy-bot
#run 'pip3 install ftx' first 
import ftx 
import sys 
apikey = ''  #api key
apisecret = ''  #api secret
limitPrice = #Price to bid
size =      #Size to bid 
client = ftx.FtxClient(api_key = apikey, api_secret = apisecret)
sys.tracebacklimit = 0
while 1 :
    try:
        client.place_order('OXY/USD', 'buy', limitPrice,size )
    except Exception:
        pass