forked from ccxt/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbl3p.py
More file actions
192 lines (178 loc) · 7.38 KB
/
bl3p.py
File metadata and controls
192 lines (178 loc) · 7.38 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
# -*- 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.base.exchange import Exchange
import base64
import hashlib
class bl3p (Exchange):
def describe(self):
return self.deep_extend(super(bl3p, self).describe(), {
'id': 'bl3p',
'name': 'BL3P',
'countries': ['NL', 'EU'], # Netherlands, EU
'rateLimit': 1000,
'version': '1',
'comment': 'An exchange market by BitonicNL',
'has': {
'CORS': False,
},
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/28501752-60c21b82-6feb-11e7-818b-055ee6d0e754.jpg',
'api': 'https://api.bl3p.eu',
'www': [
'https://bl3p.eu',
'https://bitonic.nl',
],
'doc': [
'https://github.com/BitonicNL/bl3p-api/tree/master/docs',
'https://bl3p.eu/api',
'https://bitonic.nl/en/api',
],
},
'api': {
'public': {
'get': [
'{market}/ticker',
'{market}/orderbook',
'{market}/trades',
],
},
'private': {
'post': [
'{market}/money/depth/full',
'{market}/money/order/add',
'{market}/money/order/cancel',
'{market}/money/order/result',
'{market}/money/orders',
'{market}/money/orders/history',
'{market}/money/trades/fetch',
'GENMKT/money/info',
'GENMKT/money/deposit_address',
'GENMKT/money/new_deposit_address',
'GENMKT/money/wallet/history',
'GENMKT/money/withdraw',
],
},
},
'markets': {
'BTC/EUR': {'id': 'BTCEUR', 'symbol': 'BTC/EUR', 'base': 'BTC', 'quote': 'EUR', 'maker': 0.0025, 'taker': 0.0025},
'LTC/EUR': {'id': 'LTCEUR', 'symbol': 'LTC/EUR', 'base': 'LTC', 'quote': 'EUR', 'maker': 0.0025, 'taker': 0.0025},
},
})
def fetch_balance(self, params={}):
response = self.privatePostGENMKTMoneyInfo()
data = response['data']
balance = data['wallets']
result = {'info': data}
currencies = list(self.currencies.keys())
for i in range(0, len(currencies)):
currency = currencies[i]
account = self.account()
if currency in balance:
if 'available' in balance[currency]:
account['free'] = float(balance[currency]['available']['value'])
if currency in balance:
if 'balance' in balance[currency]:
account['total'] = float(balance[currency]['balance']['value'])
if account['total']:
if account['free']:
account['used'] = account['total'] - account['free']
result[currency] = account
return self.parse_balance(result)
def parse_bid_ask(self, bidask, priceKey=0, amountKey=0):
return [
bidask[priceKey] / 100000.0,
bidask[amountKey] / 100000000.0,
]
def fetch_order_book(self, symbol, limit=None, params={}):
market = self.market(symbol)
response = self.publicGetMarketOrderbook(self.extend({
'market': market['id'],
}, params))
orderbook = response['data']
return self.parse_order_book(orderbook, None, 'bids', 'asks', 'price_int', 'amount_int')
def fetch_ticker(self, symbol, params={}):
ticker = self.publicGetMarketTicker(self.extend({
'market': self.market_id(symbol),
}, params))
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'),
'askVolume': None,
'vwap': None,
'open': None,
'close': last,
'last': last,
'previousClose': None,
'change': None,
'percentage': None,
'average': None,
'baseVolume': float(ticker['volume']['24h']),
'quoteVolume': None,
'info': ticker,
}
def parse_trade(self, trade, market):
return {
'id': str(trade['trade_id']),
'timestamp': trade['date'],
'datetime': self.iso8601(trade['date']),
'symbol': market['symbol'],
'type': None,
'side': None,
'price': trade['price_int'] / 100000.0,
'amount': trade['amount_int'] / 100000000.0,
'info': trade,
}
def fetch_trades(self, symbol, since=None, limit=None, params={}):
market = self.market(symbol)
response = self.publicGetMarketTrades(self.extend({
'market': market['id'],
}, params))
result = self.parse_trades(response['data']['trades'], market, since, limit)
return result
def create_order(self, symbol, type, side, amount, price=None, params={}):
market = self.market(symbol)
order = {
'market': market['id'],
'amount_int': int(amount * 100000000),
'fee_currency': market['quote'],
'type': 'bid' if (side == 'buy') else 'ask',
}
if type == 'limit':
order['price_int'] = int(price * 100000.0)
response = self.privatePostMarketMoneyOrderAdd(self.extend(order, params))
return {
'info': response,
'id': str(response['data']['order_id']),
}
def cancel_order(self, id, symbol=None, params={}):
return self.privatePostMarketMoneyOrderCancel({'order_id': id})
def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
request = self.implode_params(path, params)
url = self.urls['api'] + '/' + self.version + '/' + request
query = self.omit(params, self.extract_params(path))
if api == 'public':
if query:
url += '?' + self.urlencode(query)
else:
self.check_required_credentials()
nonce = self.nonce()
body = self.urlencode(self.extend({'nonce': nonce}, query))
secret = base64.b64decode(self.secret)
# eslint-disable-next-line quotes
auth = request + "\0" + body
signature = self.hmac(self.encode(auth), secret, hashlib.sha512, 'base64')
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Rest-Key': self.apiKey,
'Rest-Sign': self.decode(signature),
}
return {'url': url, 'method': method, 'body': body, 'headers': headers}