crypto-toolbox / bitex Goto Github PK
View Code? Open in Web Editor NEWCrypto-currency Exchange API Framework
License: MIT License
Crypto-currency Exchange API Framework
License: MIT License
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
Should have been implemented from the start, but since this project started out during the first year of my apprenticeship.. well.
The Tests should check that no errors occur while importing the package to python, and ensure functionality on our end (endpoint methods should execute without raising programming-related errors).
release-
or hotfix-
into the master
branch. Provide this script in the repo.For the next Release, we're planning to implement a complete overhaul of our current test suite.
This includes a complete dummy data set for all standardized methods, which were implemented for an exchange - and of course implementation of test cases for all other parts of BitEx
, including bitex.api
.
This will be alot of work, but we feel it's necessary to further promote a hygenic, professional development atmosphere, as well as making it easier for people to jump in and help out.
A complete list of tasks can be found below. Each task is linked to its related issue, where more detail is given about its requirements, and any special conditions which may apply.
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
A common problem with exchanges is the variety of ways they write their symbols.
An Example:
Poloniex:
BTC_LTC
Kraken:
LTCXBT, or XLTCXXBT
Bittrex:
LTC-BTC
in addition, some exchange APIs have case sensitive endpoints - Bitstamp for example, has endpoints that require lower-case letters, instead of caps.
In order to account for these, implement a method in each interface's formatter, which converts input into a valid format.
Do NOT check if the pair is available. That's not our job. However, for exchanges like poloniex, which express the pairs in the wrong order (BTC-LTC, although it's quoted in bitcoin, hence should be LTC-BTC), you're allowed to implement detection and format accordingly.
Example:
Bitstamp's valid pairs are btceur, btcusd, xrpusd, xrpeur, xrpbtc, eurusd.
Input: BTCEUR
-> format to btceur
Input: eurBTC
-> format to eurbtc
Input: BTC-CNY
-> format btccny
Requirements:
Tests for the APIClient ABC currently not working, since we can't instantiate an ABC by itself.
All major exchanges support a query which returns the opened orders for an account and sometimes for a specific market.
Usually the result from all exchanges is quite similar, and formatter can be easily created as well.
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
During development, I noticed various functions (and especially the initialisers) being redundant.
Some changes have varying names for symbols (for example Kraken uses XBTEUR, instead of BTCUSD).
Implement a decorator ( ? ) taking care of this.
Add an implementation of Bitcoin Indonesia's API to bitex.api
, including signature method.
Write tests and supply data to check for successful authentication procedures for each exchange.
Test data should be a validated digested signature for each exchange, against which our signature()
methods can be tested against. Be sure to include parameters (and make also VERY sure that you're not including your own private api keys and secret).
Dump them as raw json at bitex/tests/test_data
as "%s_signature.json" % exchange_name. The files should consist of two lines:
# example_signature.json
{"param1":"Value1", "param2": "value2"}
"the_digested_signature_resulting_from_the_above_params"
To-do list (Data):
To-do list (Tests):
currently, sent and received variables are written directly into code;
replace this with a @resp_timer decorator to remove redundant code from funcs and make them easier to read.
Convert / adapt Doc strings of functions and classes in bitex
classes and functions in a way that complies with RTD requirements.
It seems coincheck doesn't have endpoint implemented for DAO / ETH pairs currently; all query seem to return the BTCJPY book.
As of now, all data received is pumped out via udp socket.
For convenience, this should feature the possibility of passing paths instead, so it saves the data to a file instead.
Although this might be in conflict with the postoffice module; this should handle this instead;
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
Add an implementation of Vaultoro's API to bitex.api
, including signature method.
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
https://www.bitstamp.net/api/
The withdrawal method currently takes no parameters; clarify if this endpoint is active / implemented w/ bitstamp
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
Add an implementation of BTC38's API to bitex.api
, including signature method.
Add an implementation of Vaultoro's API to bitex.api
, including signature method.
Figure out an implementation for withdrawal from yunbi, as API Docs are unclear
Websockets currently store tuples on their internal data_q
in different ways
for example:
Gemini stores the timestamp as a separate item in the tuple:
(endpoint, pair, data, ts)
whereas Bitfinex stores the timestamp in an item with the data received:
(endpoint, pair, (data, ts))
This should be unified (preferably the Gemini way, since the ts is local and not part of the received data).
Thanks to @JoakimBe, for helping me find this one.
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
Add dummy data set for each exchange and the implemented standardized methods. These can simply be queries made to the api, dumped as a raw json.
make sure you commit each query call and its response as a separate file.
An example:
let's say you'd like to submit Kraken
's Ticker
endpoint responses.
for the query at https://api.kraken.com/0/public/Ticker?pair=XXBTZEUR
you've got this:
{"error":[],"result":{"XXBTZEUR":{"a":["1104.63000","1","1.000"],"b":["1103.80300","1","1.000"],"c":["1103.79200","0.02650517"],"v":["859.75830107","3612.58175590"],"p":["1103.68713","1108.83109"],"t":[4078,10045],"l":["1095.00000","1092.10000"],"h":["1109.00000","1120.00000"],"o":"1096.99500"}}}
dump this to a file, in raw json, named bitex/tests/test_data/kraken_ticker_successful.json
, and commit this file referencing this issue's number in the commit. A command line example would be like this:
git add bitex/tests/test_data/kraken_ticker_successful.json; git commit -m "#60 Added Kraken Ticker successful call"
.
If you get an error during a call, we want that too!
Let's say you queried https://api.kraken.com/0/public/Ticker?pair=XXEUR
.
This results in {"error":["EQuery:Unknown asset pair"]}
. Dump it to a file in the same directory as before and name it kraken_ticker_failed_invalidpair.json
- be descriptive with failure messages!
We don't necessarily require each and every single error message for an endpoint - but at least one failure should be added per endpoint nonetheless - it helps us ensure that faulty requests are properly handled for each.
To do list
Example:
def ask(self, pair, price, amount, **kwargs):
to:
def ask(self, pair, price, size, **kwargs):
replace all instances. One pull request per interface.
Add decorators for http clients, to check for faulty queries and raise meaningful errors (using custom exceptions)
Some exchanges do not offer some more advanced methods of the BitEx Standard Methods - for example withdraw() cannot be implemented for bitex.interfaces.CCEX.
Figure out if there's a more elegant way than the current raise NotImplementedError()
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
With 1.1.3:
python3 -c "import bitex;c = bitex.Cryptopia(key='<key>', secret='<secret>' );print(c.balance().json())"
python3 -c "import bitex;c = bitex.Cryptopia(key='<key>', secret='<secret>' );print(c.balance(Currency='BTC')).json()"
With 2.0:
python3 -c "import bitex;c = bitex.Cryptopia(key='<key>', secret='<secret>' );print(c.wallet().json())"
python3 -c "import bitex;c = bitex.Cryptopia(key='<key>', secret='<secret>' );print(c.wallet(Currency='BTC').json())"
ERROR:bitex.utils:return_api_response(): Error during call to balance((<bitex.interfaces.cryptopia.Cryptopia object at 0x10ef936a0>,), {})
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/bitex/utils.py", line 32, in wrapper
r = func(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/bitex/interfaces/cryptopia.py", line 81, in balance
return self.private_query('GetBalance', params=kwargs)
File "/usr/local/lib/python3.5/site-packages/bitex/interfaces/cryptopia.py", line 30, in private_query
return self.query('POST', endpoint, authenticate=True, **kwargs)
File "/usr/local/lib/python3.5/site-packages/bitex/api/REST/api.py", line 107, in query
method_verb, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/bitex/api/REST/rest.py", line 369, in sign
md5 = base64.b64encode(hashlib.md5().updated(post_data).digest())
AttributeError: '_hashlib.HASH' object has no attribute 'updated'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.5/site-packages/bitex/utils.py", line 32, in wrapper
r = func(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/bitex/interfaces/cryptopia.py", line 81, in balance
return self.private_query('GetBalance', params=kwargs)
File "/usr/local/lib/python3.5/site-packages/bitex/interfaces/cryptopia.py", line 30, in private_query
return self.query('POST', endpoint, authenticate=True, **kwargs)
File "/usr/local/lib/python3.5/site-packages/bitex/api/REST/api.py", line 107, in query
method_verb, *args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/bitex/api/REST/rest.py", line 369, in sign
md5 = base64.b64encode(hashlib.md5().updated(post_data).digest())
AttributeError: '_hashlib.HASH' object has no attribute 'updated'
Same as 1)
As expected
{'Error': 'Signature does not match request parameters.', 'Success': False}
This error is reproducible every time
If I copy the inner workings of sign() from the 2.0 branch, it works. This gives me a sign() method of:
def sign(self, uri, endpoint, endpoint_path, method_verb, *args, **kwargs):
nonce = self.nonce()
try:
params = kwargs['params']
except KeyError:
params = {}
post_data = json.dumps(params)
# generate signature
md5 = hashlib.md5()
md5.update(post_data.encode('utf-8'))
request_content_b64_string = base64.b64encode(md5.digest()).decode('utf-8')
signature = (self.key + 'POST' +
urllib.parse.quote_plus(uri).lower() +
nonce + request_content_b64_string)
hmac_sig = base64.b64encode(hmac.new(base64.b64decode(self.secret),
signature.encode('utf-8'),
hashlib.sha256).digest())
header_data = 'amx ' + self.key + ':' + hmac_sig.decode('utf-8') + ':' + nonce
# Update req_kwargs keys
headers = {'Authorization': header_data,
'Content-Type': 'application/json; charset=utf-8'}
return uri, {'headers': headers, 'data': post_data}
This then works for both 1. and 2. in 1.1.3
I can submit a PR if you'd like. It's my first time interacting with this repository so I wanted to put it in as an issue first.
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
With DASH now supported by Kraken, the currently implemented formatter needs a special case handler for this pair, since the currency does not use the prefix X
, like other pairs (i.e. DASHEUR is denoted as DASHZEUR
instead of XDASHZEUR
, which would have been the expected behaviour).
Excerpt from /AssetPairs
endpoint:
{ [...]"result":
{"DASHEUR":{
"altname":"DASHEUR",
"aclass_base":"currency",
"base":"DASH", # <-- expected format would have been XDASH, as is true for other pairs
"aclass_quote":"currency",
"quote":"ZEUR", [...]},
[...]}```
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
Check that all output received from standardized interface methods complies with the format as set in bitex.formatters.base
doc strings.
Do this by writing sensible tests and committing them as part of the file tests/formatters.py
.
Add an implementation of HitBTC's API to bitex.api
, including signature method.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.