{
	"info": {
		"_postman_id": "af537f55-a516-4a5b-9171-d468cdd97810",
		"name": "Hamptapay-oApi",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
		"_exporter_id": "21948649",
		"_collection_link": "https://hamtapay.postman.co/workspace/Core-API-Workspace~9d7544fb-da66-486a-850c-09f6d2b00aad/collection/9799800-af537f55-a516-4a5b-9171-d468cdd97810?action=share&source=collection_link&creator=21948649"
	},
	"item": [
		{
			"name": "currency-list",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "{{base_url}}/financial/api/currency",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"financial",
						"api",
						"currency"
					]
				}
			},
			"response": []
		},
		{
			"name": "orderbook",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "{{base_url}}/api/market/orderbook?symbol=BTC-USDT",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"api",
						"market",
						"orderbook"
					],
					"query": [
						{
							"key": "symbol",
							"value": "BTC-USDT"
						}
					]
				}
			},
			"response": []
		},
		{
			"name": "udf",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "{{base_url}}/api/market/udf/history?symbol=BTC-IRT&resolution=1D&from=1779074213&to=1779110213",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"api",
						"market",
						"udf",
						"history"
					],
					"query": [
						{
							"key": "symbol",
							"value": "BTC-IRT"
						},
						{
							"key": "resolution",
							"value": "1D"
						},
						{
							"key": "from",
							"value": "1779074213"
						},
						{
							"key": "to",
							"value": "1779110213"
						}
					]
				}
			},
			"response": []
		},
		{
			"name": "currency-detail",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "{{base_url}}/financial/api/currency/BTC",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"financial",
						"api",
						"currency",
						"BTC"
					]
				}
			},
			"response": []
		},
		{
			"name": "market-list",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "{{base_url}}/financial/api/market",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"financial",
						"api",
						"market"
					]
				}
			},
			"response": []
		},
		{
			"name": "market-detail",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "{{base_url}}/financial/api/market/BTC-USDT",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"financial",
						"api",
						"market",
						"BTC-USDT"
					]
				}
			},
			"response": []
		},
		{
			"name": "profile",
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "api-key",
						"value": "{{api_key}}",
						"type": "text"
					}
				],
				"url": {
					"raw": "{{base_url}}/user/api/info",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"user",
						"api",
						"info"
					]
				}
			},
			"response": []
		},
		{
			"name": "assets",
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "api-key",
						"value": "{{api_key}}",
						"type": "text"
					}
				],
				"url": {
					"raw": "{{base_url}}/financial/api/accounts/MAIN",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"financial",
						"api",
						"accounts",
						"MAIN"
					]
				}
			},
			"response": []
		},
		{
			"name": "crypto-deposit",
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "api-key",
						"value": "{{api_key}}",
						"type": "text"
					}
				],
				"url": {
					"raw": "{{base_url}}/financial/api/deposit-address/TON/TON",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"financial",
						"api",
						"deposit-address",
						"TON",
						"TON"
					]
				}
			},
			"response": []
		},
		{
			"name": "Order",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "api-key",
						"value": "{{api_key}}",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n  \"type\": \"limit\",\n  \"market\": \"USDT-IRT\",\n  \"amount\": \"4\",\n  \"side\": \"BUY\",\n  \"price\": \"137000\"\n}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{base_url}}/financial/api/order/trade",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"financial",
						"api",
						"order",
						"trade"
					]
				}
			},
			"response": []
		},
		{
			"name": "swap",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "api-key",
						"value": "{{api_key}}",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n  \"symbol\": \"USDT-IRT\",\n  \"amount\": \"7.9744\",\n  \"side\": \"SELL\"\n}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{base_url}}/financial/api/order/swap",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"financial",
						"api",
						"order",
						"swap"
					]
				}
			},
			"response": []
		},
		{
			"name": "order-history",
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "api-key",
						"value": "{{api_key}}",
						"type": "text"
					}
				],
				"url": {
					"raw": "{{base_url}}/financial/api/order/history",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"financial",
						"api",
						"order",
						"history"
					]
				}
			},
			"response": []
		},
		{
			"name": "order-detail",
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "api-key",
						"value": "{{api_key}}",
						"type": "text"
					}
				],
				"url": {
					"raw": "{{base_url}}/financial/api/order/fdd15cee-a3d0-4917-9796-92323bac7002",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"financial",
						"api",
						"order",
						"fdd15cee-a3d0-4917-9796-92323bac7002"
					]
				}
			},
			"response": []
		},
		{
			"name": "cancel-order",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "api-key",
						"value": "{{api_key}}",
						"type": "text"
					}
				],
				"url": {
					"raw": "{{base_url}}/financial/api/order/cancel/5762c0cf-824c-4bf6-b58b-e0685b8161aa",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"financial",
						"api",
						"order",
						"cancel",
						"5762c0cf-824c-4bf6-b58b-e0685b8161aa"
					]
				}
			},
			"response": []
		}
	],
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"packages": {},
				"requests": {},
				"exec": [
					"// ===============================\r",
					"// Postman Pre-request Script\r",
					"// HMAC-SHA256 Signature (conditional)\r",
					"// If request has api-key header => sign\r",
					"// If not => public request, skip\r",
					"// ===============================\r",
					"\r",
					"// baseUrl و secretKey هنوز از Collection Variables\r",
					"const secretKey = pm.collectionVariables.get(\"secret_key\");\r",
					"const baseUrl = pm.collectionVariables.get(\"base_url\");\r",
					"\r",
					"// api-key را از هدر خود request بخوان\r",
					"const headerApiKey = pm.request.headers.get(\"api-key\");\r",
					"\r",
					"// اگر api-key در هدر نیست یا خالیه => درخواست public => امضا نکن\r",
					"if (!headerApiKey || String(headerApiKey).trim() === \"\") {\r",
					"  console.log(\"Public request: api-key header not found => skipping signature.\");\r",
					"  // اگر قبلاً signature مانده باشد، بهتر است پاکش کنیم تا اشتباه نشود\r",
					"  pm.request.headers.remove(\"signature\");\r",
					"  return;\r",
					"}\r",
					"\r",
					"// از اینجا به بعد => باید امضا کنیم\r",
					"if (!secretKey || !baseUrl) {\r",
					"  throw new Error(\"یکی از متغیرها تعریف نشده: secret_key یا base_url\");\r",
					"}\r",
					"\r",
					"// متد\r",
					"const method = (pm.request.method || \"\").toUpperCase();\r",
					"\r",
					"// ساختن URLها\r",
					"const reqUrl = pm.request.url; // Url object\r",
					"const fullUrl = reqUrl.toString();\r",
					"\r",
					"// نرمال‌سازی baseUrl (حذف اسلش انتهایی) - فعلاً فقط برای debug/سازگاری نگه داشتیم\r",
					"const normalizedBase = baseUrl.replace(/\\/+$/, \"\");\r",
					"\r",
					"// path + query را از خود آبجکت Postman بساز\r",
					"const path = \"/\" + (reqUrl.path || []).join(\"/\");\r",
					"\r",
					"// Query string مرتب و دقیق\r",
					"let queryString = \"\";\r",
					"if (reqUrl.query && reqUrl.query.count() > 0) {\r",
					"  const enabled = reqUrl.query.all().filter(q => q && q.key && !q.disabled);\r",
					"\r",
					"  queryString = enabled\r",
					"    .map(q => `${encodeURIComponent(q.key)}=${encodeURIComponent(q.value ?? \"\")}`)\r",
					"    .join(\"&\");\r",
					"\r",
					"  if (queryString) queryString = \"?\" + queryString;\r",
					"}\r",
					"\r",
					"const pathAndQuery = path + queryString;\r",
					"\r",
					"// ساخت stringToSign\r",
					"let stringToSign = \"\";\r",
					"\r",
					"if ([\"GET\", \"HEAD\"].includes(method)) {\r",
					"  // GET/HEAD: method + path + query\r",
					"  stringToSign = method + pathAndQuery;\r",
					"} else if ([\"POST\", \"PUT\", \"PATCH\"].includes(method)) {\r",
					"  // POST/PUT/PATCH: method + path + rawBody (بدون query string)\r",
					"  let rawBody = \"\";\r",
					"\r",
					"  if (!pm.request.body) {\r",
					"    rawBody = \"\";\r",
					"  } else if (pm.request.body.mode === \"raw\") {\r",
					"    rawBody = pm.request.body.raw || \"\";\r",
					"  } else if (pm.request.body.mode === \"urlencoded\") {\r",
					"    const items = pm.request.body.urlencoded?.all?.() || [];\r",
					"    const enabled = items.filter(i => i && i.key && !i.disabled);\r",
					"    rawBody = enabled\r",
					"      .map(i => `${encodeURIComponent(i.key)}=${encodeURIComponent(i.value ?? \"\")}`)\r",
					"      .join(\"&\");\r",
					"  } else if (pm.request.body.mode === \"formdata\") {\r",
					"    const items = pm.request.body.formdata?.all?.() || [];\r",
					"    const enabled = items.filter(i => i && i.key && !i.disabled);\r",
					"    rawBody = enabled\r",
					"      .filter(i => i.type !== \"file\")\r",
					"      .map(i => `${encodeURIComponent(i.key)}=${encodeURIComponent(i.value ?? \"\")}`)\r",
					"      .join(\"&\");\r",
					"  } else {\r",
					"    rawBody = pm.request.body.toString() || \"\";\r",
					"  }\r",
					"\r",
					"  stringToSign = method + path + rawBody;\r",
					"} else {\r",
					"  throw new Error(\"متد درخواست پشتیبانی نمی‌شود: \" + method);\r",
					"}\r",
					"\r",
					"// تولید signature\r",
					"const signature = CryptoJS.HmacSHA256(stringToSign, secretKey).toString(CryptoJS.enc.Hex);\r",
					"\r",
					"// ست کردن هدرها\r",
					"// api-key را دست نمی‌زنیم چون از خود request آمده (ولی اگر دوست داری می‌تونی upsert هم بکنی)\r",
					"pm.request.headers.upsert({ key: \"api-key\", value: headerApiKey });\r",
					"pm.request.headers.upsert({ key: \"signature\", value: signature });\r",
					"\r",
					"// Content-Type فقط در صورت raw/json\r",
					"if ([\"POST\", \"PUT\", \"PATCH\"].includes(method)) {\r",
					"  if (pm.request.body && pm.request.body.mode === \"raw\") {\r",
					"    pm.request.headers.upsert({ key: \"Content-Type\", value: \"application/json\" });\r",
					"  }\r",
					"}\r",
					"\r",
					"// Debug logs\r",
					"console.log(\"Signing enabled (api-key found).\");\r",
					"console.log(\"Method:\", method);\r",
					"console.log(\"Full URL:\", fullUrl);\r",
					"console.log(\"Path:\", path);\r",
					"console.log(\"Query:\", queryString || \"(none)\");\r",
					"console.log(\"Path+Query:\", pathAndQuery);\r",
					"console.log(\"StringToSign:\", stringToSign);\r",
					"console.log(\"Signature:\", signature);\r",
					""
				]
			}
		},
		{
			"listen": "test",
			"script": {
				"type": "text/javascript",
				"packages": {},
				"requests": {},
				"exec": [
					""
				]
			}
		}
	],
	"variable": [
		{
			"key": "secret_key",
			"value": ""
		},
		{
			"key": "base_url",
			"value": ""
		},
		{
			"key": "api_key",
			"value": ""
		}
	]
}