Authentication Guide
Smart Money API ကို API keys၊ JWT tokens နှင့် OAuth 2.0 များဖြင့် အတည်ပြုနည်းကို လေ့လာပါ။ စက်မှုစံနှုန်းများနှင့်အညီ အတည်ပြုနည်းများနှင့် အကောင်းဆုံးအလေ့အကျင့်များဖြင့် သင့်ပေါင်းစပ်မှုများကို လုံခြုံစေပါ။
Overview
Smart Money API သည် အသုံးပြုမှုအမျိုးမျိုးအတွက် အတည်ပြုနည်းများစွာကို ပံ့ပိုးပေးသည်။ သင့်ပေါင်းစပ်မှုနှင့် အသင့်လျော်ဆုံးနည်းလမ်းကို ရွေးချယ်ပါ-
API Keys (primary): သင့်သော့ကို X-API-Key request header တွင် ထည့်သွင်းပါ။ REST API ခေါ်ဆိုမှုအားလုံးအတွက် ဤနည်းလမ်းကို bots နှင့် server-to-server အသုံးပြုမှုများအတွက် အကြံပြုထားသည်။
Session JWT (fallback): Browser/dashboard sessions များသည် session JWT ဖြင့် အတည်ပြုသည်။ Authorization: Bearer, ၂၄ နာရီအတွက် မှန်ကန်သည်။ Programmatic clients များသည် X-API-Key.
OAuth 2.0: Enterprise-grade authentication သည် multi-user applications နှင့် third-party integrations များအတွက်ဖြစ်သည်။ သင့်အက်ပ်ကို ၎င်းတို့၏ဒေတာများကို အသုံးပြုခွင့်ပေးရန် အသုံးပြုသူများက ခွင့်ပြုပေးသည်။
API requests အားလုံးကို HTTPS ဖြင့်သာ ပြုလုပ်ရမည်။ Unencrypted HTTP requests များကို ငြင်းပယ်မည်။ ထို့အပြင် API keys များကို version control တွင် မထည့်သွင်းပါနှင့် သို့မဟုတ် အများသိအောင် မပြုလုပ်ပါနှင့်။
API Keys
API keys များသည် သင့်အကောင့်အတွက် ထုတ်ပေးထားသော ထူးခြားသည့် အထောက်အထားများဖြစ်သည်။ သော့တစ်ခုစီသည် permission နှင့် quota တစ်စုံကို ကိုယ်စားပြုသည်။ သင့်အနေဖြင့် မတူညီသော applications သို့မဟုတ် environments (development, staging, production) များအတွက် သော့များစွာကို ထုတ်နိုင်သည်။
Generating an API Key
သင့်အကောင့် console မှ API keys များကို ထုတ်ပါ-
- Navigate to Smart Money Console
- Select "API Keys" from the sidebar
- Click "Generate New Key"
- Choose key type (Development, Staging, Production)
- Set rate limit and features
- Copy and store the key securely
သင့် API key ကို ချက်ချင်းသိမ်းဆည်းပါ! နောက်တစ်ကြိမ် ပြန်မြင်ရမည်မဟုတ်ပါ။ ပျောက်ဆုံးပါက အသစ်ထုတ်ရန် လိုအပ်မည်။
Key Format
API keys များသည် စံဖော်မတ်ကို လိုက်နာသည်-
sk_live_4e3e4d0f1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z
sk_test_8f4g5h6i7j8k9l0m1n2o3p4q5r6s7t8u9v0w1x2y3z4a5b6c7d8e9f
sk_dev_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6a7b
Key prefixes များသည် environment ကို ဖော်ပြသည်-
sk_live_ — Production keys with full quota
sk_test_ — Testing keys with reduced quota and development data
sk_dev_ — Personal development keys with sandbox data
X-API-Key Header (primary)
သင့် API key ကို X-API-Key request header တွင် ထည့်သွင်းပါ။ သင့်သော့ကို URL တွင် ဘယ်သောအခါမှ မထည့်ပါနှင့်။
HTTP Header
GET /v1/whales/events HTTP/1.1
Host: api.smartmoneyapi.com
X-API-Key: sm_your_key
Content-Type: application/json
cURL နမူနာ
curl -X GET https://api.smartmoneyapi.com/v1/whales/events \
-H "X-API-Key: sm_your_key" \
-H "Content-Type: application/json"
Python နမူနာ
import requests
api_key = "sm_your_key"
headers = {
"X-API-Key": api_key,
"Content-Type": "application/json"
}
response = requests.get(
"https://api.smartmoneyapi.com/v1/whales/events",
headers=headers
)
data = response.json()
JWT Token Authentication
ရေရှည်အသုံးပြုမှုများနှင့် server-to-server ဆက်သွယ်မှုများအတွက်၊ သင့် API key ကို JWT token နှင့်လဲလှယ်ပါ။ JWT token များသည် ၂၄ နာရီကြာရှည်ပြီး သင့် application code တွင် API key ကိုသိမ်းဆည်းရန်လိုအပ်ချက်ကိုလျှော့ချပေးသည်။
JWT Token ရယူခြင်း
Token တစ်ခုရရှိရန် သင့် API key ကို JWT endpoint သို့ POST လုပ်ပါ။
curl -X POST https://api.smartmoneyapi.com/auth/jwt \
-H "Content-Type: application/json" \
-d '{
"api_key": "sk_live_4e3e4d0f1b2c3d4e5f6g7h8i9j0k1l2m"
}'
JWT Response
{
"success": true,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
"expires_in": 86400,
"token_type": "Bearer"
}
JWT Token အသုံးပြုခြင်း
API keys များကဲ့သို့ပင် JWT token ကို Authorization header တွင်အသုံးပြုပါ။
import requests
import json
from datetime import datetime, timedelta
class JWTAuth:
def __init__(self, api_key):
self.api_key = api_key
self.token = None
self.token_expires = None
def get_valid_token(self):
# Check if current token is still valid
if self.token and self.token_expires > datetime.now():
return self.token
# Get new token
response = requests.post(
"https://api.smartmoneyapi.com/auth/jwt",
json={"api_key": self.api_key}
)
data = response.json()
self.token = data["token"]
self.token_expires = datetime.now() + timedelta(seconds=data["expires_in"])
return self.token
def request(self, method, url, **kwargs):
token = self.get_valid_token()
headers = kwargs.get("headers", {})
headers["Authorization"] = f"Bearer {token}"
kwargs["headers"] = headers
return requests.request(method, url, **kwargs)
# Usage
auth = JWTAuth("sk_live_4e3e4d0f1b2c3d4e5f6g7h8i9j0k1l2m")
response = auth.request(
"GET",
"https://api.smartmoneyapi.com/v1/whales/events"
)
print(response.json())
OAuth 2.0
OAuth 2.0 သည် user account များစွာကိုအသုံးပြုရန်လိုအပ်သော applications များအတွက်ဖြစ်သည်။ Users များသည် သင့်အား သူတို့၏ API keys များကိုမျှဝေခြင်းမရှိဘဲ သူတို့၏ data များကိုအသုံးပြုခွင့်ပေးနိုင်သည်။
OAuth 2.0 Flow
Smart Money API သည် web applications များအတွက် Authorization Code flow ကိုထောက်ပံ့ပေးသည်။
- User သည် "Connect with Smart Money" button ကိုနှိပ်ပါ။
- Browser သည် authorization page သို့ redirect လုပ်ပါမည်။
- User သည် သင့် application အား permission ပေးပါမည်။
- Browser သည် authorization code နှင့်အတူ ပြန်လည် redirect လုပ်ပါမည်။
- သင့် backend သည် code ကို access token အဖြစ်လဲလှယ်ပါမည်။
- ယခု သင့်အနေဖြင့် user ၏ data များကို သူတို့၏ဘက်မှ access လုပ်နိုင်ပါပြီ။
အဆင့် ၁: Authorization Request
User အား authorization endpoint သို့ redirect လုပ်ပါ။
https://auth.smartmoneyapi.com/authorize?
client_id=YOUR_CLIENT_ID&
redirect_uri=https://yourapp.com/callback&
response_type=code&
scope=whale_positions+funding_rates+liquidations&
state=random_state_string
အဆင့် ၂: Token Exchange
User မှ permission ပေးပြီးနောက်၊ code ကို access token အဖြစ်လဲလှယ်ပါ။
curl -X POST https://auth.smartmoneyapi.com/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code&code=AUTH_CODE&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&redirect_uri=https://yourapp.com/callback"
OAuth Token Response
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "rt_1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p",
"scope": "whale_positions funding_rates liquidations"
}
Security Best Practices
Keys များကို လုံခြုံစွာသိမ်းဆည်းပါ။
API keys များကို version control တွင် commit မလုပ်ပါနှင့်၊ applications တွင်မထည့်ပါနှင့်၊ သို့မဟုတ် documentation တွင်မျှဝေပါနှင့်။ Environment variables များ သို့မဟုတ် AWS Secrets Manager, HashiCorp Vault ကဲ့သို့သော secure key management services များကိုအသုံးပြုပါ။
HTTPS ကိုသာအသုံးပြုပါ။
API request အားလုံးသည် HTTPS (TLS 1.2 သို့မဟုတ် ပိုမိုမြင့်မားသော) ကိုအသုံးပြုရမည်။ HTTP requests များကိုငြင်းပယ်ပါမည်။ ၎င်းသည် သင့် API key နှင့် data များကို transit တွင်လုံခြုံစေသည်။
Key Permissions များကိုကန့်သတ်ပါ။
Applications နှင့် environments အမျိုးမျိုးအတွက် API keys များကိုသီးသန့်ဖန်တီးပါ။ Key တစ်ခုစီ၏ access ကိုကန့်သတ်ရန် scopes များကိုအသုံးပြုပါ။ Development တွင် production keys များကိုမသုံးပါနှင့်။
Key Usage ကိုစောင့်ကြည့်ပါ။
သင့် console တွင် API usage ကိုပုံမှန်စစ်ဆေးပါ။ ပုံမှန်မဟုတ်သောလှုပ်ရှားမှုများ သို့မဟုတ် quota ကန့်သတ်ချက်နီးကပ်လာပါက alerts များထားပါ။ အသုံးမပြုတော့သော keys များကိုဖျက်ပါ။
Key Rotation
သင့် API keys များကိုပုံမှန်လည်ပတ်ပါ။ အန္တရာယ်ရှိမှုကိုလျှော့ချရန် keys များကို ၉၀ ရက်တစ်ကြိမ် rotate လုပ်ရန်အကြံပြုပါသည်။
- သင့် console တွင် API key အသစ်တစ်ခုကိုဖန်တီးပါ။
- သင့်အက်ပ်များကို အသစ်သောသော့ဖြင့် အသုံးပြုရန် အပ်ဒိတ်လုပ်ပါ
- အရာအားလုံး မှန်ကန်စွာအလုပ်လုပ်ကြောင်း စမ်းသပ်ပါ
- သင့်ကြန်ဆာမှ အိုလ်သော့ကို ဖျက်ပါ
အကောင့်အခွင့်အရေးများ
API သော့များဖန်တီးသည့်အခါ သို့မဟုတ် OAuth ကိုအသုံးပြုသည့်အခါ၊ သင့်သော့သည် မည်သည့်အရင်းအမြစ်များကို ဝင်ရောက်နိုင်သည်ကို သတ်မှတ်ပါ-
| အကောင့်အခွင့်အရေး |
ဖော်ပြချက် |
အဆင့် |
| whale_positions |
ဝေလငါးအိတ်ဆောင်အနေအထားများကိုဖတ်ပါ |
Trader+ |
| funding_rates |
ငွေကြေးထောက်ပံ့မှုဒေတာများကိုဖတ်ပါ |
Free+ |
| liquidations |
ဖျက်သိမ်းမှုဖိဒ်များကိုဖတ်ပါ |
Free+ |
| open_interest |
ဖွင့်ထားသောအကျိုးစီးပွားဒေတာများကိုဖတ်ပါ |
Trader+ |
| confirmation_scores |
AI အတည်ပြုချက်အမှတ်များကိုဖတ်ပါ |
Pro+ |
| on_chain |
ချိတ်ဆက်ဒေတာများကိုဖတ်ပါ |
Pro+ |
အတည်ပြုချက်ကုဒ်နမူနာများ
Python ပေါင်းစပ်မှုအပြည့်အစုံ
import requests
from typing import Optional, Dict
from datetime import datetime, timedelta
class SmartMoneyAuth:
"""Handles all authentication methods for Smart Money API"""
def __init__(self, api_key: str):
self.api_key = api_key
self.base_url = "https://api.smartmoneyapi.com"
self.jwt_token = None
self.jwt_expires = None
def get_jwt_token(self) -> str:
"""Get or refresh JWT token"""
if self.jwt_token and self.jwt_expires > datetime.now():
return self.jwt_token
response = requests.post(
f"{self.base_url}/auth/jwt",
json={"api_key": self.api_key}
)
data = response.json()
self.jwt_token = data["token"]
self.jwt_expires = datetime.now() + timedelta(seconds=data["expires_in"] - 300)
return self.jwt_token
def headers_bearer(self) -> Dict:
"""Get headers for Bearer token auth"""
return {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json"
}
def headers_jwt(self) -> Dict:
"""Get headers for JWT auth"""
token = self.get_jwt_token()
return {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
def request(self, method: str, endpoint: str, use_jwt: bool = False, **kwargs) -> Dict:
"""Make authenticated request"""
headers = self.headers_jwt() if use_jwt else self.headers_bearer()
response = requests.request(
method,
f"{self.base_url}{endpoint}",
headers=headers,
**kwargs
)
return response.json()
# Usage
auth = SmartMoneyAuth("sk_live_abc123xyz789")
# Bearer token method
whales = auth.request("GET", "/v1/whales/events?symbol=BTCUSDT")
# JWT method (auto-refreshing)
whales_jwt = auth.request("GET", "/v1/whales/events?symbol=BTCUSDT", use_jwt=True)
print(f"Found {whales['data']['total']} whale positions")
အကူအညီလိုပါသလား?
အတည်ပြုချက်နှင့်ပတ်သက်၍ အကူအညီလိုအပ်ပါက ကျွန်ုပ်တို့၏ API စာရွက်စာတမ်းများကိုသုံးသပ်ပါ သို့မဟုတ် အထောက်အပံ့ကိုဆက်သွယ်ပါ။
API ကိုးကားချက်
သင့်ပထမဆုံး API သော့ကိုဖန်တီးပါ
Smart Money API ဖြင့်စတင်ပါ။ သင့်အကောင့်ကိုဖန်တီးပြီး မိနစ်အနည်းငယ်အတွင်း အတည်ပြုချက်အထောက်အထားများကိုဖန်တီးပါ။
Console သို့သွားပါ