forked from ccxt/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoinsecure.py
More file actions
319 lines (305 loc) · 14 KB
/
coinsecure.py
File metadata and controls
319 lines (305 loc) · 14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# -*- coding: utf-8 -*-
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
from ccxt.async_support.base.exchange import Exchange
import json
from ccxt.base.errors import ExchangeError
from ccxt.base.errors import NotSupported
class coinsecure (Exchange):
def describe(self):
return self.deep_extend(super(coinsecure, self).describe(), {
'id': 'coinsecure',
'name': 'Coinsecure',
'countries': ['IN'], # India
'rateLimit': 1000,
'version': 'v1',
'has': {
'CORS': True,
},
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/27766472-9cbd200a-5ed9-11e7-9551-2267ad7bac08.jpg',
'api': 'https://api.coinsecure.in',
'www': 'https://coinsecure.in',
'doc': [
'https://api.coinsecure.in',
'https://github.com/coinsecure/plugins',
],
},
'requiredCredentials': {
'apiKey': True,
'secret': False,
},
'api': {
'public': {
'get': [
'bitcoin/search/confirmation/{txid}',
'exchange/ask/low',
'exchange/ask/orders',
'exchange/bid/high',
'exchange/bid/orders',
'exchange/lastTrade',
'exchange/max24Hr',
'exchange/min24Hr',
'exchange/ticker',
'exchange/trades',
],
},
'private': {
'get': [
'mfa/authy/call',
'mfa/authy/sms',
'netki/search/{netkiName}',
'user/bank/otp/{number}',
'user/kyc/otp/{number}',
'user/profile/phone/otp/{number}',
'user/wallet/coin/address/{id}',
'user/wallet/coin/deposit/confirmed/all',
'user/wallet/coin/deposit/confirmed/{id}',
'user/wallet/coin/deposit/unconfirmed/all',
'user/wallet/coin/deposit/unconfirmed/{id}',
'user/wallet/coin/wallets',
'user/exchange/bank/fiat/accounts',
'user/exchange/bank/fiat/balance/available',
'user/exchange/bank/fiat/balance/pending',
'user/exchange/bank/fiat/balance/total',
'user/exchange/bank/fiat/deposit/cancelled',
'user/exchange/bank/fiat/deposit/unverified',
'user/exchange/bank/fiat/deposit/verified',
'user/exchange/bank/fiat/withdraw/cancelled',
'user/exchange/bank/fiat/withdraw/completed',
'user/exchange/bank/fiat/withdraw/unverified',
'user/exchange/bank/fiat/withdraw/verified',
'user/exchange/ask/cancelled',
'user/exchange/ask/completed',
'user/exchange/ask/pending',
'user/exchange/bid/cancelled',
'user/exchange/bid/completed',
'user/exchange/bid/pending',
'user/exchange/bank/coin/addresses',
'user/exchange/bank/coin/balance/available',
'user/exchange/bank/coin/balance/pending',
'user/exchange/bank/coin/balance/total',
'user/exchange/bank/coin/deposit/cancelled',
'user/exchange/bank/coin/deposit/unverified',
'user/exchange/bank/coin/deposit/verified',
'user/exchange/bank/coin/withdraw/cancelled',
'user/exchange/bank/coin/withdraw/completed',
'user/exchange/bank/coin/withdraw/unverified',
'user/exchange/bank/coin/withdraw/verified',
'user/exchange/bank/summary',
'user/exchange/coin/fee',
'user/exchange/fiat/fee',
'user/exchange/kycs',
'user/exchange/referral/coin/paid',
'user/exchange/referral/coin/successful',
'user/exchange/referral/fiat/paid',
'user/exchange/referrals',
'user/exchange/trade/summary',
'user/login/token/{token}',
'user/summary',
'user/wallet/summary',
'wallet/coin/withdraw/cancelled',
'wallet/coin/withdraw/completed',
'wallet/coin/withdraw/unverified',
'wallet/coin/withdraw/verified',
],
'post': [
'login',
'login/initiate',
'login/password/forgot',
'mfa/authy/initiate',
'mfa/ga/initiate',
'signup',
'user/netki/update',
'user/profile/image/update',
'user/exchange/bank/coin/withdraw/initiate',
'user/exchange/bank/coin/withdraw/newVerifycode',
'user/exchange/bank/fiat/withdraw/initiate',
'user/exchange/bank/fiat/withdraw/newVerifycode',
'user/password/change',
'user/password/reset',
'user/wallet/coin/withdraw/initiate',
'wallet/coin/withdraw/newVerifycode',
],
'put': [
'signup/verify/{token}',
'user/exchange/kyc',
'user/exchange/bank/fiat/deposit/new',
'user/exchange/ask/new',
'user/exchange/bid/new',
'user/exchange/instant/buy',
'user/exchange/instant/sell',
'user/exchange/bank/coin/withdraw/verify',
'user/exchange/bank/fiat/account/new',
'user/exchange/bank/fiat/withdraw/verify',
'user/mfa/authy/initiate/enable',
'user/mfa/ga/initiate/enable',
'user/netki/create',
'user/profile/phone/new',
'user/wallet/coin/address/new',
'user/wallet/coin/new',
'user/wallet/coin/withdraw/sendToExchange',
'user/wallet/coin/withdraw/verify',
],
'delete': [
'user/gcm/{code}',
'user/logout',
'user/exchange/bank/coin/withdraw/unverified/cancel/{withdrawID}',
'user/exchange/bank/fiat/deposit/cancel/{depositID}',
'user/exchange/ask/cancel/{orderID}',
'user/exchange/bid/cancel/{orderID}',
'user/exchange/bank/fiat/withdraw/unverified/cancel/{withdrawID}',
'user/mfa/authy/disable/{code}',
'user/mfa/ga/disable/{code}',
'user/profile/phone/delete',
'user/profile/image/delete/{netkiName}',
'user/wallet/coin/withdraw/unverified/cancel/{withdrawID}',
],
},
},
'markets': {
'BTC/INR': {'id': 'BTC/INR', 'symbol': 'BTC/INR', 'base': 'BTC', 'quote': 'INR'},
},
'fees': {
'trading': {
'maker': 0.4 / 100,
'taker': 0.4 / 100,
},
},
})
async def fetch_balance(self, params={}):
await self.load_markets()
response = await self.privateGetUserExchangeBankSummary()
balance = response['message']
coin = {
'free': balance['availableCoinBalance'],
'used': balance['pendingCoinBalance'],
'total': balance['totalCoinBalance'],
}
fiat = {
'free': balance['availableFiatBalance'],
'used': balance['pendingFiatBalance'],
'total': balance['totalFiatBalance'],
}
result = {
'info': balance,
'BTC': coin,
'INR': fiat,
}
return self.parse_balance(result)
async def fetch_order_book(self, symbol, limit=None, params={}):
await self.load_markets()
bids = await self.publicGetExchangeBidOrders(params)
asks = await self.publicGetExchangeAskOrders(params)
orderbook = {
'bids': bids['message'],
'asks': asks['message'],
}
return self.parse_order_book(orderbook, None, 'bids', 'asks', 'rate', 'vol')
async def fetch_ticker(self, symbol, params={}):
await self.load_markets()
response = await self.publicGetExchangeTicker(params)
ticker = response['message']
timestamp = ticker['timestamp']
baseVolume = self.safe_float(ticker, 'coinvolume')
if symbol == 'BTC/INR':
satoshi = 0.00000001
baseVolume = baseVolume * satoshi
quoteVolume = self.safe_float(ticker, 'fiatvolume') / 100
vwap = quoteVolume / baseVolume
last = self.safe_float(ticker, 'lastPrice') / 100
return {
'symbol': symbol,
'timestamp': timestamp,
'datetime': self.iso8601(timestamp),
'high': self.safe_float(ticker, 'high') / 100,
'low': self.safe_float(ticker, 'low') / 100,
'bid': self.safe_float(ticker, 'bid') / 100,
'bidVolume': None,
'ask': self.safe_float(ticker, 'ask') / 100,
'askVolume': None,
'vwap': vwap,
'open': self.safe_float(ticker, 'open') / 100,
'close': last,
'last': last,
'previousClose': None,
'change': None,
'percentage': None,
'average': None,
'baseVolume': baseVolume,
'quoteVolume': quoteVolume,
'info': ticker,
}
def parse_trade(self, trade, symbol=None):
timestamp = trade['time']
side = 'buy' if (trade['ordType'] == 'bid') else 'sell'
return {
'id': None,
'timestamp': timestamp,
'datetime': self.iso8601(timestamp),
'order': None,
'symbol': symbol,
'type': None,
'side': side,
'price': self.safe_float(trade, 'rate') / 100,
'amount': self.safe_float(trade, 'vol') / 100000000,
'fee': None,
'info': trade,
}
async def fetch_trades(self, symbol, since=None, limit=None, params={}):
await self.load_markets()
market = self.market(symbol)
result = await self.publicGetExchangeTrades(params)
if 'message' in result:
trades = result['message']
return self.parse_trades(trades, market)
async def create_order(self, symbol, type, side, amount, price=None, params={}):
await self.load_markets()
method = 'privatePutUserExchange'
order = {}
if type == 'market':
method += 'Instant' + self.capitalize(side)
if side == 'buy':
order['maxFiat'] = amount
else:
order['maxVol'] = amount
else:
direction = 'Bid' if (side == 'buy') else 'Ask'
method += direction + 'New'
order['rate'] = price
order['vol'] = amount
response = await getattr(self, method)(self.extend(order, params))
return {
'info': response,
'id': response['message']['orderID'],
}
async def cancel_order(self, id, symbol=None, params={}):
await self.load_markets()
# method = 'privateDeleteUserExchangeAskCancelOrderId' # TODO fixme, have to specify order side here
# return await getattr(self, method)({'orderID': id})
raise NotSupported(self.id + ' cancelOrder() is not fully implemented yet')
def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
url = self.urls['api'] + '/' + self.version + '/' + self.implode_params(path, params)
query = self.omit(params, self.extract_params(path))
if api == 'private':
self.check_required_credentials()
headers = {'Authorization': self.apiKey}
if query:
body = self.json(query)
headers['Content-Type'] = 'application/json'
return {'url': url, 'method': method, 'body': body, 'headers': headers}
def handle_errors(self, code, reason, url, method, headers, body):
if code == 200:
if (body[0] == '{') or (body[0] == '['):
response = json.loads(body)
if 'success' in response:
success = response['success']
if not success:
raise ExchangeError(self.id + ' error returned: ' + body)
if not('message' in list(response.keys())):
raise ExchangeError(self.id + ' malformed response: no "message" in response: ' + body)
else:
raise ExchangeError(self.id + ' malformed response: no "success" in response: ' + body)
else:
# if not a JSON response
raise ExchangeError(self.id + ' returned a non-JSON reply: ' + body)