bitvavo / php-bitvavo-api
Bitvavo API 的 PHP 封装。
Requires
- php: >=7.0
- ext-curl: *
- ratchet/pawl: ^0.3.0
- ratchet/rfc6455: ^0.2.3
- react/socket: ^1.0 || ^0.8 || ^0.7
README
PHP Bitvavo API
这是 Bitvavo API 的 PHP 封装。该项目可用于构建与 Bitvavo 平台交互的自定义项目。API 中可用的每个功能都可以通过 REST 请求或 Websocket 调用。有关每个参数的详细信息,请参阅 Bitvavo API 文档
安装
获取软件包及其依赖项
composer require bitvavo/php-bitvavo-api:dev-master
运行示例
cd vendor/bitvavo/php-bitvavo-api/example
php example.php
REST请求
在所有函数(REST和Websocket)中使用的通用约定是,所有可选参数都作为关联数组传递,而必需参数则作为单独的值传递。只有在下单时,一些可选参数是必需的,因为限价订单需要比市价订单更多的信息。返回的响应也全部转换为关联数组,以便于$response['<key>'] = '<value>'。
入门
API密钥和密码对于私有调用是必需的,对于公共调用是可选的。访问窗口和调试参数对于所有调用都是可选的。访问窗口用于确定请求是否在规定时间内到达,该值以毫秒为单位指定。如果您遇到错误,可以使用time函数将您的时钟同步到我们的服务器时间。REST URL和WS URL可以用于设置不同的端点(用于测试目的)。当您想记录更多信息以及完整的响应时,调试应设置为true。任何参数都可以省略,私有函数将在API密钥和密码未设置时返回错误。
require_once('bitvavo.php'); $bitvavo = new Bitvavo([ "APIKEY" => "<APIKEY>", "APISECRET" => "<APISECRET>", "RESTURL" => "https://api.bitvavo.com/v2", "WSURL" => "wss://ws.bitvavo.com/v2/", "ACCESSWINDOW" => 10000, "DEBUGGING" => false ]);
为了演示目的,我们在打印时将编码回JSON。这是因为PHP不允许美化打印数组。通常,您会按照以下方式访问所需值
$response = $bitvavo->time(); $currentTime = $response["time"]; // Do something with time echo $currentTime
通用
获取时间
$response = $bitvavo->time(); echo json_encode($response);
查看响应
{
"time": 1548686055654
}
获取市场
// options: market foreach ($bitvavo->markets([]) as $market) { echo json_encode($market) . "\n"; }
查看响应
{
"market": "ADA-BTC",
"status": "trading",
"base": "ADA",
"quote": "BTC",
"pricePrecision": 5,
"minOrderInBaseAsset": "100",
"minOrderInQuoteAsset": "0.001",
"orderTypes": [
"market",
"limit"
]
}
{
"market": "ADA-EUR",
"status": "trading",
"base": "ADA",
"quote": "EUR",
"pricePrecision": 5,
"minOrderInBaseAsset": "100",
"minOrderInQuoteAsset": "10",
"orderTypes": [
"market",
"limit"
]
}
{
"market": "AE-BTC",
"status": "trading",
"base": "AE",
"quote": "BTC",
"pricePrecision": 5,
"minOrderInBaseAsset": "10",
"minOrderInQuoteAsset": "0.001",
"orderTypes": [
"market",
"limit"
]
}
{
"market": "AE-EUR",
"status": "trading",
"base": "AE",
"quote": "EUR",
"pricePrecision": 5,
"minOrderInBaseAsset": "10",
"minOrderInQuoteAsset": "10",
"orderTypes": [
"market",
"limit"
]
}
...
获取资产
// options: symbol foreach ($bitvavo->assets([]) as $asset) { echo json_encode($asset) . "\n"; }
查看响应
{
"symbol": "ADA",
"name": "Cardano",
"decimals": 6,
"depositFee": "0",
"depositConfirmations": 20,
"depositStatus": "OK",
"withdrawalFee": "0.2",
"withdrawalMinAmount": "0.2",
"withdrawalStatus": "OK",
"networks": [
"Mainnet"
],
"message": ""
}
{
"symbol": "AE",
"name": "Aeternity",
"decimals": 8,
"depositFee": "0",
"depositConfirmations": 30,
"depositStatus": "OK",
"withdrawalFee": "2",
"withdrawalMinAmount": "2",
"withdrawalStatus": "OK",
"networks": [
"Mainnet"
],
"message": ""
}
{
"symbol": "AION",
"name": "Aion",
"decimals": 8,
"depositFee": "0",
"depositConfirmations": 0,
"depositStatus": "",
"withdrawalFee": "3",
"withdrawalMinAmount": "3",
"withdrawalStatus": "",
"networks": [
"Mainnet"
],
"message": ""
}
{
"symbol": "ANT",
"name": "Aragon",
"decimals": 8,
"depositFee": "0",
"depositConfirmations": 30,
"depositStatus": "OK",
"withdrawalFee": "2",
"withdrawalMinAmount": "2",
"withdrawalStatus": "OK",
"networks": [
"Mainnet"
],
"message": ""
}
...
市场数据
按市场获取订单簿
// options: depth $response = $bitvavo->book("BTC-EUR", []); echo json_encode($response) . "\n";
查看响应
{
"market": "BTC-EUR",
"nonce": 5111,
"bids": [
[
"2998.9",
"2.14460302"
],
[
"2998.4",
"0.35156557"
],
[
"2997",
"0.97089768"
],
[
"2996.5",
"0.74129861"
],
[
"2996",
"0.33746089"
],
...
],
"asks": [
[
"2999",
"0.34445088"
],
[
"2999.5",
"0.32306421"
],
[
"3000",
"0.37908805"
],
[
"3000.6",
"0.85330708"
],
[
"3001.7",
"0.31230068"
],
...
]
}
按市场获取交易
// options: limit, start, end, tradeIdFrom, tradeIdTo foreach ($bitvavo->publicTrades("BTC-EUR", []) as $trade) { echo json_encode($trade) . "\n"; }
查看响应
{
"id": "99cee743-1a9b-4dd4-8337-2a384e490554",
"timestamp": 1548685961053,
"amount": "0.55444771",
"price": "2996.3",
"side": "buy"
}
{
"id": "12d442cf-23a2-43c4-ae20-4b3d61a5993c",
"timestamp": 1548685961047,
"amount": "0.44555229",
"price": "2995.7",
"side": "buy"
}
{
"id": "75335db3-5b94-48af-bdc9-8716e0a3d6ae",
"timestamp": 1548685918958,
"amount": "1",
"price": "2996.1",
"side": "buy"
}
{
"id": "616bfa4e-b3ff-4b3f-a394-1538a49eb9bc",
"timestamp": 1548685870299,
"amount": "1",
"price": "2996",
"side": "buy"
}
{
"id": "34cdda49-3e9d-4d8f-a1aa-3176f61d9c27",
"timestamp": 1548684756948,
"amount": "0.79946345",
"price": "2996.3",
"side": "buy"
}
{
"id": "525a2ae0-7c0d-4945-9e4f-cf5729b44c5c",
"timestamp": 1548684756939,
"amount": "0.06202504",
"price": "2995.6",
"side": "buy"
}
...
按市场获取蜡烛
// options: limit, start, end foreach ($bitvavo->candles("LTC-EUR", "1h", []) as $candle) { echo json_encode($candle) . "\n"; }
查看响应
[
1548684000000,
"2993.7",
"2996.9",
"2992.5",
"2993.7",
"9"
]
[
1548684000000,
"2993.7",
"2996.9",
"2992.5",
"2993.7",
"9"
]
[
1548676800000,
"2999.3",
"3002.6",
"2989.2",
"2999.3",
"63.00046504"
]
[
1548669600000,
"3012.9",
"3015.8",
"3000",
"3012.9",
"8"
]
[
1548417600000,
"3124",
"3125.1",
"3124",
"3124",
"0.1"
]
...
获取价格指示器
// options: market foreach ($bitvavo->tickerPrice([]) as $price) { echo json_encode($price) . "\n"; }
查看响应
{
"market": "EOS-EUR",
"price": "2.0142"
}
{
"market": "XRP-EUR",
"price": "0.25193"
}
{
"market": "ETH-EUR",
"price": "91.1"
}
{
"market": "IOST-EUR",
"price": "0.005941"
}
{
"market": "BCH-EUR",
"price": "106.57"
}
{
"market": "BTC-EUR",
"price": "3000.2"
}
{
"market": "STORM-EUR",
"price": "0.0025672"
}
{
"market": "EOS-BTC",
"price": "0.00066289"
}
{
"market": "BSV-EUR",
"price": "57.6"
}
...
获取订单簿指示器
// options: market foreach ($bitvavo->tickerBook([]) as $book) { echo json_encode($book) . "\n"; }
查看响应
{
"market": "XVG-BTC",
"bid": "0.00000045",
"ask": "0.00000046",
"bidSize": "28815.01275017",
"askSize": "38392.85089495"
}
{
"market": "XVG-EUR",
"bid": "0.0042213",
"ask": "0.0043277",
"bidSize": "1695671.24837763",
"askSize": "792229.47382889"
}
{
"market": "ZIL-BTC",
"bid": "0.00000082",
"ask": "0.00000083",
"bidSize": "140980.13397262",
"askSize": "98839.99285373"
}
{
"market": "ZIL-EUR",
"bid": "0.0076923",
"ask": "0.0077929",
"bidSize": "348008.13304576",
"askSize": "151544.09942432"
}
{
"market": "ZRX-BTC",
"bid": "0.00001679",
"ask": "0.0000168",
"bidSize": "633.12153002",
"askSize": "1280.07668593"
}
{
"market": "ZRX-EUR",
"bid": "0.1575",
"ask": "0.15774",
"bidSize": "875.01315351",
"askSize": "1013.62085819"
}
...
获取24小时指示器
// options: market foreach ($bitvavo->ticker24h([]) as $ticker) { echo json_encode($ticker) . "\n"; }
查看响应
{
"market": "XVG-EUR",
"open": "0.0043222",
"high": "0.0044139",
"low": "0.0040849",
"last": "0.0041952",
"volume": "1237140.82971657",
"volumeQuote": "5267.56",
"bid": "0.0042245",
"bidSize": "1704411.59895476",
"ask": "0.0043217",
"askSize": "2419888.08209617",
"timestamp": 1565777160307
}
{
"market": "ZIL-EUR",
"open": "0.008125",
"high": "0.0082359",
"low": "0.0076094",
"last": "0.0077285",
"volume": "738574.75091114",
"volumeQuote": "5724.92",
"bid": "0.007698",
"bidSize": "347552.37282041",
"ask": "0.0077977",
"askSize": "151544.09942432",
"timestamp": 1565777159934
}
{
"market": "ZRX-EUR",
"open": "0.16326",
"high": "0.16326",
"low": "0.15812",
"last": "0.15858",
"volume": "4855.99528525",
"volumeQuote": "779.72",
"bid": "0.15748",
"bidSize": "874.65298311",
"ask": "0.15775",
"askSize": "545.84965752",
"timestamp": 1565777159932
}
...
私有
下单
在下单时,请确保设置了正确的可选参数。对于限价订单,必须设置数量和价格。如果设置了数量或数量引用,则市价订单有效。
// optional parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection), // stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount) // stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount) // all orderTypes: timeInForce, selfTradePrevention, responseRequired $response = $bitvavo->placeOrder("BTC-EUR", "buy", "limit", ["amount" => "1", "price" => "2000"]); echo json_encode($response) . "\n";
查看响应
{
"orderId": "97d89ffc-2339-4e8f-8032-bf7b8c9ee65b",
"market": "BTC-EUR",
"created": 1548686752319,
"updated": 1548686752319,
"status": "new",
"side": "buy",
"orderType": "limit",
"amount": "1",
"amountRemaining": "1",
"price": "2000",
"onHold": "2005",
"onHoldCurrency": "EUR",
"filledAmount": "0",
"filledAmountQuote": "0",
"feePaid": "0",
"feeCurrency": "EUR",
"fills": [],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
更新订单
在更新订单时,请确保已设置至少一个可选参数。否则无法更新。
// Optional parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly) // untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount) // stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount) $response = $bitvavo->updateOrder("BTC-EUR", "97d89ffc-2339-4e8f-8032-bf7b8c9ee65b", ["amount" => "1.1"]); echo json_encode($response) . "\n";
查看响应
{
"orderId": "97d89ffc-2339-4e8f-8032-bf7b8c9ee65b",
"market": "BTC-EUR",
"created": 1548686752319,
"updated": 1548686829227,
"status": "new",
"side": "buy",
"orderType": "limit",
"amount": "1.1",
"amountRemaining": "1.1",
"price": "2000",
"onHold": "2205.5",
"onHoldCurrency": "EUR",
"filledAmount": "0",
"filledAmountQuote": "0",
"feePaid": "0",
"feeCurrency": "EUR",
"fills": [],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
获取订单
$response = $bitvavo->getOrder("BTC-EUR", "97d89ffc-2339-4e8f-8032-bf7b8c9ee65b"); echo json_encode($response) . "\n";
查看响应
{
"orderId": "97d89ffc-2339-4e8f-8032-bf7b8c9ee65b",
"market": "BTC-EUR",
"created": 1548686752319,
"updated": 1548686752319,
"status": "new",
"side": "buy",
"orderType": "limit",
"amount": "1",
"amountRemaining": "1",
"price": "2000",
"onHold": "2005",
"onHoldCurrency": "EUR",
"filledAmount": "0",
"filledAmountQuote": "0",
"feePaid": "0",
"feeCurrency": "EUR",
"fills": [],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
取消订单
$response = $bitvavo->cancelOrder("BTC-EUR", "2557ace7-f9f3-4c15-8911-46022f01cf72"); echo json_encode($response) . "\n";
查看响应
{
"orderId":"2557ace7-f9f3-4c15-8911-46022f01cf72"
}
获取订单
返回与获取订单相同,但可用于一次性返回多个订单。
// options: limit, start, end, orderIdFrom, orderIdTo foreach ($bitvavo->getOrders("BTC-EUR", []) as $order) { echo json_encode($order) . "\n"; }
查看响应
{
"orderId": "97d89ffc-2339-4e8f-8032-bf7b8c9ee65b",
"market": "BTC-EUR",
"created": 1548686752319,
"updated": 1548686829227,
"status": "new",
"side": "buy",
"orderType": "limit",
"amount": "1.1",
"amountRemaining": "1.1",
"price": "2000",
"onHold": "2205.5",
"onHoldCurrency": "EUR",
"filledAmount": "0",
"filledAmountQuote": "0",
"feePaid": "0",
"feeCurrency": "EUR",
"fills": [],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
{
"orderId": "d0471852-d753-44a9-bc9a-a3f0ddb7c209",
"market": "BTC-EUR",
"created": 1548685870294,
"updated": 1548685870294,
"status": "filled",
"side": "buy",
"orderType": "limit",
"amount": "1",
"amountRemaining": "0",
"price": "3000",
"onHold": "0",
"onHoldCurrency": "EUR",
"filledAmount": "1",
"filledAmountQuote": "2996",
"feePaid": "7.49",
"feeCurrency": "EUR",
"fills": [
{
"id": "616bfa4e-b3ff-4b3f-a394-1538a49eb9bc",
"timestamp": 1548685870299,
"amount": "1",
"price": "2996",
"taker": true,
"fee": "7.49",
"feeCurrency": "EUR",
"settled": true
}
],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
{
"orderId": "80b5f04d-21fc-4ebe-9c5f-6d34f78ee477",
"market": "BTC-EUR",
"created": 1548684420771,
"updated": 1548684420771,
"status": "filled",
"side": "buy",
"orderType": "limit",
"amount": "1",
"amountRemaining": "0",
"price": "3000",
"onHold": "0",
"onHoldCurrency": "EUR",
"filledAmount": "1",
"filledAmountQuote": "2994.47228569",
"feePaid": "7.48771431",
"feeCurrency": "EUR",
"fills": [
{
"id": "ae9b627c-3e64-4c71-b80a-9f674498b478",
"timestamp": 1548684420781,
"amount": "0.82771431",
"price": "2994.3",
"taker": true,
"fee": "6.205041567",
"feeCurrency": "EUR",
"settled": true
},
{
"id": "64cc0e3d-6e7b-451c-9034-9a6dc6c4665a",
"timestamp": 1548684420790,
"amount": "0.17228569",
"price": "2995.3",
"taker": true,
"fee": "1.282672743",
"feeCurrency": "EUR",
"settled": true
}
],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
...
取消订单
取消市场中的所有订单。如果未指定市场,将取消该账户的所有订单。
// options: market foreach ($bitvavo->cancelOrders([]) as $order) { echo json_encode($order) . "\n"; }
查看响应
{
"orderId":"8b1c491b-13bd-40e1-b4fa-7d8ecf1f4fc3"
}
{
"orderId":"95313ae5-ad65-4430-a0fb-63591bbc337c"
}
{
"orderId":"2465c3ab-5ae2-4d4d-bec7-345f51b3494d"
}
...
获取未成交订单
返回所有未成交或已取消的订单。
// options: market foreach ($bitvavo->ordersOpen([]) as $order) { echo json_encode($order) . "\n"; }
查看响应
{
"orderId": "97d89ffc-2339-4e8f-8032-bf7b8c9ee65b",
"market": "BTC-EUR",
"created": 1548686752319,
"updated": 1548686829227,
"status": "new",
"side": "buy",
"orderType": "limit",
"amount": "1.1",
"amountRemaining": "1.1",
"price": "2000",
"onHold": "2205.5",
"onHoldCurrency": "EUR",
"filledAmount": "0",
"filledAmountQuote": "0",
"feePaid": "0",
"feeCurrency": "EUR",
"fills": [],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
{
"orderId": "2465c3ab-5ae2-4d4d-bec7-345f51b3494d",
"market": "BTC-EUR",
"created": 1548686566366,
"updated": 1548686789695,
"status": "new",
"side": "buy",
"orderType": "limit",
"amount": "1.0",
"amountRemaining": "1.0",
"price": "2200",
"onHold": "2205",
"onHoldCurrency": "EUR",
"filledAmount": "0",
"filledAmountQuote": "0",
"feePaid": "0",
"feeCurrency": "EUR",
"fills": [],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
...
获取交易
返回该账户在市场内的所有交易。
// options: limit, start, end, tradeIdFrom, tradeIdTo foreach ($bitvavo->trades("BTC-EUR", []) as $trade) { echo json_encode($trade) . "\n"; }
查看响应
{
"id": "616bfa4e-b3ff-4b3f-a394-1538a49eb9bc",
"timestamp": 1548685870299,
"market": "BTC-EUR",
"side": "buy",
"amount": "1",
"price": "2996",
"taker": true,
"fee": "7.49",
"feeCurrency": "EUR",
"settled": true
}
{
"id": "64cc0e3d-6e7b-451c-9034-9a6dc6c4665a",
"timestamp": 1548684420790,
"market": "BTC-EUR",
"side": "buy",
"amount": "0.17228569",
"price": "2995.3",
"taker": true,
"fee": "1.282672743",
"feeCurrency": "EUR",
"settled": true
}
{
"id": "ae9b627c-3e64-4c71-b80a-9f674498b478",
"timestamp": 1548684420781,
"market": "BTC-EUR",
"side": "buy",
"amount": "0.82771431",
"price": "2994.3",
"taker": true,
"fee": "6.205041567",
"feeCurrency": "EUR",
"settled": true
}
{
"id": "f78cc2d2-6044-4a6d-a86f-ff7d307142fb",
"timestamp": 1548683023452,
"market": "BTC-EUR",
"side": "sell",
"amount": "0.74190125",
"price": "2992.5",
"taker": true,
"fee": "5.549490625",
"feeCurrency": "EUR",
"settled": true
}
...
获取账户
返回该账户的费用层级。
$response = $bitvavo->account(); echo json_encode($response, JSON_PRETTY_PRINT) . "\n";
查看响应
{
"fees": {
"taker": "0.0025",
"maker": "0.0015",
"volume": "100.00"
}
}
获取余额
返回该账户的余额。
// options: symbol foreach ($bitvavo->balance([]) as $balance) { echo json_encode($balance) . "\n"; }
查看响应
{
"symbol": "EUR",
"available": "2599.95",
"inOrder": "2022.65"
}
{
"symbol": "BTC",
"available": "1.65437",
"inOrder": "0.079398"
}
{
"symbol": "ADA",
"available": "4.8",
"inOrder": "0"
}
{
"symbol": "BCH",
"available": "0.00952811",
"inOrder": "0"
}
{
"symbol": "BSV",
"available": "0.00952811",
"inOrder": "0"
}
...
存入资产
返回可用于存入资金的地址。
$response = $bitvavo->depositAssets("BTC"); echo json_encode($response) . "\n";
查看响应
{
"address": "BitcoinAddress"
}
提取资产
可用于从Bitvavo提取资金。
// optional parameters: paymentId, internal, addWithdrawalFee $response = $bitvavo->withdrawAssets("BTC", "1", "BitcoinAddress", []); echo json_encode($response) . "\n";
查看响应
{
"success": true,
"symbol": "BTC",
"amount": "1"
}
获取存款历史
返回您账户的存款历史。
// options: symbol, limit, start, end foreach ($bitvavo->depositHistory([]) as $deposit) { echo json_encode($deposit) . "\n"; }
查看响应
{
"timestamp": 1521550025000,
"symbol": "EUR",
"amount": "1",
"fee": "0",
"status": "completed",
"address": "NL12RABO324234234"
}
{
"timestamp": 1511873910000,
"symbol": "BTC",
"amount": "0.099",
"fee": "0",
"status": "completed",
"txId": "0c6497e608212a516b8218674cb0ca04f65b67a00fe8bddaa1ecb03e9b029255"
}
...
获取提取历史
返回账户的提取历史。
// options: symbol, limit, start, end foreach ($bitvavo->withdrawalHistory([]) as $withdrawal) { echo json_encode($withdrawal) . "\n"; }
查看响应
{
"timestamp": 1548687467000,
"symbol": "BTC",
"amount": "0.99994",
"fee": "0.00006",
"status": "awaiting_processing",
"address": "1CqtG5z55x7bYD5GxsAXPx59DEyujs4bjm"
}
{
"timestamp": 1548682993000,
"symbol": "BTC",
"amount": "0.99994",
"fee": "0.00006",
"status": "awaiting_processing",
"address": "1CqtG5z55x7bYD5GxsAXPx59DEyujs4bjm"
}
{
"timestamp": 1548425559000,
"symbol": "BTC",
"amount": "0.09994",
"fee": "0.00006",
"status": "awaiting_processing",
"address": "1CqtG5z55x7bYD5GxsAXPx59DEyujs4bjm"
}
{
"timestamp": 1548409721000,
"symbol": "EUR",
"amount": "50",
"fee": "0",
"status": "completed",
"address": "NL123BIM"
}
{
"timestamp": 1537803091000,
"symbol": "BTC",
"amount": "0.01939",
"fee": "0.00002",
"status": "completed",
"txId": "da2299c86fce67eb899aeaafbe1f81cf663a3850cf9f3337c92b2d87945532db",
"address": "3QpyxeA7yWWsSURXEmuBBzHpxjqn7Rbyme"
}
...
Websocket
所有可以通过REST请求完成的请求也可以通过Websocket执行。Bitvavo还提供了六个订阅。如果订阅了这些,针对该类型/市场的特定更新将立即推送。我们使用php的经验是,它的性能略低于我们的其他SDK,因此我们建议对于需要与交易所持续同步的程序,在另一种语言中实现。对于简单的操作或任何集成到网站中的函数,php就足够了。
入门
应通过$websock = $bitvavo->newWebSocket();函数初始化websocket对象。之后,应通过setErrorCallback()函数设置错误的回调。之后,可以调用任何所需的函数。最后,应通过startSocket()函数启动websocket。此调用是阻塞的,这意味着在startSocket()调用之后的任何代码将不会执行。当需要将一个函数的响应作为另一个函数的输入时,应在第一个函数的回调中调用第二个函数。
$websock = $bitvavo->newWebSocket(); $websock->setErrorCallback(function($msg) { echo "Handle errors here " . json_encode($msg) . "\n"; }); // Call your functions here, like: $websock->time(function($msg) { echo json_encode($msg) . "\n"; }); // When the response of the first call is required for the second call, make the second call in the callback. // For demonstration purposes only, since the same could be achieved through cancelOrders(). $websock->ordersOpen(["market"=>"BTC-EUR" ], function($orderResponse) use ($webSock) { foreach ($orderResponse as $order) { $websock->cancelOrder("BTC-EUR", $order["orderId"], function($cancelResponse) { echo json_encode($cancelResponse) . "\n"; }); } }); $websock->startSocket(); // Any code written here will not be executed until the websocket has been closed.
API密钥和密钥是从bitvavo对象中复制的。因此,如果您想使用Websocket API的私有部分,应设置如REST请求中指定的密钥和密钥。
公共
获取时间
$websock->time(function($response) { echo json_encode($response) . "\n"; });
查看响应
{
"time": 1548686055654
}
获取市场
// options: market $websock->markets([], function($response) { foreach ($response as $market) { echo json_encode($market) . "\n"; } });
查看响应
{
"market": "ADA-BTC",
"status": "trading",
"base": "ADA",
"quote": "BTC",
"pricePrecision": 5,
"minOrderInBaseAsset": "100",
"minOrderInQuoteAsset": "0.001",
"orderTypes": [
"market",
"limit"
]
}
{
"market": "ADA-EUR",
"status": "trading",
"base": "ADA",
"quote": "EUR",
"pricePrecision": 5,
"minOrderInBaseAsset": "100",
"minOrderInQuoteAsset": "10",
"orderTypes": [
"market",
"limit"
]
}
{
"market": "AE-BTC",
"status": "trading",
"base": "AE",
"quote": "BTC",
"pricePrecision": 5,
"minOrderInBaseAsset": "10",
"minOrderInQuoteAsset": "0.001",
"orderTypes": [
"market",
"limit"
]
}
{
"market": "AE-EUR",
"status": "trading",
"base": "AE",
"quote": "EUR",
"pricePrecision": 5,
"minOrderInBaseAsset": "10",
"minOrderInQuoteAsset": "10",
"orderTypes": [
"market",
"limit"
]
}
...
获取资产
// options: symbol $websock->assets([], function($response) { foreach ($response as $asset) { echo json_encode($asset) . "\n"; } });
查看响应
{
"symbol": "ADA",
"name": "Cardano",
"decimals": 6,
"depositFee": "0",
"depositConfirmations": 20,
"depositStatus": "OK",
"withdrawalFee": "0.2",
"withdrawalMinAmount": "0.2",
"withdrawalStatus": "OK",
"networks": [
"Mainnet"
],
"message": ""
}
{
"symbol": "AE",
"name": "Aeternity",
"decimals": 8,
"depositFee": "0",
"depositConfirmations": 30,
"depositStatus": "OK",
"withdrawalFee": "2",
"withdrawalMinAmount": "2",
"withdrawalStatus": "OK",
"networks": [
"Mainnet"
],
"message": ""
}
{
"symbol": "AION",
"name": "Aion",
"decimals": 8,
"depositFee": "0",
"depositConfirmations": 0,
"depositStatus": "",
"withdrawalFee": "3",
"withdrawalMinAmount": "3",
"withdrawalStatus": "",
"networks": [
"Mainnet"
],
"message": ""
}
{
"symbol": "ANT",
"name": "Aragon",
"decimals": 8,
"depositFee": "0",
"depositConfirmations": 30,
"depositStatus": "OK",
"withdrawalFee": "2",
"withdrawalMinAmount": "2",
"withdrawalStatus": "OK",
"networks": [
"Mainnet"
],
"message": ""
}
...
按市场获取订单簿
// options: depth $websock->book("BTC-EUR", [], function($response) { echo json_encode($response) . "\n"; });
查看响应
{
"market": "BTC-EUR",
"nonce": 5111,
"bids": [
[
"2998.9",
"2.14460302"
],
[
"2998.4",
"0.35156557"
],
[
"2997",
"0.97089768"
],
[
"2996.5",
"0.74129861"
],
[
"2996",
"0.33746089"
],
...
],
"asks": [
[
"2999",
"0.34445088"
],
[
"2999.5",
"0.32306421"
],
[
"3000",
"0.37908805"
],
[
"3000.6",
"0.85330708"
],
[
"3001.7",
"0.31230068"
],
...
]
}
按市场获取交易
// options: limit, start, end $websock->publicTrades("BTC-EUR", [], function($response) { echo json_encode($response) . "\n"; });
查看响应
{
"id": "99cee743-1a9b-4dd4-8337-2a384e490554",
"timestamp": 1548685961053,
"amount": "0.55444771",
"price": "2996.3",
"side": "buy"
}
{
"id": "12d442cf-23a2-43c4-ae20-4b3d61a5993c",
"timestamp": 1548685961047,
"amount": "0.44555229",
"price": "2995.7",
"side": "buy"
}
{
"id": "75335db3-5b94-48af-bdc9-8716e0a3d6ae",
"timestamp": 1548685918958,
"amount": "1",
"price": "2996.1",
"side": "buy"
}
{
"id": "616bfa4e-b3ff-4b3f-a394-1538a49eb9bc",
"timestamp": 1548685870299,
"amount": "1",
"price": "2996",
"side": "buy"
}
{
"id": "34cdda49-3e9d-4d8f-a1aa-3176f61d9c27",
"timestamp": 1548684756948,
"amount": "0.79946345",
"price": "2996.3",
"side": "buy"
}
{
"id": "525a2ae0-7c0d-4945-9e4f-cf5729b44c5c",
"timestamp": 1548684756939,
"amount": "0.06202504",
"price": "2995.6",
"side": "buy"
}
...
按市场获取蜡烛
// options: limit $websock->candles("LTC-EUR", "1h", [], function($response) { foreach ($response as $candle) { echo json_encode($candle) . "\n"; } });
查看响应
[
1548684000000,
"2993.7",
"2996.9",
"2992.5",
"2993.7",
"9"
]
[
1548684000000,
"2993.7",
"2996.9",
"2992.5",
"2993.7",
"9"
]
[
1548676800000,
"2999.3",
"3002.6",
"2989.2",
"2999.3",
"63.00046504"
]
[
1548669600000,
"3012.9",
"3015.8",
"3000",
"3012.9",
"8"
]
[
1548417600000,
"3124",
"3125.1",
"3124",
"3124",
"0.1"
]
...
获取价格指示器
// options: market $websock->tickerPrice([], function($response) { foreach ($response as $price) { echo json_encode($price) . "\n"; } });
查看响应
{
"market": "EOS-EUR",
"price": "2.0142"
}
{
"market": "XRP-EUR",
"price": "0.25193"
}
{
"market": "ETH-EUR",
"price": "91.1"
}
{
"market": "IOST-EUR",
"price": "0.005941"
}
{
"market": "BCH-EUR",
"price": "106.57"
}
{
"market": "BTC-EUR",
"price": "3000.2"
}
{
"market": "STORM-EUR",
"price": "0.0025672"
}
{
"market": "EOS-BTC",
"price": "0.00066289"
}
{
"market": "BSV-EUR",
"price": "57.6"
}
...
获取订单簿指示器
// options: market $websock->tickerBook([], function($response) { foreach ($response as $book) { echo json_encode($book) . "\n"; } });
查看响应
{
"market": "XVG-BTC",
"bid": "0.00000045",
"ask": "0.00000046",
"bidSize": "28815.01275017",
"askSize": "38392.85089495"
}
{
"market": "XVG-EUR",
"bid": "0.0042213",
"ask": "0.0043277",
"bidSize": "1695671.24837763",
"askSize": "792229.47382889"
}
{
"market": "ZIL-BTC",
"bid": "0.00000082",
"ask": "0.00000083",
"bidSize": "140980.13397262",
"askSize": "98839.99285373"
}
{
"market": "ZIL-EUR",
"bid": "0.0076923",
"ask": "0.0077929",
"bidSize": "348008.13304576",
"askSize": "151544.09942432"
}
{
"market": "ZRX-BTC",
"bid": "0.00001679",
"ask": "0.0000168",
"bidSize": "633.12153002",
"askSize": "1280.07668593"
}
{
"market": "ZRX-EUR",
"bid": "0.1575",
"ask": "0.15774",
"bidSize": "875.01315351",
"askSize": "1013.62085819"
}
...
获取24小时指示器
// options: market $websock->ticker24h([], function($response) { foreach ($response as $ticker) { echo json_encode($ticker) . "\n"; } });
查看响应
{
"market": "XVG-EUR",
"open": "0.0043222",
"high": "0.0044139",
"low": "0.0040849",
"last": "0.0041952",
"volume": "1237140.82971657",
"volumeQuote": "5267.56",
"bid": "0.0042245",
"bidSize": "1704411.59895476",
"ask": "0.0043217",
"askSize": "2419888.08209617",
"timestamp": 1565777160307
}
{
"market": "ZIL-EUR",
"open": "0.008125",
"high": "0.0082359",
"low": "0.0076094",
"last": "0.0077285",
"volume": "738574.75091114",
"volumeQuote": "5724.92",
"bid": "0.007698",
"bidSize": "347552.37282041",
"ask": "0.0077977",
"askSize": "151544.09942432",
"timestamp": 1565777159934
}
{
"market": "ZRX-EUR",
"open": "0.16326",
"high": "0.16326",
"low": "0.15812",
"last": "0.15858",
"volume": "4855.99528525",
"volumeQuote": "779.72",
"bid": "0.15748",
"bidSize": "874.65298311",
"ask": "0.15775",
"askSize": "545.84965752",
"timestamp": 1565777159932
}
...
私有
下单
在下单时,请确保设置了正确的可选参数。对于限价订单,必须设置数量和价格。如果设置了数量或数量引用,则市价订单有效。
// optional parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection), // stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount) // stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount) // all orderTypes: timeInForce, selfTradePrevention, responseRequired $websock->placeOrder("BTC-EUR", "buy", "limit", ["amount" => "0.1", "price" => "5000"], function($response) { echo json_encode($response) . "\n"; });
查看响应
{
"orderId": "97d89ffc-2339-4e8f-8032-bf7b8c9ee65b",
"market": "BTC-EUR",
"created": 1548686752319,
"updated": 1548686752319,
"status": "new",
"side": "buy",
"orderType": "limit",
"amount": "1",
"amountRemaining": "1",
"price": "2000",
"onHold": "2005",
"onHoldCurrency": "EUR",
"filledAmount": "0",
"filledAmountQuote": "0",
"feePaid": "0",
"feeCurrency": "EUR",
"fills": [],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
更新订单
在更新订单时,请确保已设置至少一个可选参数。否则无法更新。
// Optional parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly) // untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount) // stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount) $websock->updateOrder("BTC-EUR", "68322e0d-1a41-4e39-bc26-8c9b9a268a81", ["amount" => "0.2"], function($response) { echo json_encode($response) . "\n"; });
查看响应
{
"orderId": "97d89ffc-2339-4e8f-8032-bf7b8c9ee65b",
"market": "BTC-EUR",
"created": 1548686752319,
"updated": 1548686829227,
"status": "new",
"side": "buy",
"orderType": "limit",
"amount": "1.1",
"amountRemaining": "1.1",
"price": "2000",
"onHold": "2205.5",
"onHoldCurrency": "EUR",
"filledAmount": "0",
"filledAmountQuote": "0",
"feePaid": "0",
"feeCurrency": "EUR",
"fills": [],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
获取订单
$websock->getOrder("BTC-EUR", "68322e0d-1a41-4e39-bc26-8c9b9a268a81", function($response) { echo json_encode($response) . "\n"; });
查看响应
{
"orderId": "97d89ffc-2339-4e8f-8032-bf7b8c9ee65b",
"market": "BTC-EUR",
"created": 1548686752319,
"updated": 1548686752319,
"status": "new",
"side": "buy",
"orderType": "limit",
"amount": "1",
"amountRemaining": "1",
"price": "2000",
"onHold": "2005",
"onHoldCurrency": "EUR",
"filledAmount": "0",
"filledAmountQuote": "0",
"feePaid": "0",
"feeCurrency": "EUR",
"fills": [],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
取消订单
$websock->cancelOrder("BTC-EUR", "68322e0d-1a41-4e39-bc26-8c9b9a268a81", function($response) { echo json_encode($response) . "\n"; });
查看响应
{
"orderId":"2557ace7-f9f3-4c15-8911-46022f01cf72"
}
获取订单
返回与获取订单相同,但可用于一次性返回多个订单。
// options: limit, start, end, orderIdFrom, orderIdTo $websock->getOrders("BTC-EUR", [], function($response) { foreach ($response as $order) { echo json_encode($order) . "\n"; } });
查看响应
{
"orderId": "97d89ffc-2339-4e8f-8032-bf7b8c9ee65b",
"market": "BTC-EUR",
"created": 1548686752319,
"updated": 1548686829227,
"status": "new",
"side": "buy",
"orderType": "limit",
"amount": "1.1",
"amountRemaining": "1.1",
"price": "2000",
"onHold": "2205.5",
"onHoldCurrency": "EUR",
"filledAmount": "0",
"filledAmountQuote": "0",
"feePaid": "0",
"feeCurrency": "EUR",
"fills": [],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
{
"orderId": "d0471852-d753-44a9-bc9a-a3f0ddb7c209",
"market": "BTC-EUR",
"created": 1548685870294,
"updated": 1548685870294,
"status": "filled",
"side": "buy",
"orderType": "limit",
"amount": "1",
"amountRemaining": "0",
"price": "3000",
"onHold": "0",
"onHoldCurrency": "EUR",
"filledAmount": "1",
"filledAmountQuote": "2996",
"feePaid": "7.49",
"feeCurrency": "EUR",
"fills": [
{
"id": "616bfa4e-b3ff-4b3f-a394-1538a49eb9bc",
"timestamp": 1548685870299,
"amount": "1",
"price": "2996",
"taker": true,
"fee": "7.49",
"feeCurrency": "EUR",
"settled": true
}
],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
{
"orderId": "80b5f04d-21fc-4ebe-9c5f-6d34f78ee477",
"market": "BTC-EUR",
"created": 1548684420771,
"updated": 1548684420771,
"status": "filled",
"side": "buy",
"orderType": "limit",
"amount": "1",
"amountRemaining": "0",
"price": "3000",
"onHold": "0",
"onHoldCurrency": "EUR",
"filledAmount": "1",
"filledAmountQuote": "2994.47228569",
"feePaid": "7.48771431",
"feeCurrency": "EUR",
"fills": [
{
"id": "ae9b627c-3e64-4c71-b80a-9f674498b478",
"timestamp": 1548684420781,
"amount": "0.82771431",
"price": "2994.3",
"taker": true,
"fee": "6.205041567",
"feeCurrency": "EUR",
"settled": true
},
{
"id": "64cc0e3d-6e7b-451c-9034-9a6dc6c4665a",
"timestamp": 1548684420790,
"amount": "0.17228569",
"price": "2995.3",
"taker": true,
"fee": "1.282672743",
"feeCurrency": "EUR",
"settled": true
}
],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
...
取消订单
取消市场中的所有订单。如果未指定市场,将取消该账户的所有订单。
// options: market $websock->cancelOrders(["market" => "BTC-EUR"], function($response) { foreach ($response as $deletion) { echo json_encode($deletion) . "\n"; } });
查看响应
{
"orderId":"8b1c491b-13bd-40e1-b4fa-7d8ecf1f4fc3"
}
{
"orderId":"95313ae5-ad65-4430-a0fb-63591bbc337c"
}
{
"orderId":"2465c3ab-5ae2-4d4d-bec7-345f51b3494d"
}
...
获取未成交订单
返回所有未成交或已取消的订单。
// options: market $websock->ordersOpen([], function($response) { foreach ($response as $order) { echo json_encode($order) . "\n"; } });
查看响应
{
"orderId": "97d89ffc-2339-4e8f-8032-bf7b8c9ee65b",
"market": "BTC-EUR",
"created": 1548686752319,
"updated": 1548686829227,
"status": "new",
"side": "buy",
"orderType": "limit",
"amount": "1.1",
"amountRemaining": "1.1",
"price": "2000",
"onHold": "2205.5",
"onHoldCurrency": "EUR",
"filledAmount": "0",
"filledAmountQuote": "0",
"feePaid": "0",
"feeCurrency": "EUR",
"fills": [],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
{
"orderId": "2465c3ab-5ae2-4d4d-bec7-345f51b3494d",
"market": "BTC-EUR",
"created": 1548686566366,
"updated": 1548686789695,
"status": "new",
"side": "buy",
"orderType": "limit",
"amount": "1.0",
"amountRemaining": "1.0",
"price": "2200",
"onHold": "2205",
"onHoldCurrency": "EUR",
"filledAmount": "0",
"filledAmountQuote": "0",
"feePaid": "0",
"feeCurrency": "EUR",
"fills": [],
"selfTradePrevention": "decrementAndCancel",
"visible": true,
"timeInForce": "GTC",
"postOnly": false
}
...
获取交易
返回该账户在市场内的所有交易。
// options: limit, start, end, tradeIdFrom, tradeIdTo $websock->trades("BTC-EUR", [], function($response) { foreach ($response as $trade) { echo json_encode($trade) . "\n"; } });
查看响应
{
"id": "616bfa4e-b3ff-4b3f-a394-1538a49eb9bc",
"timestamp": 1548685870299,
"market": "BTC-EUR",
"side": "buy",
"amount": "1",
"price": "2996",
"taker": true,
"fee": "7.49",
"feeCurrency": "EUR",
"settled": true
}
{
"id": "64cc0e3d-6e7b-451c-9034-9a6dc6c4665a",
"timestamp": 1548684420790,
"market": "BTC-EUR",
"side": "buy",
"amount": "0.17228569",
"price": "2995.3",
"taker": true,
"fee": "1.282672743",
"feeCurrency": "EUR",
"settled": true
}
{
"id": "ae9b627c-3e64-4c71-b80a-9f674498b478",
"timestamp": 1548684420781,
"market": "BTC-EUR",
"side": "buy",
"amount": "0.82771431",
"price": "2994.3",
"taker": true,
"fee": "6.205041567",
"feeCurrency": "EUR",
"settled": true
}
{
"id": "f78cc2d2-6044-4a6d-a86f-ff7d307142fb",
"timestamp": 1548683023452,
"market": "BTC-EUR",
"side": "sell",
"amount": "0.74190125",
"price": "2992.5",
"taker": true,
"fee": "5.549490625",
"feeCurrency": "EUR",
"settled": true
}
...
获取账户
返回该账户的费用层级。
$websock->account(function($response) { echo json_encode($response, JSON_PRETTY_PRINT) . "\n"; });
查看响应
{
"fees": {
"taker": "0.0025",
"maker": "0.0015",
"volume": "100.00"
}
}
获取余额
返回该账户的余额。
// options: symbol $websock->balance([], function($response) { foreach ($response as $balance) { echo json_encode($balance) . "\n"; } });
查看响应
{
"symbol": "EUR",
"available": "2599.95",
"inOrder": "2022.65"
}
{
"symbol": "BTC",
"available": "1.65437",
"inOrder": "0.079398"
}
{
"symbol": "ADA",
"available": "4.8",
"inOrder": "0"
}
{
"symbol": "BCH",
"available": "0.00952811",
"inOrder": "0"
}
{
"symbol": "BSV",
"available": "0.00952811",
"inOrder": "0"
}
...
存入资产
返回可用于存入资金的地址。
$websock->depositAssets("BTC", function($response) { echo json_encode($response) . "\n"; });
查看响应
{
"address": "BitcoinAddress"
}
提取资产
可用于从Bitvavo提取资金。
// optional parameters: paymentId, internal, addWithdrawalFee $websock->withdrawAssets("BTC", "1", "BitcoinAddress", [], function($response) { echo json_encode($response) . "\n"; });
查看响应
{
"success": true,
"symbol": "BTC",
"amount": "1"
}
获取存款历史
返回您账户的存款历史。
// options: symbol, limit, start, end $websock->depositHistory([], function($response) { foreach ($response as $deposit) { echo json_encode($deposit) . "\n"; } });
查看响应
{
"timestamp": 1521550025000,
"symbol": "EUR",
"amount": "1",
"fee": "0",
"status": "completed",
"address": "NL12RABO324234234"
}
{
"timestamp": 1511873910000,
"symbol": "BTC",
"amount": "0.099",
"fee": "0",
"status": "completed",
"txId": "0c6497e608212a516b8218674cb0ca04f65b67a00fe8bddaa1ecb03e9b029255"
}
...
获取提取历史
返回账户的提取历史。
// options: symbol, limit, start, end $websock->withdrawalHistory([], function($response) { foreach ($response as $withdrawal) { echo json_encode($withdrawal) . "\n"; } });
查看响应
{
"timestamp": 1548687467000,
"symbol": "BTC",
"amount": "0.99994",
"fee": "0.00006",
"status": "awaiting_processing",
"address": "1CqtG5z55x7bYD5GxsAXPx59DEyujs4bjm"
}
{
"timestamp": 1548682993000,
"symbol": "BTC",
"amount": "0.99994",
"fee": "0.00006",
"status": "awaiting_processing",
"address": "1CqtG5z55x7bYD5GxsAXPx59DEyujs4bjm"
}
{
"timestamp": 1548425559000,
"symbol": "BTC",
"amount": "0.09994",
"fee": "0.00006",
"status": "awaiting_processing",
"address": "1CqtG5z55x7bYD5GxsAXPx59DEyujs4bjm"
}
{
"timestamp": 1548409721000,
"symbol": "EUR",
"amount": "50",
"fee": "0",
"status": "completed",
"address": "NL123BIM"
}
{
"timestamp": 1537803091000,
"symbol": "BTC",
"amount": "0.01939",
"fee": "0.00002",
"status": "completed",
"txId": "da2299c86fce67eb899aeaafbe1f81cf663a3850cf9f3337c92b2d87945532db",
"address": "3QpyxeA7yWWsSURXEmuBBzHpxjqn7Rbyme"
}
...
订阅
交易牌价订阅
每次最佳买入价、最佳卖出价或最新价格发生变化时发送更新。
$websock->subscriptionTicker("BTC-EUR", function($response) { echo json_encode($response) . "\n"; });
查看响应
{
"event": "ticker",
"market": "BTC-EUR",
"bestAsk": "9410.1",
"bestAskSize": "0.10847628",
"lastPrice": "9335"
}
24小时交易牌价订阅
更新后的ticker24h对象将每秒通过此通道发送一次。如果除时间戳之外的值发生变化,则认为ticker24h对象已更新。
$websock->subscriptionTicker24h("BTC-EUR", function($response) { echo json_encode($response) . "\n"; });
查看响应
{
"market": "BTC-EUR",
"open": "10061",
"high": "10061",
"low": "9265.4",
"last": "9400.3",
"volume": "309.30172822",
"volumeQuote": "2993760.89",
"bid": "9400.1",
"bidSize": "0.10576468",
"ask": "9400.4",
"askSize": "0.10858821",
"timestamp": 1565777506453
}
账户订阅
每当发生与账户相关的事件时,都会发送更新。这些是“订单”事件(创建、更新、取消)或“成交”事件(发生了交易)。
$websock->subscriptionAccount("BTC-EUR", function($function){ echo json_encode($response) . "\n"; });
查看响应
Fill: { "event": "fill", "timestamp": 1548688159231, "market": "BTC-EUR", "orderId": "a7844f9d-2f63-46ae-b96f-0df1a63dc6ae", "fillId": "0b921924-9ee7-4276-b63c-1681f49d016c", "side": "buy", "amount": "0.36346668", "price": "2993.9", "taker": true, "fee": "2.717106748", "feeCurrency": "EUR" } Order: { "event": "order", "orderId": "a7844f9d-2f63-46ae-b96f-0df1a63dc6ae", "market": "BTC-EUR", "created": 1548688159220, "updated": 1548688159220, "status": "filled", "side": "buy", "orderType": "limit", "amount": "1", "amountRemaining": "0", "price": "3000", "onHold": "2.24", "onHoldCurrency": "EUR", "selfTradePrevention": "decrementAndCancel", "visible": true, "timeInForce": "GTC", "postOnly": false }
蜡烛订阅
对于指定区间和市场的每笔交易发送更新的蜡烛。
$websock->subscriptionCandles("BTC-EUR", "1h", function($response) { echo json_encode($response) . "\n"; });
查看响应
{
"event": "candle",
"market": "BTC-EUR",
"interval": "1h",
"candle": [
[
1548687600000,
"2998.2",
"3000.3",
"2990.8",
"2998.2",
"3.05"
]
]
}
交易订阅
每当该市场发生交易时发送更新。对于您自己的交易,请订阅账户。
$websock->subscriptionTrades("BTC-EUR", function($response) { echo json_encode($response) . "\n"; });
查看响应
{
"event": "trade",
"timestamp": 1548688231625,
"market": "BTC-EUR",
"id": "9956f4c9-b9e3-4ec9-9793-1070ef56c016",
"amount": "0.05",
"price": "2992.9",
"side": "sell"
}
订单簿订阅
每当该特定市场的订单簿发生变化时发送更新。返回一个由元组([价格,数量])组成的列表,其中数量‘0’表示该价格没有更多订单。如果您想维护自己订单簿的副本,请考虑使用下一个函数。尽管将接收到所有更新,但与其他语言相比可能会略有延迟。在使用此函数进行自动交易时,请考虑用另一种语言进行编码。
$webSock->subscriptionBookUpdate("BTC-EUR", function($response){ echo json_encode($response) . "\n"; });
查看响应
{
"event": "book",
"market": "BTC-EUR",
"nonce": 18592,
"bids": [
[
"2986",
"0"
]
],
"asks": [
[
"2986.6",
"0"
],
[
"2986.5",
"0.00335008"
]
]
}
带有本地副本的订单簿订阅
这是“按市场获取图书”和“图书订阅”的结合,它维护了本地副本。每当订单簿更新时,整个订单簿都会返回到回调函数中,而图书订阅只会返回图书的更新。虽然会接收到所有更新,但与其他语言相比可能会略有延迟。在用于自动化交易时,请考虑使用其他语言的编码。
$websock->subscriptionBook("BTC-EUR", function($response) { echo json_encode($response) . "\n"; });
查看响应
{
"bids": [
[
"2986.3",
"0.0033503"
],
[
"2985.8",
"0.00335087"
],
[
"2985",
"0.00335176"
],
[
"2984.4",
"0.00335244"
],
[
"2984.1",
"2.06836375"
],
...
],
"asks": [
[
"2986.4",
"0.00335019"
],
[
"2987.1",
"0.00334996"
],
[
"2987.5",
"0.00335008"
],
[
"2988.2",
"0.00334996"
],
[
"2989",
"5.19132723"
],
...
],
"nonce": 18632
}