-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f894ff1
commit 159761d
Showing
5 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "1.1.0" | ||
__version__ = "1.1.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from typing import Optional | ||
|
||
from coinbase.constants import API_PREFIX | ||
|
||
|
||
def allocate_portfolio( | ||
self, portfolio_uuid: str, symbol: str, amount: str, currency: str, **kwargs | ||
): | ||
""" | ||
Allocate more funds to an isolated position in your Perpetuals portfolio. | ||
https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_allocateportfolio | ||
""" | ||
endpoint = f"{API_PREFIX}/intx/allocate" | ||
|
||
data = { | ||
"portfolio_uuid": portfolio_uuid, | ||
"symbol": symbol, | ||
"amount": amount, | ||
"currency": currency, | ||
} | ||
|
||
return self.post(endpoint, data=data, **kwargs) | ||
|
||
|
||
def get_perps_portfolio_summary(self, portfolio_uuid: str, **kwargs): | ||
""" | ||
Get a summary of your Perpetuals portfolio. | ||
https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getintxportfoliosummary | ||
""" | ||
endpoint = f"{API_PREFIX}/intx/portfolio/{portfolio_uuid}" | ||
|
||
return self.get(endpoint, **kwargs) | ||
|
||
|
||
def list_perps_positions(self, portfolio_uuid: str, **kwargs): | ||
""" | ||
Get a list of open positions in your Perpetuals portfolio. | ||
https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getintxpositions | ||
""" | ||
endpoint = f"{API_PREFIX}/intx/positions/{portfolio_uuid}" | ||
|
||
return self.get(endpoint, **kwargs) | ||
|
||
|
||
def get_perps_position(self, portfolio_uuid: str, symbol: str, **kwargs): | ||
""" | ||
Get a specific open position in your Perpetuals portfolio | ||
https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getintxposition | ||
""" | ||
endpoint = f"{API_PREFIX}/intx/positions/{portfolio_uuid}/{symbol}" | ||
|
||
return self.get(endpoint, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import unittest | ||
|
||
from requests_mock import Mocker | ||
|
||
from coinbase.rest import RESTClient | ||
|
||
from ..constants import TEST_API_KEY, TEST_API_SECRET | ||
|
||
|
||
class PerpetualsTest(unittest.TestCase): | ||
def test_allocate_portfolio(self): | ||
client = RESTClient(TEST_API_KEY, TEST_API_SECRET) | ||
|
||
expected_response = {"key_1": "value_1", "key_2": "value_2"} | ||
|
||
with Mocker() as m: | ||
m.request( | ||
"POST", | ||
"https://api.coinbase.com/api/v3/brokerage/intx/allocate", | ||
json=expected_response, | ||
) | ||
response = client.allocate_portfolio( | ||
portfolio_uuid="test_uuid", | ||
symbol="BTC-PERP-INTX", | ||
amount="100", | ||
currency="USD", | ||
) | ||
|
||
captured_request = m.request_history[0] | ||
captured_json = captured_request.json() | ||
|
||
self.assertEqual(captured_request.query, "") | ||
self.assertEqual( | ||
captured_json, | ||
{ | ||
"portfolio_uuid": "test_uuid", | ||
"symbol": "BTC-PERP-INTX", | ||
"amount": "100", | ||
"currency": "USD", | ||
}, | ||
) | ||
self.assertEqual(response, expected_response) | ||
|
||
def test_get_perps_portfolio_summary(self): | ||
client = RESTClient(TEST_API_KEY, TEST_API_SECRET) | ||
|
||
expected_response = {"key_1": "value_1", "key_2": "value_2"} | ||
|
||
with Mocker() as m: | ||
m.request( | ||
"GET", | ||
"https://api.coinbase.com/api/v3/brokerage/intx/portfolio/test_uuid", | ||
json=expected_response, | ||
) | ||
portfolios = client.get_perps_portfolio_summary(portfolio_uuid="test_uuid") | ||
|
||
captured_request = m.request_history[0] | ||
|
||
self.assertEqual(captured_request.query, "") | ||
self.assertEqual(portfolios, expected_response) | ||
|
||
def test_list_perps_positions(self): | ||
client = RESTClient(TEST_API_KEY, TEST_API_SECRET) | ||
|
||
expected_response = {"key_1": "value_1", "key_2": "value_2"} | ||
|
||
with Mocker() as m: | ||
m.request( | ||
"GET", | ||
"https://api.coinbase.com/api/v3/brokerage/intx/positions/test_uuid", | ||
json=expected_response, | ||
) | ||
portfolios = client.list_perps_positions(portfolio_uuid="test_uuid") | ||
|
||
captured_request = m.request_history[0] | ||
|
||
self.assertEqual(captured_request.query, "") | ||
self.assertEqual(portfolios, expected_response) | ||
|
||
def test_get_perps_position(self): | ||
client = RESTClient(TEST_API_KEY, TEST_API_SECRET) | ||
|
||
expected_response = {"key_1": "value_1", "key_2": "value_2"} | ||
|
||
with Mocker() as m: | ||
m.request( | ||
"GET", | ||
"https://api.coinbase.com/api/v3/brokerage/intx/positions/test_uuid/BTC-PERP-INTX", | ||
json=expected_response, | ||
) | ||
portfolios = client.get_perps_position( | ||
portfolio_uuid="test_uuid", symbol="BTC-PERP-INTX" | ||
) | ||
|
||
captured_request = m.request_history[0] | ||
|
||
self.assertEqual(captured_request.query, "") | ||
self.assertEqual(portfolios, expected_response) |