3131
3232URI_API = 'https://cointracking.info/api/v1/'
3333
34-
34+ #
35+ # API object
36+ #
3537class CTAPI (object ):
36- """ requesting CoinTracking API with API key and API secret """
38+ """
39+ requesting CoinTracking API with API key and API secret
40+
41+ Documentation: https://cointracking.info/api/api.php
42+ """
3743
3844 #
3945 # init
4046 #
41- def __init__ (self , api_key = '' , api_secret = '' , debug = False ):
47+ def __init__ (self , api_key = None , api_secret = None , debug = False ):
48+ # if not self.api_key or not self.api_secret:
49+
50+
4251 self .api_key = api_key
4352 self .api_secret = api_secret
4453 self .debug = debug
@@ -57,7 +66,11 @@ def __init__(self, api_key='', api_secret='', debug=False):
5766 # encode parameters for url
5867 #
5968 def _encode_params_url (self , params ):
60- """ TODO """
69+ """
70+ encoding URL parameters
71+
72+ :params: Request parameters to be encoded
73+ """
6174
6275 encoded_string = ''
6376
@@ -73,7 +86,13 @@ def _encode_params_url(self, params):
7386 # make query to API
7487 #
7588 def _api_query (self , method , params = {}):
76- """ TODO """
89+ """
90+ Queries CoinTracking.info
91+
92+ :method: Request method
93+ :params: Request parameters
94+ :return: JSON response from Bittrex
95+ """
7796
7897 global URI_API
7998
@@ -82,14 +101,20 @@ def _api_query(self, method, params={}):
82101 'nonce' : '%d' % int (time .time () * 10 ),
83102 })
84103
104+ if not self .api_secret :
105+ return {
106+ 'success' : False ,
107+ 'message' : 'no valid secret key' ,
108+ }
109+
85110 params_string = self ._encode_params_url (params )
86111 params_signed = hmac .new (self .api_secret .encode (), msg = params_string .encode (), digestmod = hashlib .sha512 ).hexdigest ()
87112
88113 hdrs = {
89114 'Key' : self .api_key ,
90115 'Sign' : params_signed ,
91116 'Connection' : 'close' ,
92- 'User-Agent' : 'python-cointracking-api /%s (https://github.com/tbl42/python-ctapi)' % (__version__ ),
117+ 'User-Agent' : 'python-ctapi /%s (https://github.com/tbl42/python-ctapi)' % (__version__ ),
93118 }
94119
95120 logger .debug ("=" * 30 )
@@ -108,7 +133,7 @@ def _api_query(self, method, params={}):
108133 ret_json = r .json ()
109134
110135 return {
111- 'success' : True ,
136+ 'success' : ret_json [ 'success' ] ,
112137 'result' : ret_json
113138 }
114139 except :
@@ -125,61 +150,90 @@ def _api_query(self, method, params={}):
125150 # getTrades
126151 #
127152 def getTrades (self , ** args ):
128- """ TODO: desc """
153+ """
154+ Used to get all your CoinTracking trades and transactions.
155+ Similar to the Trade List at https://cointracking.info/trades_full.php
156+ """
157+
129158 params = {
130159 'limit' : 5 ,
131160 'order' : 'DESC' ,
132161 }
133162 params .update (args )
163+
134164 return self ._api_query ('getTrades' , params )
135165
136166 #
137167 # getBalance
138168 #
139169 def getBalance (self ):
140- """ TODO: desc """
170+ """
171+ Used to get your current CoinTracking account and coin balance.
172+ Similar to the Current Balance at https://cointracking.info/current_balance.php
173+ """
174+
141175 return self ._api_query ('getBalance' )
142176
143177 #
144178 # getHistoricalSummary
145179 #
146180 def getHistoricalSummary (self , ** args ):
147- """ TODO: desc """
181+ """
182+ Used to get all historical values for all your coins, currencies, commodities, and the total account value.
183+ Similar to the Daily Balance at https://cointracking.info/overview.php or the Trade Statistics at https://cointracking.info/stats.php
184+ """
185+
148186 params = {
149187 'btc' : 0 ,
150188 }
151189 params .update (args )
190+
152191 return self ._api_query ('getHistoricalSummary' , params )
153192
154193 #
155194 # getHistoricalCurrency
156195 #
157196 def getHistoricalCurrency (self , ** args ):
158- """ TODO: desc """
197+ """
198+ Used to get all historical amounts and values for a specific currency/coin or for all currencies/coins.
199+ Similar to the Daily Balance at https://cointracking.info/overview.php or the Trade Statistics at https://cointracking.info/stats.php
200+ """
201+
159202 params = {
160203 'currency' : 'ETH' ,
161204 }
162205 params .update (args )
206+
163207 return self ._api_query ('getHistoricalCurrency' , params )
164208
165209 #
166210 # getGroupedBalance
167211 #
168212 def getGroupedBalance (self , ** args ):
169- """ TODO: desc """
213+ """
214+ Used to get the current balance grouped by exchange, trade-group or transaction type.
215+ Similar to the Balance by Exchange at https://cointracking.info/balance_by_exchange.php
216+ """
217+
170218 params = {
171219 'group' : 'exchange' ,
172220 }
173221 params .update (args )
222+
174223 return self ._api_query ('getGroupedBalance' , params )
175224
176225 #
177226 # getGains
178227 #
179228 def getGains (self , ** args ):
180- """ TODO: desc """
229+ """
230+ Used to get Returns your current realized and unrealized gains data.
231+ Similar to the Realized and Unrealized Gains at https://cointracking.info/gains.php
232+ """
233+
181234 params = {
182235 'method' : 'FIFO' ,
183236 }
184237 params .update (args )
238+
185239 return self ._api_query ('getGains' , params )
0 commit comments