File size: 10,837 Bytes
da0ce7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/usr/bin/env python3
"""

Verify connectivity and portfolio state across all trading platforms

KRAKEN | BINANCE | CAPITAL.COM

"""

from aureon_baton_link import link_system as _baton_link; _baton_link(__name__)
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

from kraken_client import KrakenClient, get_kraken_client
from binance_client import BinanceClient
from capital_client import CapitalClient
import json
from datetime import datetime

def check_kraken():
    """Check Kraken connectivity and portfolio"""
    print("\n" + "="*80)
    print("πŸ™ KRAKEN - Connectivity & Portfolio Check")
    print("="*80)
    
    try:
        client = get_kraken_client()
        
        # Check API connectivity
        print("βœ… API Connection: SUCCESS")
        
        # Get balance via account()
        account_data = client.account()
        print(f"\nπŸ’° KRAKEN BALANCES:")
        total_gbp = 0
        holdings = []
        
        for bal in account_data.get('balances', []):
            asset = bal.get('asset', '')
            amount = float(bal.get('free', 0))
            
            if amount > 0.00001:
                # Get GBP value
                try:
                    if asset in ['GBP', 'ZGBP', 'EUR', 'ZEUR']:
                        value_gbp = amount if asset.startswith('GBP') else amount * 0.87
                    else:
                        # Get price vs GBP
                        symbol = f"{asset}GBP" if asset not in ['BTC', 'XBT'] else "XBTGBP"
                        price = client.get_current_price(symbol)
                        value_gbp = amount * price if price else 0
                except:
                    value_gbp = 0
                
                total_gbp += value_gbp
                holdings.append({
                    'asset': asset,
                    'amount': amount,
                    'value_gbp': value_gbp
                })
                print(f"  {asset:8s}: {amount:>15.8f} (Β£{value_gbp:>10.2f})")
        
        print(f"\nπŸ“Š Total Portfolio Value: Β£{total_gbp:.2f}")
        
        # Check tradeable pairs
        print(f"\nπŸ”„ Checking tradeable pairs...")
        pairs = ['BTCUSD', 'ETHUSD', 'XRPUSD', 'ADAUSD', 'SOLUSD']
        tradeable = []
        for pair in pairs:
            try:
                price = client.get_current_price(pair)
                if price:
                    tradeable.append(pair)
                    print(f"  βœ… {pair}: Β£{price:,.2f}")
            except:
                print(f"  ❌ {pair}: Not available")
        
        return {
            'platform': 'KRAKEN',
            'status': 'CONNECTED',
            'total_value_gbp': total_gbp,
            'holdings': holdings,
            'tradeable_pairs': tradeable
        }
        
    except Exception as e:
        print(f"❌ KRAKEN ERROR: {e}")
        return {'platform': 'KRAKEN', 'status': 'ERROR', 'error': str(e)}

def check_binance():
    """Check Binance connectivity and portfolio"""
    print("\n" + "="*80)
    print("🟑 BINANCE - Connectivity & Portfolio Check")
    print("="*80)
    
    try:
        client = get_binance_client()
        
        # Check API connectivity
        print("βœ… API Connection: SUCCESS")
        
        # Get balance via account()
        account_data = client.account()
        print(f"\nπŸ’° BINANCE BALANCES:")
        total_gbp = 0
        holdings = []
        
        # Get GBP/USDT rate for conversions
        try:
            gbp_usdt_rate = client.get_current_price("GBPUSDT")
        except:
            gbp_usdt_rate = 1.27  # Fallback
        
        for bal in account_data.get('balances', []):
            asset = bal.get('asset', '')
            amount = float(bal.get('free', 0))
            
            if amount > 0.0001:  # Filter dust
                # Get price in GBP
                try:
                    if asset == 'GBP':
                        value_gbp = amount
                    elif asset == 'USDT':
                        value_gbp = amount / gbp_usdt_rate
                    else:
                        # Try to get USDT price first, then convert
                        usdt_price = client.get_current_price(f"{asset}USDT")
                        value_gbp = (amount * usdt_price) / gbp_usdt_rate if usdt_price else 0
                    
                    total_gbp += value_gbp
                    holdings.append({
                        'asset': asset,
                        'amount': amount,
                        'value_gbp': value_gbp
                    })
                    print(f"  {asset:8s}: {amount:>15.8f} (Β£{value_gbp:>10.2f})")
                except Exception as e:
                    print(f"  {asset:8s}: {amount:>15.8f} (price unavailable)")
        
        print(f"\nπŸ“Š Total Portfolio Value: Β£{total_gbp:.2f}")
        
        # Check tradeable pairs
        print(f"\nπŸ”„ Checking tradeable pairs...")
        pairs = ['BTCUSDT', 'ETHUSDT', 'XRPUSDT', 'ADAUSDT', 'SOLUSDT']
        tradeable = []
        for pair in pairs:
            try:
                price = client.get_current_price(pair)
                if price:
                    tradeable.append(pair)
                    print(f"  βœ… {pair}: ${price:,.2f}")
            except:
                print(f"  ❌ {pair}: Not available")
        
        return {
            'platform': 'BINANCE',
            'status': 'CONNECTED',
            'total_value_gbp': total_gbp,
            'holdings': holdings,
            'tradeable_pairs': tradeable
        }
        
    except Exception as e:
        print(f"❌ BINANCE ERROR: {e}")
        return {'platform': 'BINANCE', 'status': 'ERROR', 'error': str(e)}

def check_capital():
    """Check Capital.com connectivity and portfolio"""
    print("\n" + "="*80)
    print("πŸ›οΈ CAPITAL.COM - Connectivity & Portfolio Check")
    print("="*80)
    
    try:
        client = CapitalClient()
        
        # Check API connectivity
        print("βœ… API Connection: SUCCESS")
        
        # Get balance via get_account_balance()
        balance_data = client.get_account_balance()
        print(f"\nπŸ’° CAPITAL.COM BALANCES:")
        
        total_gbp = balance_data.get('GBP', 0)
        available = balance_data.get('available', total_gbp)
        
        print(f"  Total Balance:    Β£{total_gbp:,.2f}")
        print(f"  Available:        Β£{available:,.2f}")
        print(f"  In Positions:     Β£{total_gbp - available:,.2f}")
        
        # Get open positions
        positions = client.get_positions()
        print(f"\nπŸ“Š OPEN POSITIONS: {len(positions)}")
        position_data = []
        
        for pos in positions:
            pos_value = abs(pos.get('size', 0) * pos.get('level', 0))
            pnl = pos.get('profit', 0)
            position_data.append({
                'symbol': pos.get('market', 'N/A'),
                'direction': pos.get('direction', 'N/A'),
                'size': pos.get('size', 0),
                'level': pos.get('level', 0),
                'value': pos_value,
                'pnl': pnl
            })
            print(f"  {pos.get('market', 'N/A'):12s} {pos.get('direction', 'N/A'):5s} "
                  f"Size: {pos.get('size', 0):>10.4f} @ Β£{pos.get('level', 0):>10.2f} "
                  f"P&L: Β£{pnl:>+8.2f}")
        
        # Check tradeable instruments
        print(f"\nπŸ”„ Checking tradeable instruments...")
        instruments = ['BITCOIN', 'ETHEREUM', 'RIPPLE', 'CARDANO', 'SOLANA']
        tradeable = []
        for inst in instruments:
            try:
                price = client.get_current_price(inst)
                if price:
                    tradeable.append(inst)
                    print(f"  βœ… {inst}: Β£{price:,.2f}")
            except:
                print(f"  ❌ {inst}: Not available")
        
        return {
            'platform': 'CAPITAL.COM',
            'status': 'CONNECTED',
            'total_value_gbp': total_gbp,
            'available_gbp': available,
            'positions': position_data,
            'tradeable_instruments': tradeable
        }
        
    except Exception as e:
        print(f"❌ CAPITAL.COM ERROR: {e}")
        return {'platform': 'CAPITAL.COM', 'status': 'ERROR', 'error': str(e)}

def main():
    """Execute platform checks and generate report"""
    print("\n" + "β•”" + "="*78 + "β•—")
    print("β•‘" + " "*20 + "🌐 MULTI-PLATFORM CONNECTIVITY CHECK" + " "*22 + "β•‘")
    print("β•š" + "="*78 + "╝")
    
    timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    print(f"\nπŸ• Timestamp: {timestamp}")
    
    # Check all platforms
    kraken_data = check_kraken()
    binance_data = check_binance()
    capital_data = check_capital()
    
    # Generate summary
    print("\n" + "="*80)
    print("πŸ“Š SUMMARY REPORT")
    print("="*80)
    
    all_data = [kraken_data, binance_data, capital_data]
    
    total_portfolio_gbp = sum(d.get('total_value_gbp', 0) for d in all_data if d.get('status') == 'CONNECTED')
    connected_count = sum(1 for d in all_data if d.get('status') == 'CONNECTED')
    
    print(f"\nβœ… Connected Platforms: {connected_count}/3")
    print(f"πŸ’° Total Portfolio Value: Β£{total_portfolio_gbp:,.2f}")
    
    for data in all_data:
        status = "🟒" if data.get('status') == 'CONNECTED' else "πŸ”΄"
        value = f"Β£{data.get('total_value_gbp', 0):,.2f}" if data.get('status') == 'CONNECTED' else "N/A"
        print(f"  {status} {data['platform']:15s} - {value}")
    
    # Save to file
    report_file = f"/tmp/platform_connectivity_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
    report_data = {
        'timestamp': timestamp,
        'platforms': all_data,
        'summary': {
            'connected': connected_count,
            'total_value_gbp': total_portfolio_gbp
        }
    }
    
    with open(report_file, 'w') as f:
        json.dump(report_data, f, indent=2)
    
    print(f"\nπŸ“ Report saved: {report_file}")
    
    # Trading readiness check
    print("\n" + "="*80)
    print("🎯 TRADING READINESS")
    print("="*80)
    
    if connected_count == 3:
        print("βœ… All platforms connected - READY FOR LIVE TRADING")
        print(f"βœ… Total capital available: Β£{total_portfolio_gbp:,.2f}")
        print("βœ… Multi-exchange arbitrage: ENABLED")
    else:
        print("⚠️  Not all platforms connected - check errors above")
    
    return report_data

if __name__ == "__main__":
    main()