GithubHelp home page GithubHelp logo

crypto-toolbox / bitex Goto Github PK

View Code? Open in Web Editor NEW
484.0 484.0 137.0 3.87 MB

Crypto-currency Exchange API Framework

License: MIT License

Python 100.00%
api-wrapper crypto-currency-exchanges crypto-exchanges endpoint-communication exchange framework python3

bitex's People

Contributors

bnsmith3 avatar hajdbo avatar hughmacdonald avatar rchiossi avatar richardhoekstra avatar rudimeier avatar scythargon avatar technickai avatar zippymagician avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bitex's Issues

Supply Tests for Bitstamp Formatter

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.

Supply Tests for QuadrigaCX Formatter

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.

Supply Basic Test Facilities to check current Build

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).

  • Supply Package integrity tests
    Package imports without errors, when using it in standalone code.
  • Supply standardized methods integrity tests
    Methods execute without raising programming-related errors (invalid syntax, reference errors etc).
  • Supply Git hooks and scripts to run these tests on Release branches
    A hook should run upon merging any branch prefixed release- or hotfix- into the master branch. Provide this script in the repo.

Overhaul Test Suite

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.

Supply Tests for CCEX Formatter

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.

Implement Pair Formatter for each interface

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:

  • Atomic Commits
  • One Pullrequest per interface & formatter
  • Supply test for method

Add open_orders to BitEx Standardized Methods

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.

Supply Tests for it-Bit Formatter

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.

Supply Tests for Kraken Formatter

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 BTCIndonesia

Add an implementation of Bitcoin Indonesia's API to bitex.api, including signature method.

Supply Tests and Data for Signature Procedures

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):

  • Add Bitfinex sample data for signature method
  • Add Bittrex sample data for signature method
  • Add Bitstamp sample data for signature method
  • Add Bter sample data for signature method
  • Add CCEX sample data for signature method
  • Add CoinCheck sample data for signature method
  • Add Cryptopia sample data for signature method
  • Add GDAX sample data for signature method
  • Add Gemini sample data for signature method
  • Add HITBtc sample data for signature method
  • Add itBit sample data for signature method
  • Add Kraken sample data for signature method
  • Add OKCoin sample data for signature method
  • Add Poloniex sample data for signature method
  • Add QuadrigaCX sample data for signature method
  • Add Quoine sample data for signature method
  • Add The Rock Trading LTD sample data for signature method
  • Add Vaultoro sample data for signature method
  • Add Yunbi sample data for signature method

To-do list (Tests):

  • Add Bitfinex test for signature method
  • Add Bittrex test for signature method
  • Add Bitstamp test for signature method
  • Add Bter test for signature method
  • Add CCEX test for signature method
  • Add CoinCheck test for signature method
  • Add Cryptopia test for signature method
  • Add GDAX test for signature method
  • Add Gemini test for signature method
  • Add HITBtc test for signature method
  • Add itBit test for signature method
  • Add Kraken test for signature method
  • Add OKCoin test for signature method
  • Add Poloniex test for signature method
  • Add QuadrigaCX test for signature method
  • Add Quoine test for signature method
  • Add The Rock Trading LTD test for signature method
  • Add Vaultoro test for signature method
  • Add Yunbi test for signature method

Write decorator for http times

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.

Implement more client.send() options

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;

Supply Tests for Bitfinex Formatter

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.

Supply Tests for Poloniex Formatter

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.

Supply Tests for Quoine Formatter

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.

Supply Tests for Bittrex Formatter

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.

Supply Tests for CoinCheck Formatters

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.

Supply Tests for Yunbi Formatter

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.

Ensure unified layout for Websocket Data Tuples on Queue

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.

Supply Tests for OkCoin Formatter

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.

Supply Test Data for Standardized Methods

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

  • Add Bitfinex sample data for all standardized endpoints
  • Add Bittrex sample data for all standardized endpoints
  • Add Bitstamp sample data for all standardized endpoints
  • Add Bter sample data for all standardized endpoints
  • Add CCEX sample data for all standardized endpoints
  • Add CoinCheck sample data for all standardized endpoints
  • Add Cryptopia sample data for all standardized endpoints
  • Add GDAX sample data for all standardized endpoints
  • Add Gemini sample data for all standardized endpoints
  • Add HITBtc sample data for all standardized endpoints
  • Add itBit sample data for all standardized endpoints
  • Add Kraken sample data for all standardized endpoints
  • Add OKCoin sample data for all standardized endpoints
  • Add Poloniex sample data for all standardized endpoints
  • Add QuadrigaCX sample data for all standardized endpoints
  • Add Quoine sample data for all standardized endpoints
  • Add The Rock Trading LTD sample data for all standardized endpoints
  • Add Vaultoro sample data for all standardized endpoints
  • Add Yunbi sample data for all standardized endpoints

Replace 'amount' parameter with 'size'

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 Error Checking Decorators

Add decorators for http clients, to check for faulty queries and raise meaningful errors (using custom exceptions)

Handle BitEx Standard Methods which cannot be implemented

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()

Supply Tests for GDAX Formatter

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.

Cryptopia signing failure

Issue with authentication signing for Cryptopia under 1.1.3 (and 2.0)

Steps to reproduce

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())"

Actual results

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'
  1. Same as 1)

  2. As expected

{'Error': 'Signature does not match request parameters.', 'Success': False}

Expected Results

  1. Balance of all currencies in wallets
  2. Balance of BTC wallet
  3. Balance of all currencies in wallets
  4. Balance of BTC wallet

Reproducibility

This error is reproducible every time

Additional Information

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.

Supply Tests for Gemini Formatters

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.

Pairformatter for Kraken needs DASH Edge Case Handling

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", [...]},
[...]}```

Supply Tests for RockTradingLTD Formatter

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.

Supply Tests for Cryptopia Formatters

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.