/exchange/peek
GET ASYNCInspects a specific sale listing on the exchange.
GET /api/v1/exchange/peek
Alias: /inspect-sale-listing
Description
This endpoint allows a user to "peek" at the coins within one of their own sale listings to verify its contents. This is an asynchronous operation that returns a task ID.
Query Parameters
Parameter | Type | Required | Description |
---|---|---|---|
cointype | integer | Yes | The cryptocurrency type of the listing. |
amount | number | Yes | The amount of CloudCoins in the listing. |
name | string | Yes | The name of the wallet that created the listing. |
price | number | Yes | The price of the listing. |
Response
The final result, available after polling the task, contains the details of the coins in the sale listing.
Response Properties (in completed task `data`)
totalnumber
Total value of coins in the listing.
coinsarray
An array of coin objects.
Examples
JavaScript Example
const apiHost = 'http://localhost:8006';
// Generic function to poll any task
async function pollTask(taskId) {
const taskResponse = await fetch(`${apiHost}/api/v1/tasks/${taskId}`);
const taskData = await taskResponse.json();
const task = taskData.payload;
console.log(`Task ${taskId} progress: ${task.progress}% - ${task.message}`);
if (task.status === 'completed') {
console.log(`Task finished successfully!`, task.data);
return true; // Stop polling
} else if (task.status === 'error') {
console.error(`Task failed:`, task.message);
return true; // Stop polling
}
return false; // Continue polling
}
async function peekSale(params) {
const query = new URLSearchParams(params).toString();
const response = await fetch(`${apiHost}/api/v1/exchange/peek?${query}`);
const taskInfo = await response.json();
const taskId = taskInfo.payload.id;
console.log(`PeekSale task created with ID: ${taskId}`);
const pollInterval = setInterval(async () => {
const isDone = await pollTask(taskId);
if (isDone) clearInterval(pollInterval);
}, 2000); // Check every 2 seconds
}
peekSale({ cointype: 1, amount: 100, name: 'Default', price: 0.001 });
cURL Example
# Step 1: Initiate the peek task
TASK_ID=$(curl -s -X GET "http://localhost:8006/api/v1/exchange/peek?cointype=1&amount=100&name=Default&price=0.001" | jq -r '.payload.id')
echo "Peek task started with ID: $TASK_ID"
# Step 2: Poll the task endpoint until finished
while true; do
RESPONSE=$(curl -s "http://localhost:8006/api/v1/tasks/$TASK_ID")
STATUS=$(echo $RESPONSE | jq -r '.payload.status')
echo "Polling task.. Status: $STATUS"
if [[ "$STATUS" == "completed" ]] || [[ "$STATUS" == "error" ]]; then
echo "Final Response:"
echo $RESPONSE | jq
break
fi
sleep 2
done
Go Example
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/url"
"time"
)
const apiHost = "http://localhost:8006/api/v1"
type TaskResponse struct {
Payload struct {
ID string `json:"id"`
Status string `json:"status"`
Message string `json:"message"`
Data interface{} `json:"data"`
} `json:"payload"`
}
func pollTask(taskId string) {
for {
resp, err := http.Get(fmt.Sprintf("%s/tasks/%s", apiHost, taskId))
if err != nil { log.Printf("Error polling task: %v\n", err); return }
defer resp.Body.Close()
var taskResp TaskResponse
json.NewDecoder(resp.Body).Decode(&taskResp)
fmt.Printf("Polling... Status: %s, Message: %s\n", taskResp.Payload.Status, taskResp.Payload.Message)
if taskResp.Payload.Status == "completed" {
fmt.Printf("Task completed. Data: %+v\n", taskResp.Payload.Data)
return
} else if taskResp.Payload.Status == "error" {
fmt.Printf("Task failed: %s\n", taskResp.Payload.Message)
return
}
time.Sleep(2 * time.Second)
}
}
func peekSale(params map[string]string) {
baseURL := fmt.Sprintf("%s/exchange/peek", apiHost)
queryParams := url.Values{}
for key, val := range params {
queryParams.Add(key, val)
}
resp, err := http.Get(fmt.Sprintf("%s?%s", baseURL, queryParams.Encode()))
if err != nil {
log.Fatalf("Failed to start peek task: %v", err)
}
defer resp.Body.Close()
var taskResp TaskResponse
json.NewDecoder(resp.Body).Decode(&taskResp)
fmt.Printf("Peek task created with ID: %s\n", taskResp.Payload.ID)
pollTask(taskResp.Payload.ID)
}
func main() {
saleParams := map[string]string{
"cointype": "1",
"amount": "100",
"name": "Default",
"price": "0.001",
}
peekSale(saleParams)
}