forked from ccxt/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoinmate.py
More file actions
203 lines (189 loc) · 7.79 KB
/
coinmate.py
File metadata and controls
203 lines (189 loc) · 7.79 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
# -*- 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
from ccxt.base.errors import ExchangeError
class coinmate (Exchange):
def describe(self):
return self.deep_extend(super(coinmate, self).describe(), {
'id': 'coinmate',
'name': 'CoinMate',
'countries': ['GB', 'CZ', 'EU'], # UK, Czech Republic
'rateLimit': 1000,
'has': {
'CORS': True,
},
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/27811229-c1efb510-606c-11e7-9a36-84ba2ce412d8.jpg',
'api': 'https://coinmate.io/api',
'www': 'https://coinmate.io',
'doc': [
'http://docs.coinmate.apiary.io',
'https://coinmate.io/developers',
],
'referral': 'https://coinmate.io?referral=YTFkM1RsOWFObVpmY1ZjMGREQmpTRnBsWjJJNVp3PT0',
},
'requiredCredentials': {
'apiKey': True,
'secret': True,
'uid': True,
},
'api': {
'public': {
'get': [
'orderBook',
'ticker',
'transactions',
],
},
'private': {
'post': [
'balances',
'bitcoinWithdrawal',
'bitcoinDepositAddresses',
'buyInstant',
'buyLimit',
'cancelOrder',
'cancelOrderWithInfo',
'createVoucher',
'openOrders',
'redeemVoucher',
'sellInstant',
'sellLimit',
'transactionHistory',
'unconfirmedBitcoinDeposits',
],
},
},
'markets': {
'BTC/EUR': {'id': 'BTC_EUR', 'symbol': 'BTC/EUR', 'base': 'BTC', 'quote': 'EUR', 'precision': {'amount': 4, 'price': 2}},
'BTC/CZK': {'id': 'BTC_CZK', 'symbol': 'BTC/CZK', 'base': 'BTC', 'quote': 'CZK', 'precision': {'amount': 4, 'price': 2}},
'LTC/BTC': {'id': 'LTC_BTC', 'symbol': 'LTC/BTC', 'base': 'LTC', 'quote': 'BTC', 'precision': {'amount': 4, 'price': 5}},
},
'fees': {
'trading': {
'maker': 0.0005,
'taker': 0.0035,
},
},
})
async def fetch_balance(self, params={}):
response = await self.privatePostBalances()
balances = response['data']
result = {'info': balances}
currencies = list(self.currencies.keys())
for i in range(0, len(currencies)):
currency = currencies[i]
account = self.account()
if currency in balances:
account['free'] = balances[currency]['available']
account['used'] = balances[currency]['reserved']
account['total'] = balances[currency]['balance']
result[currency] = account
return self.parse_balance(result)
async def fetch_order_book(self, symbol, limit=None, params={}):
response = await self.publicGetOrderBook(self.extend({
'currencyPair': self.market_id(symbol),
'groupByPriceLimit': 'False',
}, params))
orderbook = response['data']
timestamp = orderbook['timestamp'] * 1000
return self.parse_order_book(orderbook, timestamp, 'bids', 'asks', 'price', 'amount')
async def fetch_ticker(self, symbol, params={}):
response = await self.publicGetTicker(self.extend({
'currencyPair': self.market_id(symbol),
}, params))
ticker = response['data']
timestamp = ticker['timestamp'] * 1000
last = self.safe_float(ticker, 'last')
return {
'symbol': symbol,
'timestamp': timestamp,
'datetime': self.iso8601(timestamp),
'high': self.safe_float(ticker, 'high'),
'low': self.safe_float(ticker, 'low'),
'bid': self.safe_float(ticker, 'bid'),
'bidVolume': None,
'ask': self.safe_float(ticker, 'ask'),
'vwap': None,
'askVolume': None,
'open': None,
'close': last,
'last': last,
'previousClose': None,
'change': None,
'percentage': None,
'average': None,
'baseVolume': self.safe_float(ticker, 'amount'),
'quoteVolume': None,
'info': ticker,
}
def parse_trade(self, trade, market=None):
if not market:
market = self.markets_by_id[trade['currencyPair']]
return {
'id': trade['transactionId'],
'info': trade,
'timestamp': trade['timestamp'],
'datetime': self.iso8601(trade['timestamp']),
'symbol': market['symbol'],
'type': None,
'side': None,
'price': trade['price'],
'amount': trade['amount'],
}
async def fetch_trades(self, symbol, since=None, limit=None, params={}):
market = self.market(symbol)
response = await self.publicGetTransactions(self.extend({
'currencyPair': market['id'],
'minutesIntoHistory': 10,
}, params))
return self.parse_trades(response['data'], market, since, limit)
async def create_order(self, symbol, type, side, amount, price=None, params={}):
method = 'privatePost' + self.capitalize(side)
order = {
'currencyPair': self.market_id(symbol),
}
if type == 'market':
if side == 'buy':
order['total'] = amount # amount in fiat
else:
order['amount'] = amount # amount in fiat
method += 'Instant'
else:
order['amount'] = amount # amount in crypto
order['price'] = price
method += self.capitalize(type)
response = await getattr(self, method)(self.extend(order, params))
return {
'info': response,
'id': str(response['data']),
}
async def cancel_order(self, id, symbol=None, params={}):
return await self.privatePostCancelOrder({'orderId': id})
def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
url = self.urls['api'] + '/' + path
if api == 'public':
if params:
url += '?' + self.urlencode(params)
else:
self.check_required_credentials()
nonce = str(self.nonce())
auth = nonce + self.uid + self.apiKey
signature = self.hmac(self.encode(auth), self.encode(self.secret))
body = self.urlencode(self.extend({
'clientId': self.uid,
'nonce': nonce,
'publicKey': self.apiKey,
'signature': signature.upper(),
}, params))
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
return {'url': url, 'method': method, 'body': body, 'headers': headers}
async def request(self, path, api='public', method='GET', params={}, headers=None, body=None):
response = await self.fetch2(path, api, method, params, headers, body)
if 'error' in response:
if response['error']:
raise ExchangeError(self.id + ' ' + self.json(response))
return response