forked from ccxt/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfybse.py
More file actions
166 lines (152 loc) · 5.63 KB
/
fybse.py
File metadata and controls
166 lines (152 loc) · 5.63 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
# -*- 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 hashlib
from ccxt.base.errors import ExchangeError
class fybse (Exchange):
def describe(self):
return self.deep_extend(super(fybse, self).describe(), {
'id': 'fybse',
'name': 'FYB-SE',
'countries': ['SE'], # Sweden
'has': {
'CORS': False,
},
'rateLimit': 1500,
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/27766512-31019772-5edb-11e7-8241-2e675e6797f1.jpg',
'api': 'https://www.fybse.se/api/SEK',
'www': 'https://www.fybse.se',
'doc': 'http://docs.fyb.apiary.io',
},
'api': {
'public': {
'get': [
'ticker',
'tickerdetailed',
'orderbook',
'trades',
],
},
'private': {
'post': [
'test',
'getaccinfo',
'getpendingorders',
'getorderhistory',
'cancelpendingorder',
'placeorder',
'withdraw',
],
},
},
'markets': {
'BTC/SEK': {'id': 'SEK', 'symbol': 'BTC/SEK', 'base': 'BTC', 'quote': 'SEK'},
},
})
def fetch_balance(self, params={}):
balance = self.privatePostGetaccinfo()
btc = float(balance['btcBal'])
symbol = self.symbols[0]
quote = self.markets[symbol]['quote']
lowercase = quote.lower() + 'Bal'
fiat = float(balance[lowercase])
crypto = {
'free': btc,
'used': 0.0,
'total': btc,
}
result = {'BTC': crypto}
result[quote] = {
'free': fiat,
'used': 0.0,
'total': fiat,
}
result['info'] = balance
return self.parse_balance(result)
def fetch_order_book(self, symbol, limit=None, params={}):
orderbook = self.publicGetOrderbook(params)
return self.parse_order_book(orderbook)
def fetch_ticker(self, symbol, params={}):
ticker = self.publicGetTickerdetailed(params)
timestamp = self.milliseconds()
last = None
volume = None
if 'last' in ticker:
last = self.safe_float(ticker, 'last')
if 'vol' in ticker:
volume = self.safe_float(ticker, 'vol')
return {
'symbol': symbol,
'timestamp': timestamp,
'datetime': self.iso8601(timestamp),
'high': None,
'low': None,
'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': volume,
'quoteVolume': None,
'info': ticker,
}
def parse_trade(self, trade, market):
timestamp = int(trade['date']) * 1000
return {
'info': trade,
'id': str(trade['tid']),
'order': None,
'timestamp': timestamp,
'datetime': self.iso8601(timestamp),
'symbol': market['symbol'],
'type': None,
'side': None,
'price': self.safe_float(trade, 'price'),
'amount': self.safe_float(trade, 'amount'),
}
def fetch_trades(self, symbol, since=None, limit=None, params={}):
market = self.market(symbol)
response = self.publicGetTrades(params)
return self.parse_trades(response, market, since, limit)
def create_order(self, symbol, type, side, amount, price=None, params={}):
response = self.privatePostPlaceorder(self.extend({
'qty': amount,
'price': price,
'type': side[0].upper(),
}, params))
return {
'info': response,
'id': response['pending_oid'],
}
def cancel_order(self, id, symbol=None, params={}):
return self.privatePostCancelpendingorder({'orderNo': id})
def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
url = self.urls['api'] + '/' + path
if api == 'public':
url += '.json'
else:
self.check_required_credentials()
nonce = self.nonce()
body = self.urlencode(self.extend({'timestamp': nonce}, params))
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'key': self.apiKey,
'sig': self.hmac(self.encode(body), self.encode(self.secret), hashlib.sha1),
}
return {'url': url, 'method': method, 'body': body, 'headers': headers}
def request(self, path, api='public', method='GET', params={}, headers=None, body=None):
response = self.fetch2(path, api, method, params, headers, body)
if api == 'private':
if 'error' in response:
if response['error']:
raise ExchangeError(self.id + ' ' + self.json(response))
return response