تبدیل تومان ↔ TON
POST
/api/v1/wallet/convertscope: wallet:writeاحراز هویت: Bearerlive و test
کسر از یک کیف پول و واریز به دیگری در یک تراکنش. scope ِ wallet:write پیشفرض نیست و باید هنگام ساخت کلید انتخاب شود. min_receive محافظ لغزش نرخ است.
درخواست
| نام | محل | نوع | توضیح | |
|---|---|---|---|---|
Authorization | header | string | الزامی | Bearer sk_live_… یا Bearer sk_test_… |
Idempotency-Key | header | string | الزامی | الزامی؛ تکرار همان کلید همان نتیجه را برمیگرداند |
بدنه (JSON)
| فیلد | نوع | توضیح | |
|---|---|---|---|
direction | string | الزامی | toman_to_ton | ton_to_toman |
amount | string | الزامی | مبلغ |
min_receive | string | اختیاری | حداقل مبلغ دریافتی |
نمونه
curl -X POST "https://stard-market.ir/api/v1/wallet/convert" \
-H "Authorization: Bearer $STARD_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: cv-1001" \
-d '{"direction": "toman_to_ton", "amount": "500000"}'const res = await fetch("https://stard-market.ir/api/v1/wallet/convert", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.STARD_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": "cv-1001",
},
body: JSON.stringify({
"direction": "toman_to_ton",
"amount": "500000"
}),
});
const data = await res.json();
if (!res.ok) throw new Error(`${data.error.code}: ${data.error.message}`);
console.log(data);type StardError = { error: { type: string; code: string; message: string; param: string | null; request_id: string } };
const res = await fetch("https://stard-market.ir/api/v1/wallet/convert", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.STARD_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": "cv-1001",
},
body: JSON.stringify({
"direction": "toman_to_ton",
"amount": "500000"
}),
});
if (!res.ok) {
const { error } = (await res.json()) as StardError;
throw new Error(`${error.code}: ${error.message} (${error.request_id})`);
}
const data: Record<string, unknown> = await res.json();import os
import requests
r = requests.post(
"https://stard-market.ir/api/v1/wallet/convert",
headers={
"Authorization": f"Bearer {os.environ['STARD_API_KEY']}",
"Idempotency-Key": "cv-1001",
},
json={
"direction": "toman_to_ton",
"amount": "500000"
},
timeout=20,
)
data = r.json()
if r.status_code >= 400:
raise RuntimeError(f"{data['error']['code']}: {data['error']['message']}")
print(data)<?php
$ch = curl_init("https://stard-market.ir/api/v1/wallet/convert");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("STARD_API_KEY"),
"Content-Type: application/json",
"Idempotency-Key: cv-1001",
],
CURLOPT_POSTFIELDS => json_encode([
"direction" => "toman_to_ton",
"amount" => "500000"
]),
CURLOPT_TIMEOUT => 20,
]);
$data = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($status >= 400) {
throw new RuntimeException($data["error"]["code"] . ": " . $data["error"]["message"]);
}
print_r($data);package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
)
func main() {
body := strings.NewReader(`{"direction": "toman_to_ton", "amount": "500000"}`)
req, _ := http.NewRequest("POST", "https://stard-market.ir/api/v1/wallet/convert", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("STARD_API_KEY"))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", "cv-1001")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
b, _ := io.ReadAll(res.Body)
fmt.Println(res.StatusCode, string(b))
}خطاها
| HTTP | code | کی |
|---|---|---|
400 | live_only | فقط با کلید live |
400 | parameter_missing | Idempotency-Key لازم است |
402 | insufficient_funds | موجودی کافی نیست |
409 | unavailable | نرخ بدتر از min_receive شد |
403 | insufficient_scope | کلید scope wallet:write را ندارد |
401 | invalid_api_key / missing_api_key / api_key_revoked / api_key_expired | کلید نیامده، نامعتبر، باطل یا منقضی است |
429 | rate_limit_exceeded | سقف درخواست در دقیقه پر شده؛ بعد از Retry-After ثانیه دوباره بفرست |
محدودیت نرخ
پیشفرض ۶۰ درخواست در دقیقه برای هر کلید (قابل تنظیم در داشبورد). وضعیت در هدرهای X-RateLimit-* برمیگردد — جزئیات.
