Skip to content

Commit e7e50ed

Browse files
Joeri van VuurenJoeri van Vuuren
authored andcommitted
✨ New account endpoint, stoploss example
1 parent f89d307 commit e7e50ed

File tree

4 files changed

+84
-10
lines changed

4 files changed

+84
-10
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
setup.py
3+
dist
4+
python_bitvavo_api.egg-info

README.md

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This is the python wrapper for the Bitvavo API. This project can be used to buil
2727
* Cancel Orders [REST](https://github.com/bitvavo/python-bitvavo-api#cancel-orders) [Websocket](https://github.com/bitvavo/python-bitvavo-api#cancel-orders-1)
2828
* Orders Open [REST](https://github.com/bitvavo/python-bitvavo-api#get-orders-open) [Websocket](https://github.com/bitvavo/python-bitvavo-api#get-orders-open-1)
2929
* Trades [REST](https://github.com/bitvavo/python-bitvavo-api#get-trades) [Websocket](https://github.com/bitvavo/python-bitvavo-api#get-trades-1)
30+
* Account [REST](https://github.com/bitvavo/python-bitvavo-api#get-account) [Websocket](https://github.com/bitvavo/python-bitvavo-api#get-account-1)
3031
* Balance [REST](https://github.com/bitvavo/python-bitvavo-api#get-balance) [Websocket](https://github.com/bitvavo/python-bitvavo-api#get-balance-1)
3132
* Deposit Assets [REST](https://github.com/bitvavo/python-bitvavo-api#deposit-assets) [Websocket](https://github.com/bitvavo/python-bitvavo-api#deposit-assets-1)
3233
* Withdraw Assets [REST](https://github.com/bitvavo/python-bitvavo-api#withdraw-assets) [Websocket](https://github.com/bitvavo/python-bitvavo-api#withdraw-assets-1)
@@ -563,7 +564,9 @@ print(response)
563564
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 amount or amountQuote is set.
564565
```python
565566
# optional parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection),
566-
# both: timeInForce, selfTradePrevention, responseRequired
567+
# stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
568+
# stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
569+
# all orderTypes: timeInForce, selfTradePrevention, responseRequired
567570
response = bitvavo.placeOrder('BTC-EUR', 'buy', 'limit', { 'amount': '1', 'price': '3000' })
568571
print(response)
569572
```
@@ -601,7 +604,8 @@ print(response)
601604
When updating an order make sure that at least one of the optional parameters has been set. Otherwise nothing can be updated.
602605
```python
603606
# Optional parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
604-
# (set at least 1) (responseRequired can be set as well, but does not update anything)
607+
# untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
608+
# stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
605609
response = bitvavo.updateOrder('BTC-EUR', '5444f908-67c4-4c5d-a138-7e834b94360e', { 'amount': '1.1' })
606610
print(response)
607611
```
@@ -923,6 +927,26 @@ print(response)
923927
```
924928
</details>
925929

930+
#### Get account
931+
Returns the fee tier for this account.
932+
```python
933+
response = bitvavo.account()
934+
print(response)
935+
```
936+
<details>
937+
<summary>View Response</summary>
938+
939+
```python
940+
{
941+
"fees": {
942+
"taker": "0.0025",
943+
"maker": "0.0015",
944+
"volume": "100.00"
945+
}
946+
}
947+
```
948+
</details>
949+
926950
#### Get balance
927951
Returns the balance for this account.
928952
```python
@@ -1584,7 +1608,9 @@ websocket.ticker24h({}, timeCallback)
15841608
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 amount or amountQuote has been set.
15851609
```python
15861610
# optional parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection),
1587-
# both: timeInForce, selfTradePrevention, responseRequired
1611+
# stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
1612+
# stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
1613+
# all orderTypes: timeInForce, selfTradePrevention, responseRequired
15881614
websocket.placeOrder('BTC-EUR', 'buy', 'limit', { 'amount': '1', 'price': '3000' }, ownCallback)
15891615
```
15901616
<details>
@@ -1621,7 +1647,8 @@ websocket.placeOrder('BTC-EUR', 'buy', 'limit', { 'amount': '1', 'price': '3000'
16211647
When updating an order make sure that at least one of the optional parameters has been set. Otherwise nothing can be updated.
16221648
```python
16231649
# Optional parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
1624-
# (set at least 1) (responseRequired can be set as well, but does not update anything)
1650+
# untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
1651+
# stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
16251652
websocket.updateOrder('BTC-EUR', '5444f908-67c4-4c5d-a138-7e834b94360e', { 'amount': '1.1' }, ownCallback)
16261653
```
16271654
<details>
@@ -1936,6 +1963,25 @@ websocket.trades('BTC-EUR', {}, ownCallback)
19361963
```
19371964
</details>
19381965

1966+
#### Get account
1967+
Returns the fee tier for this account.
1968+
```python
1969+
websocket.account(ownCallback)
1970+
```
1971+
<details>
1972+
<summary>View Response</summary>
1973+
1974+
```python
1975+
{
1976+
"fees": {
1977+
"taker": "0.0025",
1978+
"maker": "0.0015",
1979+
"volume": "100.00"
1980+
}
1981+
}
1982+
```
1983+
</details>
1984+
19391985
#### Get balance
19401986
Returns the balance for this account.
19411987
```python

python_bitvavo_api/bitvavo.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ def ticker24h(self, options):
269269
postfix = createPostfix(options)
270270
return self.publicRequest((self.base + '/ticker/24h' + postfix))
271271

272-
# optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection), both: timeInForce, selfTradePrevention, responseRequired
272+
# optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection)
273+
# stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
274+
# stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
275+
# all orderTypes: timeInForce, selfTradePrevention, responseRequired
273276
def placeOrder(self, market, side, orderType, body):
274277
body['market'] = market
275278
body['side'] = side
@@ -280,8 +283,9 @@ def getOrder(self, market, orderId):
280283
postfix = createPostfix({ 'market': market, 'orderId': orderId })
281284
return self.privateRequest('/order', postfix, {}, 'GET')
282285

283-
# Optional body parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
284-
# (set at least 1) (responseRequired can be set as well, but does not update anything)
286+
# Optional parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
287+
# untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
288+
# stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
285289
def updateOrder(self, market, orderId, body):
286290
body['market'] = market
287291
body['orderId'] = orderId
@@ -313,6 +317,9 @@ def trades(self, market, options):
313317
postfix = createPostfix(options)
314318
return self.privateRequest('/trades', postfix, {}, 'GET')
315319

320+
def account(self):
321+
return self.privateRequest('/account', '', {}, 'GET')
322+
316323
# options: symbol
317324
def balance(self, options):
318325
postfix = createPostfix(options)
@@ -438,6 +445,8 @@ def on_message(ws, msg):
438445
callbacks['ordersOpen'](msg['response'])
439446
elif(msg['action'] == 'privateGetTrades'):
440447
callbacks['trades'](msg['response'])
448+
elif(msg['action'] == 'privateGetAccount'):
449+
callbacks['account'](msg['response'])
441450
elif(msg['action'] == 'privateGetBalance'):
442451
callbacks['balance'](msg['response'])
443452
elif(msg['action'] == 'privateDepositAssets'):
@@ -594,7 +603,10 @@ def tickerBook(self, options, callback):
594603
options['action'] = 'getTickerBook'
595604
self.doSend(self.ws, json.dumps(options))
596605

597-
# optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection), both: timeInForce, selfTradePrevention, responseRequired
606+
# optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection)
607+
# stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
608+
# stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
609+
# all orderTypes: timeInForce, selfTradePrevention, responseRequired
598610
def placeOrder(self, market, side, orderType, body, callback):
599611
self.callbacks['placeOrder'] = callback
600612
body['market'] = market
@@ -608,8 +620,9 @@ def getOrder(self, market, orderId, callback):
608620
options = { 'action': 'privateGetOrder', 'market': market, 'orderId': orderId }
609621
self.doSend(self.ws, json.dumps(options), True)
610622

611-
# Optional body parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
612-
# (set at least 1) (responseRequired can be set as well, but does not update anything)
623+
# Optional parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
624+
# untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
625+
# stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
613626
def updateOrder(self, market, orderId, body, callback):
614627
self.callbacks['updateOrder'] = callback
615628
body['market'] = market
@@ -648,6 +661,10 @@ def trades(self, market, options, callback):
648661
options['market'] = market
649662
self.doSend(self.ws, json.dumps(options), True)
650663

664+
def account(self, callback):
665+
self.callbacks['account'] = callback
666+
self.doSend(self.ws, json.dumps({ 'action': 'privateGetAccount' }), True)
667+
651668
# options: symbol
652669
def balance(self, options, callback):
653670
options['action'] = 'privateGetBalance'

python_bitvavo_api/testApi.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def testREST(bitvavo):
6666
# response = bitvavo.placeOrder('BTC-EUR', 'buy', 'limit', { 'amount': '0.1', 'price': '2000' })
6767
# print(json.dumps(response, indent=2))
6868

69+
# response = bitvavo.placeOrder('BTC-EUR', 'sell', 'stopLoss', { amount: '0.1', 'triggerType': 'price', 'triggerReference': 'lastTrade', 'triggerAmount': '5000' })
70+
# print(json.dumps(response, indent=2))
71+
6972
# response = bitvavo.getOrder('BTC-EUR', 'dd055772-0f02-493c-a049-f4356fa0d221')
7073
# print(json.dumps(response, indent=2))
7174

@@ -91,6 +94,9 @@ def testREST(bitvavo):
9194
# for item in response:
9295
# print(json.dumps(item, indent=2))
9396

97+
# response = bitvavo.account()
98+
# print(json.dumps(response, indent=2))
99+
94100
# response = bitvavo.balance({})
95101
# for item in response:
96102
# print(json.dumps(item, indent=2))
@@ -142,6 +148,7 @@ def testWebsockets(bitvavo):
142148

143149
# websocket.trades('BTC-EUR', {}, callback)
144150

151+
# websocket.account(callback)
145152
# websocket.balance({}, callback)
146153
# websocket.depositAssets('BTC', callback)
147154
# websocket.withdrawAssets('BTC', '1', 'BitcoinAddress', {}, callback)

0 commit comments

Comments
 (0)