Authentication Guide - Secure API Setup
Complete authentication setup guide for AxiomTradeAPI-py. Learn how to securely authenticate with Axiom Trade API for professional trading bot development.
Authentication Guide - AxiomTradeAPI-py | Secure Solana Trading Bot Setup
Complete Authentication Setup for Axiom Trade API Integration
Secure authentication is crucial for professional Solana trading bots and DeFi automation systems. This comprehensive guide covers everything you need to know about authenticating with the Axiom Trade API using our Python SDK.
π Authentication Overview
AxiomTradeAPI-py supports multiple authentication methods:
- Public Access - For basic balance queries and market data
- Authenticated Access - For WebSocket subscriptions and advanced features
- Production Authentication - Enterprise-grade security for trading bots
π Quick Authentication Setup
Basic Authentication (5 minutes)
For WebSocket features and real-time token monitoring:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| from axiomtradeapi import AxiomTradeClient
import os
# Store your tokens securely
AUTH_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
REFRESH_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
# Initialize authenticated client
client = AxiomTradeClient(
auth_token=AUTH_TOKEN,
refresh_token=REFRESH_TOKEN
)
print("π Authenticated client ready for advanced trading features!")
|
π Obtaining Authentication Tokens
- Visit Axiom Trade: Navigate to https://axiom.trade
- Login to Your Account: Sign in with your credentials
- Open Developer Tools: Press
F12
or right-click β βInspectβ
- Go to Application Tab: Navigate to Application β Storage β Cookies
- Find Your Tokens:
- Look for
auth-access-token
- Look for
auth-refresh-token
- Copy the Values: These are your authentication tokens
Method 2: Network Tab Method
- Open Network Tab: In developer tools, go to Network tab
- Make an API Request: Perform any action on Axiom Trade
- Check Request Headers: Look for requests to
axiom.trade/api
- Copy Cookie Header: Extract tokens from the Cookie header
Method 3: Programmatic Login (Advanced)
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
| import requests
import json
def login_to_axiom(username, password):
"""
Programmatic login to Axiom Trade
Returns authentication tokens for bot usage
"""
login_url = "https://axiom.trade/api/auth/login"
payload = {
"email": username,
"password": password
}
headers = {
"Content-Type": "application/json",
"Origin": "https://axiom.trade"
}
try:
response = requests.post(login_url, json=payload, headers=headers)
if response.status_code == 200:
# Extract tokens from response cookies
auth_token = response.cookies.get('auth-access-token')
refresh_token = response.cookies.get('auth-refresh-token')
return {
"auth_token": auth_token,
"refresh_token": refresh_token,
"success": True
}
else:
return {"success": False, "error": response.text}
except Exception as e:
return {"success": False, "error": str(e)}
# Usage
credentials = login_to_axiom("your-email@example.com", "your-password")
if credentials["success"]:
print("β
Login successful!")
print(f"Auth Token: {credentials['auth_token'][:20]}...")
else:
print(f"β Login failed: {credentials['error']}")
|
π‘οΈ Secure Token Management
Environment Variables (Recommended)
Never hardcode tokens in your source code:
1
2
3
| # .env file (never commit this to git!)
AXIOM_AUTH_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
AXIOM_REFRESH_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| # secure_trading_bot.py
import os
from dotenv import load_dotenv
from axiomtradeapi import AxiomTradeClient
# Load environment variables
load_dotenv()
# Secure authentication
client = AxiomTradeClient(
auth_token=os.getenv('AXIOM_AUTH_TOKEN'),
refresh_token=os.getenv('AXIOM_REFRESH_TOKEN')
)
print("π Securely authenticated trading bot ready!")
|
Production Secrets Management
For enterprise trading systems:
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
| # Using AWS Secrets Manager
import boto3
import json
def get_axiom_credentials():
"""Retrieve credentials from AWS Secrets Manager"""
client = boto3.client('secretsmanager', region_name='us-east-1')
try:
response = client.get_secret_value(SecretId='axiom-trade-credentials')
credentials = json.loads(response['SecretString'])
return {
'auth_token': credentials['auth_token'],
'refresh_token': credentials['refresh_token']
}
except Exception as e:
print(f"Failed to retrieve credentials: {e}")
return None
# Initialize with secure credentials
creds = get_axiom_credentials()
if creds:
client = AxiomTradeClient(
auth_token=creds['auth_token'],
refresh_token=creds['refresh_token']
)
|
Azure Key Vault Integration
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| from azure.keyvault.secrets import SecretClient
from azure.identity import DefaultAzureCredential
def get_credentials_from_keyvault():
"""Retrieve Axiom Trade credentials from Azure Key Vault"""
credential = DefaultAzureCredential()
client = SecretClient(
vault_url="https://your-keyvault.vault.azure.net/",
credential=credential
)
auth_token = client.get_secret("axiom-auth-token").value
refresh_token = client.get_secret("axiom-refresh-token").value
return auth_token, refresh_token
# Secure initialization
auth_token, refresh_token = get_credentials_from_keyvault()
client = AxiomTradeClient(
auth_token=auth_token,
refresh_token=refresh_token
)
|
π Token Refresh and Management
Automatic Token Refresh
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
| import time
import requests
from axiomtradeapi import AxiomTradeClient
class SecureAxiomClient:
def __init__(self, auth_token, refresh_token):
self.auth_token = auth_token
self.refresh_token = refresh_token
self.client = None
self.token_expiry = time.time() + 3600 # 1 hour default
self._initialize_client()
def _initialize_client(self):
"""Initialize the client with current tokens"""
self.client = AxiomTradeClient(
auth_token=self.auth_token,
refresh_token=self.refresh_token
)
def _refresh_tokens(self):
"""Refresh authentication tokens"""
refresh_url = "https://axiom.trade/api/auth/refresh"
headers = {
"Cookie": f"auth-refresh-token={self.refresh_token}"
}
try:
response = requests.post(refresh_url, headers=headers)
if response.status_code == 200:
self.auth_token = response.cookies.get('auth-access-token')
new_refresh = response.cookies.get('auth-refresh-token')
if new_refresh:
self.refresh_token = new_refresh
self.token_expiry = time.time() + 3600
self._initialize_client()
print("β
Tokens refreshed successfully")
return True
else:
print(f"β Token refresh failed: {response.status_code}")
return False
except Exception as e:
print(f"β Token refresh error: {e}")
return False
def ensure_valid_tokens(self):
"""Ensure tokens are valid before API calls"""
if time.time() >= self.token_expiry - 300: # Refresh 5 minutes early
return self._refresh_tokens()
return True
def get_balance(self, wallet_address):
"""Get balance with automatic token refresh"""
if not self.ensure_valid_tokens():
raise Exception("Failed to refresh authentication tokens")
return self.client.GetBalance(wallet_address)
# Usage
secure_client = SecureAxiomClient(
auth_token="your-auth-token",
refresh_token="your-refresh-token"
)
# Automatic token management
balance = secure_client.get_balance("BJBgjyDZx5FSsyJf6bFKVXuJV7DZY9PCSMSi5d9tcEVh")
print(f"Balance: {balance['sol']} SOL")
|
π§ͺ Testing Authentication
Authentication Validation Script
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
| import asyncio
from axiomtradeapi import AxiomTradeClient
async def test_authentication(auth_token, refresh_token):
"""Comprehensive authentication testing"""
print("π Testing Axiom Trade Authentication...")
print("=" * 50)
# Test 1: Basic authentication
try:
client = AxiomTradeClient(
auth_token=auth_token,
refresh_token=refresh_token
)
print("β
Authentication initialization: PASSED")
except Exception as e:
print(f"β Authentication failed: {e}")
return False
# Test 2: Authenticated API call
try:
balance = client.GetBalance("BJBgjyDZx5FSsyJf6bFKVXuJV7DZY9PCSMSi5d9tcEVh")
print(f"β
Authenticated API call: PASSED - {balance['sol']} SOL")
except Exception as e:
print(f"β API call failed: {e}")
return False
# Test 3: WebSocket authentication
try:
async def dummy_callback(tokens):
print(f"π‘ Received {len(tokens)} token updates")
await client.subscribe_new_tokens(dummy_callback)
print("β
WebSocket authentication: PASSED")
except Exception as e:
print(f"β WebSocket authentication failed: {e}")
return False
print("\nπ All authentication tests passed!")
print("π Ready for advanced Solana trading features!")
return True
# Run authentication tests
async def main():
AUTH_TOKEN = "your-auth-token-here"
REFRESH_TOKEN = "your-refresh-token-here"
await test_authentication(AUTH_TOKEN, REFRESH_TOKEN)
if __name__ == "__main__":
asyncio.run(main())
|
π¨ Security Best Practices
1. Token Storage Security
1
2
3
4
5
6
7
8
9
10
11
12
| # β NEVER do this - tokens exposed in code
client = AxiomTradeClient(
auth_token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", # BAD!
refresh_token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." # BAD!
)
# β
DO this - secure environment variables
import os
client = AxiomTradeClient(
auth_token=os.getenv('AXIOM_AUTH_TOKEN'),
refresh_token=os.getenv('AXIOM_REFRESH_TOKEN')
)
|
2. Token Rotation Strategy
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
| import schedule
import time
class TokenManager:
def __init__(self):
self.client = None
self.setup_auto_refresh()
def refresh_tokens_daily(self):
"""Refresh tokens daily for security"""
print("π Performing daily token refresh...")
# Implement token refresh logic
def setup_auto_refresh(self):
"""Setup automatic token refresh schedule"""
schedule.every(12).hours.do(self.refresh_tokens_daily)
# Run scheduler in background
def run_scheduler():
while True:
schedule.run_pending()
time.sleep(60)
import threading
scheduler_thread = threading.Thread(target=run_scheduler, daemon=True)
scheduler_thread.start()
|
3. Rate Limiting and Monitoring
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
| import time
import logging
from collections import deque
class RateLimitedAxiomClient:
def __init__(self, auth_token, refresh_token, max_requests_per_minute=60):
self.client = AxiomTradeClient(auth_token, refresh_token)
self.request_times = deque()
self.max_requests = max_requests_per_minute
# Setup monitoring
logging.basicConfig(level=logging.INFO)
self.logger = logging.getLogger(__name__)
def _check_rate_limit(self):
"""Ensure we don't exceed rate limits"""
now = time.time()
# Remove requests older than 1 minute
while self.request_times and self.request_times[0] < now - 60:
self.request_times.popleft()
if len(self.request_times) >= self.max_requests:
wait_time = 60 - (now - self.request_times[0])
self.logger.warning(f"Rate limit reached. Waiting {wait_time:.2f} seconds")
time.sleep(wait_time)
self.request_times.append(now)
def get_balance(self, wallet_address):
"""Rate-limited balance query"""
self._check_rate_limit()
return self.client.GetBalance(wallet_address)
|
π Integration Examples
Discord Bot Integration
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
| import discord
from discord.ext import commands
from axiomtradeapi import AxiomTradeClient
class SolanaBot(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.axiom_client = AxiomTradeClient(
auth_token=os.getenv('AXIOM_AUTH_TOKEN'),
refresh_token=os.getenv('AXIOM_REFRESH_TOKEN')
)
@commands.command(name='balance')
async def check_balance(self, ctx, wallet_address):
"""Check Solana wallet balance"""
try:
balance = self.axiom_client.GetBalance(wallet_address)
await ctx.send(f"π° Balance: {balance['sol']} SOL")
except Exception as e:
await ctx.send(f"β Error: {e}")
# Discord bot setup
bot = commands.Bot(command_prefix='!')
bot.add_cog(SolanaBot(bot))
bot.run(os.getenv('DISCORD_TOKEN'))
|
Telegram Bot Integration
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
| import telegram
from telegram.ext import Updater, CommandHandler
from axiomtradeapi import AxiomTradeClient
# Initialize Axiom client
axiom_client = AxiomTradeClient(
auth_token=os.getenv('AXIOM_AUTH_TOKEN'),
refresh_token=os.getenv('AXIOM_REFRESH_TOKEN')
)
def balance_command(update, context):
"""Telegram command to check wallet balance"""
if not context.args:
update.message.reply_text("Please provide a wallet address!")
return
wallet_address = context.args[0]
try:
balance = axiom_client.GetBalance(wallet_address)
update.message.reply_text(f"π° Balance: {balance['sol']} SOL")
except Exception as e:
update.message.reply_text(f"β Error: {e}")
# Setup Telegram bot
updater = Updater(token=os.getenv('TELEGRAM_TOKEN'))
updater.dispatcher.add_handler(CommandHandler('balance', balance_command))
updater.start_polling()
|
Monitor your authentication performance:
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
| import time
import statistics
class AuthMetrics:
def __init__(self):
self.response_times = []
self.success_count = 0
self.failure_count = 0
def record_request(self, start_time, success=True):
"""Record authentication request metrics"""
response_time = time.time() - start_time
self.response_times.append(response_time)
if success:
self.success_count += 1
else:
self.failure_count += 1
def get_stats(self):
"""Get authentication performance statistics"""
if not self.response_times:
return "No data available"
return {
"avg_response_time": statistics.mean(self.response_times),
"success_rate": self.success_count / (self.success_count + self.failure_count),
"total_requests": len(self.response_times)
}
# Usage
metrics = AuthMetrics()
start = time.time()
try:
balance = client.GetBalance(wallet_address)
metrics.record_request(start, success=True)
except:
metrics.record_request(start, success=False)
print(metrics.get_stats())
|
π― Next Steps
Now that you have secure authentication set up:
- WebSocket Integration - Real-time token monitoring
- Build Trading Bots - Automated trading strategies
- Performance Optimization - Scale your trading system
πΌ Professional Development Services
Need help with complex authentication scenarios or enterprise security?
Chipa.tech offers professional services:
- Custom authentication solutions
- Enterprise security implementations
- Multi-exchange integration
- 24/7 monitoring and support
Get Expert Help β
Visit Chipa.tech Shop for:
- Advanced authentication modules
- Security monitoring tools
- Enterprise trading solutions
- Professional support packages
Authentication guide by Chipa.tech - Your trusted partner for secure Solana trading automation