MCPcopy Create free account
hub / github.com/danpaquin/coinbasepro-python / TestAuthenticatedClient

Class TestAuthenticatedClient

tests/test_authenticated_client.py:72–208  ·  view source on GitHub ↗

Test the authenticated client by validating basic behavior from the sandbox exchange.

Source from the content-addressed store, hash-verified

70@pytest.mark.usefixtures('dc')
71@pytest.mark.skip(reason="these test require authentication")
72class TestAuthenticatedClient(object):
73 """Test the authenticated client by validating basic behavior from the
74 sandbox exchange."""
75 def test_get_accounts(self, client):
76 r = client.get_accounts()
77 assert type(r) is list
78 assert 'currency' in r[0]
79 # Now get a single account
80 r = client.get_account(account_id=r[0]['id'])
81 assert type(r) is dict
82 assert 'currency' in r
83
84 def test_account_history(self, client):
85 accounts = client.get_accounts()
86 account_usd = [x for x in accounts if x['currency'] == 'USD'][0]['id']
87 r = list(islice(client.get_account_history(account_usd), 5))
88 assert type(r) is list
89 assert 'amount' in r[0]
90 assert 'details' in r[0]
91
92 # Now exercise the pagination abstraction. Setting limit to 1 means
93 # each record comes in a separate HTTP response.
94 history_gen = client.get_account_history(account_usd, limit=1)
95 r = list(islice(history_gen, 2))
96 r2 = list(islice(history_gen, 2))
97 assert r != r2
98 # Now exercise the `before` parameter.
99 r3 = list(client.get_account_history(account_usd, before=r2[0]['id']))
100 assert r3 == r
101
102 def test_get_account_holds(self, client):
103 accounts = client.get_accounts()
104 account_usd = [x for x in accounts if x['currency'] == 'USD'][0]['id']
105 r = list(client.get_account_holds(account_usd))
106 assert type(r) is list
107 assert 'type' in r[0]
108 assert 'ref' in r[0]
109
110 def test_convert_stablecoin(self, client):
111 r = client.convert_stablecoin('10.0', 'USD', 'USDC')
112 assert type(r) is dict
113 assert 'id' in r
114 assert r['amount'] == '10.00000000'
115 assert r['from'] == 'USD'
116 assert r['to'] == 'USDC'
117
118 def test_place_order(self, client):
119 r = client.place_order('BTC-USD', 'buy', 'limit',
120 price=0.62, size=0.0144)
121 assert type(r) is dict
122 assert r['stp'] == 'dc'
123
124 def test_place_limit_order(self, client):
125 r = client.place_limit_order('BTC-USD', 'buy', 4.43, 0.01232)
126 assert type(r) is dict
127 assert 'executed_value' in r
128 assert not r['post_only']
129 client.cancel_order(r['id'])

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected