Einführung
Die SaleSwap-API ermöglicht es Ihnen, den Empfang von Informationen über die Wechselkurse von Währungen, erstellten Aufträgen, die im SaleSwap-Dienst präsentiert werden, zu automatisieren, Aufträge zu erstellen und sie damit zu verwalten.
Um die SaleSwap-API zu verwenden, müssen Sie einen API key und ein API secret abrufen.
Abrufen des API key
Gehen Sie folgendermaßen vor, um einen API Key und ein API Secret zu erhalten:
- Einloggen oder Anmelden im SaleSwap
- Gehen Sie zum Abschnitt API management
- Klicken Sie auf die Schaltfläche "Generieren" und folgen Sie den Anweisungen im erscheinenden Fenster
- Kopieren Sie den API Key und das API Secret und bewahren Sie diese an einem sicheren Ort auf. Verwenden Sie diese Parameter für Anforderungen an die SaleSwap-API
Anfrage und Beispiel
Die gesendeten Daten müssen im JSON-Format mit UTF-8-Kodierung vorliegen.
Für erfolgreiche API-Anfragen müssen alle Anfragen einige obligatorische Header enthalten:
- Der Content-Type header muss application/json; charset=UTF-8
- Der X-API-KEY Header sollte Ihren erhaltenen API Key (YOUR_API_KEY) enthalten
- Der X-API-SIGN muss die Signatur GENERATED_SIGN enthalten. Um die Signatur zu erhalten, müssen Sie Ihr API Secret (YOUR_API_SECRET) als HMAC SHA256 Operationsschlüssel und die json Datenzeichenfolge als Wert verwenden.
[linux]$ echo -n 'DATA_JSON' | openssl dgst -sha256 -hmac "YOUR_API_SECRET"
(stdin)= GENERATED_SIGN
cURL -X POST \
-H "Accept: application/json" \
-H "X-API-KEY: YOUR_API_KEY" \
-H "X-API-SIGN: GENERATED_SIGN" \
-H "Content-Type: application/json; charset=UTF-8" \
-d 'DATA_JSON'
"/api/v2/METHOD" -L
import hmac
import json
import hashlib
import requests
def sign(params):
if isinstance(params, dict):
parts = []
for k in params:
parts.append('%s=%s' % (k, params[k]))
payload = '&'.join(parts)
else:
payload = params
return hmac.new(
key=YOUR_API_SECRET.encode(),
msg=payload.encode(),
digestmod=hashlib.sha256
).hexdigest()
def request(method, params={}):
url = 'https://ff.io/api/v2/' + method
data = json.dumps(params)
headers = {
'X-API-KEY': YOUR_API_KEY,
'X-API-SIGN': sign(params)
}
r = requests.post(url, data=params, headers=headers)
return r.json()
request(METHOD, DATA)
<?php
function sign($data) {
return hash_hmac('sha256', $data, YOUR_API_SECRET);
}
function request($method, $data) {
$url = 'https://ff.io/api/v2/'.$method;
$req = json_encode($data);
$ch = curl_init();
curl_setopt($ch, , $url);
curl_setopt($ch, , true);
curl_setopt($ch, , 2);
curl_setopt($ch, , true);
curl_setopt($ch, , $req);
curl_setopt($ch, , array(
'Content-Type:application/json',
'X-API-KEY: ' . YOUR_API_KEY,
'X-API-SIGN: ' . sign($req)
));
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
if ($result['code'] == 0) {
return $result['data'];
} else {
throw new Exception($result['msg'], $result['code']);
}
}
request(METHOD, DATA);
?>
Limits anfordern
Das Anforderungslimit pro Minute beträgt 250 Gewichtseinheiten.
Die Anfrage /api/v2/create kostet 50 Gewichtseinheiten, alle anderen Anfragen kosten 1 Gewichtseinheit.
Wenn das Limit überschritten wird, wird Ihr Token vorübergehend gesperrt. Mit jeder weiteren Limitüberschreitung nach dem Entsperren verlängert sich die Sperrzeit
Verfügbare Währungen
Abrufen einer Liste der vom SaleSwap-Dienst unterstützten Währungen sowie Daten zu deren Anzeige und Informationen zur Verfügbarkeit zum Empfangen und Senden.
Parameter
Für diese Anfrage müssen keine Parameter übergeben werden.
X-API-SIGN wird generiert, indem die Funktion HMAC SHA256 aus einem leeren String aufgerufen wird, wenn keine Parameter übergeben werden, oder aus einem leeren JSON Objekt.
cURL -X POST \
-H "Accept: application/json" \
-H "X-API-KEY: YOUR_API_KEY" \
-H "X-API-SIGN: GENERATED_SIGN" \
-H "Content-Type: application/json; charset=UTF-8" \
"/api/v2/ccies" -L
<?php
require_once('fixedfloat.php');
$ff = new SaleSwapApi(YOUR_API_KEY, YOUR_API_SECRET);
return $ff->ccies();
?>
Antwort
Eine erfolgreiche Antwort enthält ein Array von Währungsinformationsobjekten.
| Field | Type | Description |
| code | number | Response status code. If the request is successful, then the status code is "0", otherwise it is an error |
| msg | string | Status message |
| data | Array | List of currencies supported by SaleSwap |
| data[].code | string | Unique currency code in SaleSwap |
| data[].coin | string | Common asset ticker |
| data[].network | string | Blockchain network in which this asset is represented |
| data[].name | string | Name of currency |
| data[].recv | boolean | Availability of currency for acceptance into the service from the client |
| data[].send | boolean | Availability of currency to send to the client |
| data[].tag | string | The name of the additional field, if available; otherwise null |
| data[].logo | string | Link to currency image |
| data[].color | string | Currency color specified in HEX format |
| data[].priority | number | Priority in the list of currencies of the service |
{ "code": 0,
"msg": "",
"data": [
{
"code": "BTC",
"coin": "BTC",
"network": "BTC",
"name": "Bitcoin",
"recv": true,
"send": true,
"tag": null,
"logo": "https://fixedfloat.com/assets/images/coins/svg/btc.svg",
"color": "#f7931a",
"priority": "5",
},
...,
],
}
Exchange rate
Getting the exchange rate of a pair of currencies in the selected direction and type of rate.
ATTENTION! To get the exchange rates of all available currencies, you should use the export rate file available at the link https://ff.io/rates.xml
For this method, as well as for method /api/v2/create, it is possible to increase accrued earnings under the affiliate program using parameter afftax.
The final exchange rate when passing parameters afftax and refcode depends on whether your affiliate program code has been approved for earning for orders generated by the API and the base percentage (AFFBASE) set for your code, and will be calculated according to the formula:
total = FF - AFFB + afftax, if afftax < FF - AFFB
total = afftax x 2 , if FF - AFFB < afftax < FF
total = FF + afftax , if afftax > FF
where FF is the base percentage of the service for the selected type of exchange rate (1% for a fixed rate and 0.5% for a floating rate);
AFFB is the base percentage of the service profit set for your affiliate program code, for the selected type of exchange rate (AFFBASE for a fixed rate and AFFBASE÷2 for a floating rate)
For clarity, we suggest that you familiarize yourself with the table below with AFFBASE=0.4, where FFP = FF - AFFB:
| FIXED RATE | FLOAT RATE | ||||
| Total | FFP | afftax | Total | FFP | afftax |
| 1.0 | 0.6 | 0.4 | 0.5 | 0.3 | 0.2 |
| 1.1 | 0.6 | 0.5 | 0.55 | 0.3 | 0.25 |
| 1.2 | 0.6 | 0.6 | 0.6 | 0.3 | 0.3 |
| 1.4 | 0.7 | 0.7 | 0.7 | 0.35 | 0.35 |
| 1.6 | 0.8 | 0.8 | 0.8 | 0.4 | 0.4 |
| 1.8 | 0.9 | 0.9 | 0.9 | 0.45 | 0.45 |
| 2.0 | 1.0 | 1.0 | 1.0 | 0.5 | 0.5 |
| 2.1 | 1.0 | 1.1 | 1.05 | 0.5 | 0.55 |
| 2.2 | 1.0 | 1.2 | 1.1 | 0.5 | 0.6 |
If your affiliate code did not have a base API earnings percentage set, then the final exchange rate will be calculated as:
FF + afftax
where FF is the base percentage of the service for the selected type of exchange rate (1% for a fixed rate and 0.5% for a floating rate).
Earnings will be credited to your account if the affiliate program code was passed in the refcode parameter and this code belongs to your account. Otherwise, the afftax and refcode parameters will be ignored.
Parameters
| Name | Required | Type | Description |
| type | true | string | Order type |
| fromCcy | true | string | Code of the currency the client wants to send |
| toCcy | true | string | Code of the currency the client wants to receive |
| direction | true | string |
The direction of the exchange determines whether the client wants to send a certain amount or receive a certain amount. Can take one of the following values:
● from — if the client wants to send the amount amount in the currency fromCcy ● to — if the client wants to receive the amount amount in the currency toCcy |
| amount | true | numeric | If direction="from", then this is the amount in currency fromCcy that the client wants to send. If direction="to", then this is the amount in currency toCcy that the client wants to receive |
| ccies | false | boolean | Adding a list of currencies to the response with information about the availability for sending and receiving |
| usd | false | boolean | Amount in USD, by which fromAmount or toAmount will be changed in case the limits are exceeded |
| refcode | false | string | Affiliate program code for which earnings will be accrued under the affiliate program. If the afftax parameter is not set and this affiliate program code does not participate in earning via the API, passing this parameter will not affect anything. It is possible to transfer only affiliate program codes that were received in the same account in which the API key used for this request was received |
| afftax | false | float | Desired earnings under the affiliate program as a percentage of the exchange amount. Affects the final exchange rate and earnings under the affiliate program if the refcode parameter is also set. |
cURL -X POST \
-H "Accept: application/json" \
-H "X-API-KEY: YOUR_API_KEY" \
-H "X-API-SIGN: GENERATED_SIGN" \
-H "Content-Type: application/json; charset=UTF-8" \
-d '{"fromCcy":"BTC","toCcy":"USDTTRC","amount":0.5,direction":"from","type":"float"}'
"/api/v2/create" -L
<?php
require_once('fixedfloat.php');
$ff = new SaleSwapApi(YOUR_API_KEY, YOUR_API_SECRET);
$data = array(
'fromCcy' => 'BTC',
'toCcy' => 'USDTTRC',
'amount' => '0.5',
'direction' => 'from',
'type' => 'float',
);
return $ff->price($data);
?>
Response
A successful response contains information about the currencies of the selected pair, the exchange rate, and the amount sent and received.
| Field | Type | Description |
| code | number | Response status code. If the request is successful, then the status code is "0", otherwise it is an error |
| msg | string | Status message |
| data | Object | An object with information about the currencies of the selected pair, the exchange rate, and the amount sent and received |
| data.from | Object | Data about the asset that the client must send |
| data.from.code | string | Unique currency code in SaleSwap |
| data.from.network | string | Blockchain network in which this asset is represented |
| data.from.coin | string | Common asset ticker |
| data.from.amount | string | Amount that the client needs to send |
| data.from.rate | string | Final exchange rate |
| data.from.precision | integer | Rounding accuracy |
| data.from.min | string | Minimum amount |
| data.from.max | string | Maximum amount |
| data.from.usd | string | Equivalent in USD |
| data.from.btc | string | Equivalent in BTC |
| data.to | Object | Data about the asset that the client will receive |
| data.to.code | string | Unique currency code in SaleSwap |
| data.to.network | string | Blockchain network in which this asset is represented |
| data.to.coin | string | Common asset ticker |
| data.to.amount | string | Amount that the client must to receive |
| data.to.rate | string | Final exchange rate |
| data.to.precision | integer | Rounding accuracy |
| data.to.min | string | Minimum amount |
| data.to.max | string | Maximum amount |
| data.to.usd | string | Equivalent in USD |
| data.errors | Array | An array of a list of errors. If the array is empty, then creating an order with these parameters is possible.
The array may contain the following errors: ● MAINTENANCE_FROM — Currency from data.from object under maintenance ● MAINTENANCE_TO — Currency from object data.to under maintenance ● OFFLINE_FROM — Currency from object data.from is not available ● OFFLINE_TO — Currency from object data.to is not available ● RESERVE_FROM — Not enough currency reserves from object data.from ● RESERVE_TO — Not enough currency reserves from object data.to ● LIMIT_MIN — Amount less than limit ● LIMIT_MAX — The amount is greater than the limit |
| data.ccies | Array | Added if the ccies parameter is true. An array containing a list of objects with information about the availability for sending and receiving currencies |
| data.ccies[].code | string | Unique currency code in SaleSwap |
| data.ccies[].recv | boolean | Availability of currency for acceptance into the service from the client |
| data.ccies[].send | boolean | Availability of currency to send to the client |
{ "code": 0,
"msg": "",
"data": {
"from": {
"code": "BSC",
"network": "BSC",
"coin": "BNB",
"amount": "0.040297",
"rate": "0.01452202",
"precision": 8,
"min": "0.005053",
"max": "967.072057",
"usd": "12.28",
"btc": "0.00058813",
},
"to": {
"code": "BTC",
"network": "BTC",
"coin": "BTC",
"amount": "0.00055984",
"rate": "68.164781",
"precision": 8,
"min": "0.0000479",
"max": "14.04381911",
"usd": "11.69",
},
"errors": [],
"ccies": [
{
"code": "ADA",
"recv": true,
"send": true,
},
...,
],
},
}
Bestellung anlegen
Erstellen eines Auftrags zum Umtausch ausgewählter Währungen mit einem bestimmten Betrag und einer bestimmten Adresse.
Bei dieser Methode sowie bei der /api/v2/price Methode ist es möglich, die anfallenden Einnahmen im Rahmen des Partnerprogramms mit dem Parameter afftax zu erhöhen. Die Regeln für die Verwendung dieses Parameters sind in der Methode /api/v2/price beschrieben
Parameter
| Name | Required | Type | Description |
| type | true | string | Order type |
| fromCcy | true | string | Code of the currency the client wants to send |
| toCcy | true | string | Code of the currency the client wants to receive |
| direction | true | string |
The direction of the exchange determines whether the client wants to send a certain amount or receive a certain amount. Can take one of the following values:
● from — if the client wants to send the amount amount in the currency fromCcy ● to — if the client wants to receive the amount amount in the currency toCcy |
| amount | true | numeric | If direction="from", then this is the amount in currency fromCcy that the client wants to send. If direction="to", then this is the amount in currency toCcy that the client wants to receive |
| toAddress | true | string | Destination address to which the funds will be dispatched upon the successful completion of the Order |
| tag | false | boolean | If you need to specify a Memo or Destination Tag when sending, you should specify it here. This parameter can be omitted by specifying the MEMO or Destination Tag in toAddress separated by a colon. |
| refcode | false | string | Affiliate program code for which earnings will be accrued under the affiliate program. If the afftax parameter is not set and this affiliate program code does not participate in earning via the API, passing this parameter will not affect anything. It is possible to transfer only affiliate program codes that were received in the same account in which the API key used for this request was received |
| afftax | false | float | Desired earnings under the affiliate program as a percentage of the exchange amount. Affects the final exchange rate and earnings under the affiliate program if the refcode parameter is also set. |
cURL -X POST \
-H "Accept: application/json" \
-H "X-API-KEY: YOUR_API_KEY" \
-H "X-API-SIGN: GENERATED_SIGN" \
-H "Content-Type: application/json; charset=UTF-8" \
-d '{"fromCcy":"BTC","toCcy":"USDTTRC","amount":0.5,direction":"from","type":"float","toAddress":"TAzsQ9Gx8eqFNFSKbeXrbi45CuVPHzA8wr"}'
"/api/v2/create" -L
<?php
require_once('fixedfloat.php');
$ff = new SaleSwapApi(YOUR_API_KEY, YOUR_API_SECRET);
$data = array(
'fromCcy' => 'BTC',
'toCcy' => 'USDTTRC',
'amount' => '0.5',
'direction' => 'from',
'type' => 'float',
'toAddress' => 'TAzsQ9Gx8eqFNFSKbeXrbi45CuVPHzA8wr'
);
return $ff->create($data);
?>
Antwort
Eine erfolgreiche Antwort enthält ein Objekt mit Informationen über alle Daten der erstellten Bestellung, einschließlich des Parameters token, um später aktualisierte Informationen über die Bestellung mit der Methode /api/v2/ Bestellung und Bestellverwaltung zu erhalten.
| Field | Type | Description |
| code | number | Response status code. If the request is successful, then the status code is "0", otherwise it is an error |
| msg | string | Status message |
| data | Object | Object with information about all the data of the created order |
| data.token | string | Order access token |
| data.id | string | Order ID. Consists of 6 characters |
| data.type | string | Order type. Can be one of the values:
● fixed — fixed rate order ● float — floating rate order |
| data.email | string | Email address for the order to receive notifications about changes in the order |
| data.status | string | Order status. Can be one of the values:
● NEW — New order ● PENDING — Transaction received, pending confirmation ● EXCHANGE — Transaction confirmed, exchange in progress ● WITHDRAW — Sending funds ● DONE — Order completed ● EXPIRED — Order expired ● EMERGENCY — Emergency, customer choice required |
| data.time | Object | Object containing timestamp data |
| data.time.reg | number | Order creation timestamp |
| data.time.start | number | Transaction receive timestamp |
| data.time.finish | number | Timestamp when the order was completed |
| data.time.update | number | Timestamp of last order update |
| data.time.expiration | number | Timestamp when order expires |
| data.time.left | number | The number of seconds before the end of the order |
| data.from | Object | An object containing information about the currency sent by clients and transactions |
| data.from.code | string | Currency code |
| data.from.coin | string | Common asset ticker |
| data.from.network | string | Blockchain network in which this asset is represented |
| data.from.name | string | Name of currency |
| data.from.alias | string | Alias for creating qr code |
| data.from.amount | string | Amount that the client needs to send |
| data.from.address | string | The destination address to which the user is ought to deposit his funds in order for the trade to execute |
| data.from.tag | string | MEMO or Destination Tag if required |
| data.from.addressMix | string | Address with a colon-connected tag |
| data.from.reqСonfirmations | number | Required n |