Rename README.md to README.mdautodelegator

#2
by XRPEASY - opened

import ccxt
import time
from datetime import datetime, timedelta
import requests # For FTSO performance data

====== FTSO DELEGATION CONFIG ======

FTSO_API = "https://ftso-api.flare.network" # Example FTSO stats endpoint
DELEGATION_SPLIT = [0.5, 0.5] # 50% to top 2 providers
DELEGATION_CONTRACT = "0xFLARE_FTSO_CONTRACT_ADDRESS" # From Flare docs

====== ENHANCED BIFROST CLASS ======

class BifrostFTSO(ccxt.bifrost):
def delegate(self, provider_address, amount):
"""Send delegation transaction via Bifrost"""
return self.privatePostDelegate({
'provider': provider_address,
'amount': str(amount),
'currency': 'FLR' # or 'SGB' for Songbird
})

====== DELEGATION FUNCTIONS ======

def get_top_ftso_providers(network='flare'):
"""Fetch previous month's best FTSO performers"""
try:
end_date = datetime.utcnow().replace(day=1) - timedelta(days=1)
start_date = end_date.replace(day=1)

    response = requests.get(
        f"{FTSO_API}/providers/{network}",
        params={'from': start_date.isoformat(), 'to': end_date.isoformat()}
    )
    
    providers = sorted(
        response.json()['providers'],
        key=lambda x: x['score'],
        reverse=True
    )[:2]
    
    return [p['address'] for p in providers]

except Exception as e:
    print(f"⚠️ FTSO API Error: {e}")
    return ['DEFAULT_PROVIDER_1', 'DEFAULT_PROVIDER_2']  # Fallback addresses

def auto_delegate(balance, currency='FLR'):
"""Delegate 50/50 to top providers"""
providers = get_top_ftso_providers('coston' if currency == 'SGB' else 'flare')
amounts = [balance * split for split in DELEGATION_SPLIT]

print(f"\n🔹 Auto-Delegating {currency}:")
for provider, amount in zip(providers, amounts):
    try:
        # Convert to smallest unit (e.g., wei)
        decimal_amount = int(amount * 1e18)
        exchange.delegate(provider, decimal_amount)
        print(f" - {amount} {currency} → {provider[:12]}...")
    except Exception as e:
        print(f"❌ Delegation failed to {provider[:12]}: {str(e)}")

====== UPDATED MAIN LOOP ======

def main():
last_delegation = None
while True:
# ... (existing trading logic)

    # Monthly delegation on 1st day
    now = datetime.utcnow()
    if (now.day == 1 and 
        (not last_delegation or 
         (now - last_delegation).days >= 28)):
        
        print("\n=== FTSO REBALANCING ===")
        flr_balance = exchange.fetch_balance()['FLR']['free']
        sgb_balance = exchange.fetch_balance()['SGB']['free']
        
        auto_delegate(flr_balance * 0.5, 'FLR')  # Delegate 50% of FLR
        auto_delegate(sgb_balance * 0.5, 'SGB')  # Delegate 50% of SGB
        
        last_delegation = now
    
    time.sleep(86400)  # Check daily

====== INITIALIZATION ======

exchange = BifrostFTSO({
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_SECRET_KEY',
'enableRateLimit': True
})

if name == "main":
main()

date,address,score,asset
2024-03-01,0xProvider1,98.7,FLR
2024-03-01,0xProvider2,95.2,FLR
2024-03-01,0xProviderA,89.1,SGB
timestamp,symbol,price
2024-03-01T00:00:00,FLR/SGB,0.024
2024-03-01T00:05:00,FLR/SGB,0.0238

{
"testnet": true,
"api_key": "your_testnet_key",
"api_secret": "your_testnet_secret",
"max_risk": 0.2,
"delegation_split": [0.5, 0.5],
"assets": {
"FLR": {"support": [0.02, 0.018], "resistance": [0.025, 0.03]},
"SGB": {"support": [0.006, 0.005], "resistance": [0.007, 0.01]}
}
}
{
"testnet": true,
"api_key": "your_testnet_key",
"api_secret": "your_testnet_secret",
"max_risk": 0.2,
"delegation_split": [0.5, 0.5],
"assets": {
"FLR": {"support": [0.02, 0.018], "resistance": [0.025, 0.03]},
"SGB": {"support": [0.006, 0.005], "resistance": [0.007, 0.01]}
}
}

Install dependencies

pip install ccxt pandas python-dotenv

Run in test mode (uses mock data)

python trading_bot.py

Switch to live mode

Update config.json with live API keys and set "testnet": false

SmartSelect_20250128_010020_Perplexity.jpg

XRPEASY changed pull request status to merged

Built to Accumulate Flare & Songbird auto delegate 50% to each of the previous months best performing FTSOs XRPEASY EARN

Sign up or log in to comment