Skip to content

Commit 8c80973

Browse files
committed
increased compatibility and additional endpoint functionality
1 parent f900479 commit 8c80973

4 files changed

Lines changed: 62 additions & 14 deletions

File tree

GDAX/AuthenticatedClient.py

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
#
55
# For authenticated requests to the GDAX exchange
66

7-
import hmac, hashlib, time, requests, base64
7+
import hmac, hashlib, time, requests, base64, json
88
from requests.auth import AuthBase
99
from GDAX.PublicClient import PublicClient
1010

1111
class AuthenticatedClient(PublicClient):
1212
def __init__(self, key, b64secret, passphrase, api_url="https://api.gdax.com", product_id="BTC-USD"):
13-
self.url = api_url
13+
if api_url[-1] == "/":
14+
self.url = api_url[:-1]
15+
else:
16+
self.url = api_url
1417
self.productId = product_id
1518
self.auth = GdaxAuth(key, b64secret, passphrase)
1619

@@ -57,12 +60,12 @@ def buy(self, buyParams):
5760
buyParams["side"] = "buy"
5861
if not buyParams["product_id"]:
5962
buyParams["product_id"] = self.productId
60-
r = requests.post(self.url + '/orders', json=buyParams, auth=self.auth)
63+
r = requests.post(self.url + '/orders', data=json.dumps(buyParams), auth=self.auth)
6164
return r.json()
6265

6366
def sell(self, sellParams):
6467
sellParams["side"] = "sell"
65-
r = requests.post(self.url + '/orders', json=sellParams, auth=self.auth)
68+
r = requests.post(self.url + '/orders', data=json.dumps(sellParams), auth=self.auth)
6669
return r.json()
6770

6871
def cancelOrder(self, orderId):
@@ -120,7 +123,7 @@ def deposit(self, amount="", accountId=""):
120123
"amount": amount,
121124
"accountId": accountId
122125
}
123-
r = requests.post(self.url + "/transfers", json=payload, auth=self.auth)
126+
r = requests.post(self.url + "/transfers", data=json.dumps(payload), auth=self.auth)
124127
return r.json()
125128

126129
def withdraw(self, amount="", accountId=""):
@@ -129,7 +132,36 @@ def withdraw(self, amount="", accountId=""):
129132
"amount": amount,
130133
"accountId": accountId
131134
}
132-
r = requests.post(self.url + "/transfers", json=payload, auth=self.auth)
135+
r = requests.post(self.url + "/transfers", data=json.dumps(payload), auth=self.auth)
136+
return r.json()
137+
138+
def getPaymentMethods(self):
139+
r = requests.get(self.url + "/payment-methods", auth=self.auth)
140+
return r.json()
141+
142+
def getCoinbaseAccounts(self):
143+
r = requests.get(self.url + "/coinbase-accounts", auth=self.auth)
144+
return r.json()
145+
146+
def createReport(self, type="", start_date="", end_date="", product_id="", account_id="", format="", email=""):
147+
payload = {
148+
"type": type,
149+
"start_date": start_date,
150+
"end_date": end_date,
151+
"product_id": product_id,
152+
"account_id": account_id,
153+
"format": format,
154+
"email": email
155+
}
156+
r = requests.post(self.url + "/reports", data=json.dumps(payload), auth=self.auth)
157+
return r.json()
158+
159+
def getReport(self, reportId=""):
160+
r = requests.get(self.url + "/reports/" + reportId, auth=self.auth)
161+
return r.json()
162+
163+
def getTrailingVolume(self):
164+
r = requests.get(self.url + "/users/self/trailing-volume", auth=self.auth)
133165
return r.json()
134166

135167
class GdaxAuth(AuthBase):
@@ -147,9 +179,10 @@ def __call__(self, request):
147179
signature = hmac.new(hmac_key, message, hashlib.sha256)
148180
signature_b64 = base64.b64encode(signature.digest())
149181
request.headers.update({
182+
'Content-Type': 'Application/JSON',
150183
'CB-ACCESS-SIGN': signature_b64,
151184
'CB-ACCESS-TIMESTAMP': timestamp,
152185
'CB-ACCESS-KEY': self.api_key,
153-
'CB-ACCESS-PASSPHRASE': self.passphrase,
186+
'CB-ACCESS-PASSPHRASE': self.passphrase
154187
})
155188
return request

GDAX/PublicClient.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
class PublicClient():
1010
def __init__(self, api_url="https://api.gdax.com", product_id="BTC-USD"):
11-
self.url = api_url
11+
if api_url[-1] == "/":
12+
self.url = api_url[:-1]
13+
else:
14+
self.url = api_url
1215
self.productId = product_id
1316

1417
def getProducts(self):

GDAX/WebsocketClient.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
#
55
# Template object to receive messages from the GDAX Websocket Feed
66

7-
import json
7+
import json, time
88
from threading import Thread
9-
import time
109
from websocket import create_connection
1110

1211
class WebsocketClient():
13-
def __init__(self, ws_url="wss://ws-feed.gdax.com", product_id="BTC-USD"):
12+
def __init__(self, ws_url="wss://ws-feed-public.sandbox.gdax.com", product_id="BTC-USD"):
13+
if ws_url[-1] == "/":
14+
self.url = ws_url[:-1]
15+
else:
16+
self.url = ws_url
1417
self.stop = False
15-
self.url = ws_url
1618
self.product_id = product_id
1719
self.thread = Thread(target=self.setup)
1820
self.thread.start()

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@ A Python client for the [GDAX API](https://docs.gdax.com/) (formerly known as th
1111
- Do not worry about handling the nuances of the API with easy-to-use methods for every API endpoint.
1212
- Have an advantage in the market by getting under the hood of GDAX to learn what and who is *really* behind every tick.
1313

14+
1415
## Under Development
15-
- Bug Fixing **please report**
16+
- Test Scripts **looking for help**
17+
- Additional Functionality for *AuthenticatedClient.py* (including support for all order types)
1618
- FIX API Client **researching**
1719

20+
## Change Log
21+
*0.1.2*
22+
- Updated JSON handling for increased compatibility among some users
23+
- Added support for payment methods, reports, and coinbase user accounts
24+
- Other compatibility updates
25+
*0.1.1b2 **Current PyPI release***
26+
- Original PyPI Release
27+
1828
## Getting Started
19-
This README is only to inform you on the intricacies of the python wrapper presented in this repository. In order to use it to its full potential, you must familiarize yourself with the official documentation.
29+
This README is only to inform you on the intricacies of the python wrapper presented in this repository. **In order to use this wrapper to its full potential, you must familiarize yourself with the official documentation.**
2030

2131
- https://docs.gdax.com/
2232

0 commit comments

Comments
 (0)