Crypto-toolbox / bitex

Crypto-currency Exchange API Framework
MIT License
484 stars 136 forks source link

2 modifies I want to make, Nils' advise? #180

Open ajeep8 opened 6 years ago

ajeep8 commented 6 years ago

Nils,

  1. One config file for each market, it's not conveniently, I want change them to one config file.
  2. interface.base.__init__, each time new a market class, need fetch pairs, but pairs not change daily, it seem not necessary. And, many market has request limit, this double the request times, get "Too Many Requests" response. I want to save all pairs in one json file with timestamp, and config it's path in the config file. User can refresh pairs json file periodically, but in _get_supported_pairs only fetch from json file.

Your advise?

deepbrook commented 6 years ago
  1. What exactly do you mean by config file?
  2. Shouldn't be an issue since they ideally only initialize once - so it's really a single request more on start up.
ajeep8 commented 6 years ago
  1. like this: apikeys = { "Bitfinex": ['key','secret','user_id','addr','version'], "Bitstamp": ['key','secret','user_id','addr','version'], ...... }
firepol commented 6 years ago

@ajeep8 I'm also coding something based on bitex, I save APIs in a json config file and read it like this:

Here how my settings json looks like:

{
  "accounts": {
    "bitstamp": {
      "type": "bitstamp",
      "api": {
        "api_key": "",
        "api_secret": ""
      }
    },
    "binance": {
      "type": "binance",
      "api": {
        "api_key": "",
        "api_secret": ""
      }
    },
    "cexio": {
      "api": {
      "type": "cexio",
        "username": "",
        "api_key": "",
        "api_secret": ""
      }
    }
  }
}

Then I read it like this:

    settings_root = json.load(open(f'{data_path}/settings.json'))
    settings_accounts = settings_root['accounts']
    settings_bitstamp = settings_accounts['bitstamp']

In reality I loop the file and check the "type" (in my case type is the exchange name) and use it to create the correct api object based on it...

If you need an example on how to cache stuff in a json and read from the json if the json is not older than X seconds, minutes or so, have a look at my coinmarketcap-helper:

https://github.com/firepol/coinmarketcap-helper/blob/master/src/coinmarketcap_helper.py

Was this what you were looking for? Hope it helped ;)

deepbrook commented 6 years ago

Ah, now I got ya. I'm not a fan of the json format - however, you could merge the ini files into a single one, with sections for each API.

Like so:

[Bitfinex]
api_key=XXXXXXX
api_secret=YYYYYYY

[Bitstamp]
api_key=ZZZZZZZ
api_secret=VVVVVVV

Of course that would require some updates to the config parser methods.