Skip to content

Commit 3409d3f

Browse files
committed
✨ New account endpoint, stoploss example
1 parent 857b9eb commit 3409d3f

File tree

3 files changed

+83
-8
lines changed

3 files changed

+83
-8
lines changed

README.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This is the PHP wrapper for the Bitvavo API. This project can be used to build y
2727
* Cancel Orders [REST](https://github.com/bitvavo/php-bitvavo-api#cancel-orders) [Websocket](https://github.com/bitvavo/php-bitvavo-api#cancel-orders-1)
2828
* Orders Open [REST](https://github.com/bitvavo/php-bitvavo-api#get-orders-open) [Websocket](https://github.com/bitvavo/php-bitvavo-api#get-orders-open-1)
2929
* Trades [REST](https://github.com/bitvavo/php-bitvavo-api#get-trades) [Websocket](https://github.com/bitvavo/php-bitvavo-api#get-trades-1)
30+
* Account [REST](https://github.com/bitvavo/php-bitvavo-api#get-account) [Websocket](https://github.com/bitvavo/php-bitvavo-api#get-account-1)
3031
* Balance [REST](https://github.com/bitvavo/php-bitvavo-api#get-balance) [Websocket](https://github.com/bitvavo/php-bitvavo-api#get-balance-1)
3132
* Deposit Assets [REST](https://github.com/bitvavo/php-bitvavo-api#deposit-assets) [Websocket](https://github.com/bitvavo/php-bitvavo-api#deposit-assets-1)
3233
* Withdraw Assets [REST](https://github.com/bitvavo/php-bitvavo-api#withdraw-assets) [Websocket](https://github.com/bitvavo/php-bitvavo-api#withdraw-assets-1)
@@ -590,7 +591,9 @@ foreach ($bitvavo->ticker24h([]) as $ticker) {
590591
When placing an order, make sure that the correct optional parameters are set. For a limit order it is required to set both the amount and price. A market order is valid if either the amount or the amountQuote has been set.
591592
```PHP
592593
// optional parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection),
593-
// both: timeInForce, selfTradePrevention, responseRequired
594+
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
595+
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
596+
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
594597
$response = $bitvavo->placeOrder("BTC-EUR", "buy", "limit", ["amount" => "1", "price" => "2000"]);
595598
echo json_encode($response) . "\n";
596599
```
@@ -628,7 +631,8 @@ echo json_encode($response) . "\n";
628631
When updating an order make sure that at least one of the optional parameters has been set. Otherwise nothing can be updated.
629632
```PHP
630633
// Optional parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
631-
// (set at least 1) (responseRequired can be set as well, but does not update anything)
634+
// untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
635+
// stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
632636
$response = $bitvavo->updateOrder("BTC-EUR", "97d89ffc-2339-4e8f-8032-bf7b8c9ee65b", ["amount" => "1.1"]);
633637
echo json_encode($response) . "\n";
634638
```
@@ -980,6 +984,26 @@ foreach ($bitvavo->trades("BTC-EUR", []) as $trade) {
980984
```
981985
</details>
982986

987+
#### Get account
988+
Returns the fee tier for this account.
989+
```PHP
990+
$response = $bitvavo->account();
991+
echo json_encode($response, JSON_PRETTY_PRINT) . "\n";
992+
```
993+
<details>
994+
<summary>View Response</summary>
995+
996+
```PHP
997+
{
998+
"fees": {
999+
"taker": "0.0025",
1000+
"maker": "0.0015",
1001+
"volume": "100.00"
1002+
}
1003+
}
1004+
```
1005+
</details>
1006+
9831007
#### Get balance
9841008
Returns the balance for this account.
9851009
```PHP
@@ -1701,7 +1725,9 @@ $websock->ticker24h([], function($response) {
17011725
When placing an order, make sure that the correct optional parameters are set. For a limit order it is required to set both the amount and price. A market order is valid if either the amount or the amountQuote has been set.
17021726
```PHP
17031727
// optional parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection),
1704-
// both: timeInForce, selfTradePrevention, responseRequired
1728+
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
1729+
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
1730+
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
17051731
$websock->placeOrder("BTC-EUR", "buy", "limit", ["amount" => "0.1", "price" => "5000"], function($response) {
17061732
echo json_encode($response) . "\n";
17071733
});
@@ -1740,7 +1766,8 @@ $websock->placeOrder("BTC-EUR", "buy", "limit", ["amount" => "0.1", "price" => "
17401766
When updating an order make sure that at least one of the optional parameters has been set. Otherwise nothing can be updated.
17411767
```PHP
17421768
// Optional parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
1743-
// (set at least 1) (responseRequired can be set as well, but does not update anything)
1769+
// untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
1770+
// stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
17441771
$websock->updateOrder("BTC-EUR", "68322e0d-1a41-4e39-bc26-8c9b9a268a81", ["amount" => "0.2"], function($response) {
17451772
echo json_encode($response) . "\n";
17461773
});
@@ -2103,6 +2130,27 @@ $websock->trades("BTC-EUR", [], function($response) {
21032130
```
21042131
</details>
21052132

2133+
#### Get account
2134+
Returns the fee tier for this account.
2135+
```PHP
2136+
$websock->account(function($response) {
2137+
echo json_encode($response, JSON_PRETTY_PRINT) . "\n";
2138+
});
2139+
```
2140+
<details>
2141+
<summary>View Response</summary>
2142+
2143+
```PHP
2144+
{
2145+
"fees": {
2146+
"taker": "0.0025",
2147+
"maker": "0.0015",
2148+
"volume": "100.00"
2149+
}
2150+
}
2151+
```
2152+
</details>
2153+
21062154
#### Get balance
21072155
Returns the balance for this account.
21082156
```PHP

bitvavo.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ public function ticker24h($options) {
230230
return $this->sendPublic($this->base . "/ticker/24h", $options, "GET", "");
231231
}
232232

233-
// optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection), both: timeInForce, selfTradePrevention, responseRequired
233+
// optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection)
234+
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
235+
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
236+
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
234237
public function placeOrder($market, $side, $orderType, $body) {
235238
$body["market"] = $market;
236239
$body["side"] = $side;
@@ -244,7 +247,8 @@ public function getOrder($market, $orderId) {
244247
}
245248

246249
// Optional body parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
247-
// (set at least 1) (responseRequired can be set as well, but does not update anything)
250+
// untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
251+
// stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
248252
public function updateOrder($market, $orderId, $body) {
249253
$body["market"] = $market;
250254
$body["orderId"] = $orderId;
@@ -278,6 +282,10 @@ public function trades($market, $options) {
278282
return $this->sendPrivate("/trades", $options, [], "GET", $this->apiSecret, $this->base, $this->apiKey);
279283
}
280284

285+
public function account() {
286+
return $this->sendPrivate("/account", [], [], "GET", $this->apiSecret, $this->base, $this->apiKey);
287+
}
288+
281289
// options: symbol
282290
public function balance($options) {
283291
return $this->sendPrivate("/balance", $options, [], "GET", $this->apiSecret, $this->base, $this->apiKey);
@@ -518,6 +526,9 @@ public function handleMessage($msg) {
518526
case "privateGetTrades":
519527
call_user_func($this->tradesCallback, $jsonResponse["response"]);
520528
break;
529+
case "privateGetAccount":
530+
call_user_func($this->accountCallback, $jsonResponse["response"]);
531+
break;
521532
case "privateGetBalance":
522533
call_user_func($this->balanceCallback, $jsonResponse["response"]);
523534
break;
@@ -684,7 +695,10 @@ public function tickerBook($options, callable $callback) {
684695
$this->sendPublic($options);
685696
}
686697

687-
// optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection), both: timeInForce, selfTradePrevention, responseRequired
698+
// optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection)
699+
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
700+
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
701+
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
688702
public function placeOrder($market, $side, $orderType, $body, callable $callback) {
689703
$this->placeOrderCallback = $callback;
690704
$body["action"] = "privateCreateOrder";
@@ -700,7 +714,8 @@ public function getOrder($market, $orderId, callable $callback) {
700714
}
701715

702716
// Optional body parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
703-
// (set at least 1) (responseRequired can be set as well, but does not update anything)
717+
// untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
718+
// stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
704719
public function updateOrder($market, $orderId, $body, callable $callback) {
705720
$body["market"] = $market;
706721
$body["orderId"] = $orderId;
@@ -744,6 +759,11 @@ public function trades($market, $options, callable $callback) {
744759
$this->sendPrivate($options);
745760
}
746761

762+
public function account(callable $callback) {
763+
$this->accountCallback = $callback;
764+
$this->sendPrivate(["action" => "privateGetAccount"]);
765+
}
766+
747767
// options: symbol
748768
public function balance($options, callable $callback) {
749769
$options["action"] = "privateGetBalance";

example/example.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ function testREST($bitvavo) {
6666

6767
// $response = $bitvavo->placeOrder("BTC-EUR", "buy", "limit", ["amount" => "1", "price" => "2000"]);
6868
// echo json_encode($response, JSON_PRETTY_PRINT) . "\n";
69+
// $response = $bitvavo->placeOrder("BTC-EUR", "sell", "stopLoss", ["amount" => "0.1", "triggerType" => "price", "triggerReference" => "lastTrade", "triggerAmount" => "5000"]);
70+
// echo json_encode($response, JSON_PRETTY_PRINT) . "\n";
6971

7072
// $response = $bitvavo->getOrder("BTC-EUR", "db985cbc-70dd-4afd-a9ff-9ba363efab70");
7173
// echo json_encode($response, JSON_PRETTY_PRINT) . "\n";
@@ -93,6 +95,8 @@ function testREST($bitvavo) {
9395
// echo json_encode($trade, JSON_PRETTY_PRINT) . "\n";
9496
// }
9597

98+
// $response = $bitvavo->account();
99+
// echo json_encode($response, JSON_PRETTY_PRINT) . "\n";
96100

97101
// foreach ($bitvavo->balance([]) as $balance) {
98102
// echo json_encode($balance, JSON_PRETTY_PRINT) . "\n";
@@ -194,6 +198,9 @@ function testWebsocket($websock) {
194198
// }
195199
// });
196200

201+
// $websock->account(function($response) {
202+
// echo json_encode($response, JSON_PRETTY_PRINT) . "\n";
203+
// });
197204
// $websock->balance([], function($response) {
198205
// foreach ($response as $balance) {
199206
// echo json_encode($balance, JSON_PRETTY_PRINT) . "\n";

0 commit comments

Comments
 (0)