Skip to content

Commit 9e79421

Browse files
committed
Move to docstrings.
1 parent b746211 commit 9e79421

File tree

1 file changed

+140
-117
lines changed

1 file changed

+140
-117
lines changed

Cryptsy.py

Lines changed: 140 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
class Api:
10+
""" API wrapper for the Cryptsy API. """
1011
def __init__(self, key, secret):
1112
self.API_KEY = key
1213
self.SECRET = secret
@@ -40,136 +41,156 @@ def _api_query(self, method, request_data=None):
4041
return json.loads(rv.read())
4142

4243
def market_data(self, v2=False):
44+
""" Get market data for all markets.
45+
46+
Defaults to the old version of getmarketdata. Set v2 to True to use
47+
getmarketdatav2.
48+
"""
4349
if v2 is True:
4450
return self._public_api_query("marketdatav2")
4551
return self._public_api_query("marketdata")
4652

4753
def single_market_data(self, marketid=None):
54+
""" Get general market data for the given market.
55+
56+
:param marketid: Market ID you are querying for.
57+
"""
4858
return self._public_api_query("singlemarketdata", marketid=marketid)
4959

5060
def order_book_data(self, marketid=None):
61+
""" Get orderbook data for all markets, or for a single one.
62+
63+
:param marketid: If provided, API will only return orderbook data for
64+
this specific market.
65+
"""
5166
if marketid is None:
5267
return self._public_api_query("orderdata")
5368
return self._public_api_query("singleorderdata", marketid=marketid)
5469

55-
# Outputs:
56-
# balances_available Array of currencies and the balances availalbe for each
57-
# balances_hold Array of currencies and the amounts currently on hold for open orders
58-
# servertimestamp Current server timestamp
59-
# servertimezone Current timezone for the server
60-
# serverdatetime Current date/time on the server
61-
# openordercount Count of open orders on your account
6270
def info(self):
71+
""" Get some information about the server and your account.
72+
73+
Resultset contains:
74+
75+
balances_available Array of currencies and the balances availalbe for each
76+
balances_hold Array of currencies and the amounts currently on hold for open orders
77+
servertimestamp Current server timestamp
78+
servertimezone Current timezone for the server
79+
serverdatetime Current date/time on the server
80+
openordercount Count of open orders on your account
81+
"""
6382
return self._api_query('getinfo')
6483

65-
# Outputs: Array of Active Markets
66-
# marketid Integer value representing a market
67-
# label Name for this market, for example: AMC/BTC
68-
# primary_currency_code Primary currency code, for example: AMC
69-
# primary_currency_name Primary currency name, for example: AmericanCoin
70-
# secondary_currency_code Secondary currency code, for example: BTC
71-
# secondary_currency_name Secondary currency name, for example: BitCoin
72-
# current_volume 24 hour trading volume in this market
73-
# last_trade Last trade price for this market
74-
# high_trade 24 hour highest trade price in this market
75-
# low_trade 24 hour lowest trade price in this market
7684
def markets(self):
85+
""" Get a list of all active markets.
86+
87+
Resultset contains:
88+
89+
marketid Integer value representing a market
90+
label Name for this market, for example: AMC/BTC
91+
primary_currency_code Primary currency code, for example: AMC
92+
primary_currency_name Primary currency name, for example: AmericanCoin
93+
secondary_currency_code Secondary currency code, for example: BTC
94+
secondary_currency_name Secondary currency name, for example: BitCoin
95+
current_volume 24 hour trading volume in this market
96+
last_trade Last trade price for this market
97+
high_trade 24 hour highest trade price in this market
98+
low_trade 24 hour lowest trade price in this market
99+
"""
77100
return self._api_query('getmarkets')
78101

79-
# Outputs: Array of Deposits and Withdrawals on your account
80-
# currency Name of currency account
81-
# timestamp The timestamp the activity posted
82-
# datetime The datetime the activity posted
83-
# timezone Server timezone
84-
# type Type of activity. (Deposit / Withdrawal)
85-
# address Address to which the deposit posted or Withdrawal was sent
86-
# amount Amount of transaction
87102
def my_transactions(self):
103+
""" Get all your deposits and withdrawals from your account.
104+
105+
Resultset contains:
106+
107+
currency Name of currency account
108+
timestamp The timestamp the activity posted
109+
datetime The datetime the activity posted
110+
timezone Server timezone
111+
type Type of activity. (Deposit / Withdrawal)
112+
address Address to which the deposit posted or Withdrawal was sent
113+
amount Amount of transaction
114+
"""
88115
return self._api_query('mytransactions')
89116

90-
# Inputs:
91-
# marketid Market ID for which you are querying
92-
##
93-
# Outputs: Array of last 1000 Trades for this Market, in Date Decending Order
94-
# datetime Server datetime trade occurred
95-
# tradeprice The price the trade occurred at
96-
# quantity Quantity traded
97-
# total Total value of trade (tradeprice * quantity)
98117
def market_trades(self, marketid):
118+
""" Get the last 1000 trades for this market, ordered descending by
119+
date.
120+
121+
Resultset contains:
122+
123+
datetime Server datetime trade occurred
124+
tradeprice The price the trade occurred at
125+
quantity Quantity traded
126+
total Total value of trade (tradeprice * quantity)
127+
128+
:param marketid: Market for which you are querying.
129+
"""
99130
return self._api_query('markettrades', request_data={'marketid': marketid})
100131

101-
# Inputs:
102-
# marketid Market ID for which you are querying
103-
##
104-
# Outputs: 2 Arrays. First array is sellorders listing current open sell orders ordered price ascending. Second array is buyorders listing current open buy orders ordered price descending.
105-
# sellprice If a sell order, price which order is selling at
106-
# buyprice If a buy order, price the order is buying at
107-
# quantity Quantity on order
108-
# total Total value of order (price * quantity)
109132
def market_orders(self, marketid):
110-
return self._api_query('marketorders', request_data={'marketid': marketid})
111-
112-
113-
# Inputs:
114-
# marketid Market ID for which you are querying
115-
# limit (optional) Limit the number of results. Default: 200
116-
##
117-
# Outputs: Array your Trades for this Market, in Date Decending Order
118-
# tradeid An integer identifier for this trade
119-
# tradetype Type of trade (Buy/Sell)
120-
# datetime Server datetime trade occurred
121-
# tradeprice The price the trade occurred at
122-
# quantity Quantity traded
123-
# total Total value of trade (tradeprice * quantity)
133+
""" Return currently open sell and buy orders.
134+
135+
Resultset contains two arrays, one for sell orders, one for buy orders,
136+
containing the following fields:
137+
138+
sellprice If a sell order, price which order is selling at
139+
buyprice If a buy order, price the order is buying at
140+
quantity Quantity on order
141+
total Total value of order (price * quantity)
142+
143+
:param marketid: Market ID for which you are querying.
144+
"""
145+
return self._api_query('marketorders',
146+
request_data={'marketid': marketid})
147+
124148
def my_trades(self, marketid=None, limit=200):
149+
""" Get all your trades for this market, ordered descending by date.
150+
151+
Resultset contains:
152+
153+
tradeid An integer identifier for this trade
154+
tradetype Type of trade (Buy/Sell)
155+
datetime Server datetime trade occurred
156+
tradeprice The price the trade occurred at
157+
quantity Quantity traded
158+
total Total value of trade (tradeprice * quantity)
159+
160+
:param marketid: Marketid for which you are querying.
161+
:param limit: Maximum number of results, defaults to 200.
162+
"""
125163
if marketid is None:
126164
return self._api_query('allmytrades')
127165
return self._api_query('mytrades', request_data={'marketid': marketid,
128166
'limit': limit})
129167

130-
# Inputs:
131-
# marketid Market ID for which you are querying
132-
##
133-
# Outputs: Array of your orders for this market listing your current open sell and buy orders.
134-
# orderid Order ID for this order
135-
# created Datetime the order was created
136-
# ordertype Type of order (Buy/Sell)
137-
# price The price per unit for this order
138-
# quantity Quantity for this order
139-
# total Total value of order (price * quantity)
140168
def my_orders(self, marketid=None):
169+
""" Get all your orders, or your orders for a specific market.
170+
171+
Resultset contains:
172+
173+
orderid Order ID for this order
174+
created Datetime the order was created
175+
ordertype Type of order (Buy/Sell)
176+
price The price per unit for this order
177+
quantity Quantity for this order
178+
total Total value of order (price * quantity)
179+
180+
:param marketid: If provided, orders will be filtered by this marketid.
181+
"""
141182
if marketid is None:
142183
return self.api_query('allmyorders')
143184
return self._api_query('myorders', request_data={'marketid': marketid})
144185

145-
# Inputs:
146-
# marketid Market ID for which you are querying
147-
##
148-
# Outputs: Array of buy and sell orders on the market representing market depth.
149-
# Output Format is:
150-
# array(
151-
# 'sell'=>array(
152-
# array(price,quantity),
153-
# array(price,quantity),
154-
# ....
155-
# ),
156-
# 'buy'=>array(
157-
# array(price,quantity),
158-
# array(price,quantity),
159-
# ....
160-
# )
161-
# )
162186
def depth(self, marketid):
187+
""" Get an array of buy and sell orders on the given market
188+
representing the market depth.
189+
190+
:param marketid: A market ID.
191+
"""
163192
return self._api_query('depth', request_data={'marketid': marketid})
164193

165-
# Inputs:
166-
# marketid Market ID for which you are creating an order for
167-
# ordertype Order type you are creating (Buy/Sell)
168-
# quantity Amount of units you are buying/selling in this order
169-
# price Price per unit you are buying/selling at
170-
##
171-
# Outputs:
172-
# orderid If successful, the Order ID for the order which was created
173194
def _create_order(self, marketid, ordertype, quantity, price):
174195
""" Creates an order for buying or selling coins.
175196
@@ -180,6 +201,7 @@ def _create_order(self, marketid, ordertype, quantity, price):
180201
:param ordertype: Either Buy or Sell.
181202
:param quantity: Number of coins to buy.
182203
:param price: At this price.
204+
:returns: A dict containing the orderid of the created order.
183205
"""
184206
return self._api_query('createorder',
185207
request_data={'marketid': marketid,
@@ -195,54 +217,55 @@ def sell(self, marketid, quantity, price):
195217
""" Sell a specified number of coins on the given market. """
196218
return self._create_order(marketid, 'Sell', quantity, price)
197219

198-
# Inputs:
199-
# orderid Order ID for which you would like to cancel
200-
##
201-
# Outputs: If successful, it will return a success code.
202220
def cancel_order(self, orderid):
221+
""" Cancel a specific order.
222+
223+
:param orderid: The ID of the order you want to cancel.
224+
:returns: A succescode if succesfull.
225+
"""
203226
return self._api_query('cancelorder', request_data={'orderid': orderid})
204227

205-
# Inputs:
206-
# marketid Market ID for which you would like to cancel all open orders
207-
##
208-
# Outputs:
209-
# return Array for return information on each order cancelled
210228
def cancel_all_market_orders(self, marketid):
229+
""" Cancel all currently pending orders for a specific market.
230+
231+
:param marketid: Market ID for wich you would like to cancel orders.
232+
"""
211233
return self._api_query('cancelmarketorders',
212234
request_data={'marketid': marketid})
213235

214-
# Outputs:
215-
# return Array for return information on each order cancelled
216236
def cancel_all_orders(self):
237+
""" Cancel all currently pending orders. """
217238
return self._api_query('cancelallorders')
218239

219-
# Inputs:
220-
# ordertype Order type you are calculating for (Buy/Sell)
221-
# quantity Amount of units you are buying/selling
222-
# price Price per unit you are buying/selling at
223-
##
224-
# Outputs:
225-
# fee The that would be charged for provided inputs
226-
# net The net total with fees
227240
def calculate_fees(self, ordertype, quantity, price):
241+
""" Calculate fees that would be charged for the provided inputs.
242+
243+
:param ordertype: Order type you are calculating for (Buy/Sell)
244+
:param quantity: Amount of units you are buying/selling
245+
:param price: Price per unit you are buying/selling at
246+
:returns: A dict containing the fee and the net total with fees.
247+
"""
228248
return self._api_query('calculatefees',
229249
request_data={'ordertype': ordertype,
230250
'quantity': quantity,
231251
'price': price})
232252

233-
# Inputs: (either currencyid OR currencycode required - you do not have to supply both)
234-
# currencyid Currency ID for the coin you want to generate a new address for (ie. 3 = BitCoin)
235-
# currencycode Currency Code for the coin you want to generate a new address for (ie. BTC = BitCoin)
236-
##
237-
# Outputs:
238-
# address The new generated address
239253
def generate_new_address(self, currencyid=None, currencycode=None):
254+
""" Generate a new address for a currency. Expects either a currencyid
255+
OR a currencycode (not both).
256+
257+
:param currencyid: ID of a currency on Cryptsy.
258+
:param currencycode: Code of a currency on Cryptsy.
259+
:throws ValueError: Fails if neither of the parameters are given.
260+
:returns: A dict containing the newly generated address.
261+
"""
240262
if currencyid is not None:
241263
req = {'currencyid': currencyid}
242264
elif currencycode is not None:
243265
req = {'currencycode': currencycode}
244266
else:
245-
return None
267+
raise ValueError('You should specify either a currencyid or a'
268+
'currencycode')
246269

247270
return self._api_query('generatenewaddress', request_data=req)
248271

0 commit comments

Comments
 (0)