bitex icon indicating copy to clipboard operation
bitex copied to clipboard

2 modifies I want to make, Nils' advise?

Open ajeep8 opened this issue 6 years ago • 4 comments

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?

ajeep8 avatar Apr 19 '18 09:04 ajeep8

  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.

deepbrook avatar Apr 19 '18 09:04 deepbrook

  1. like this: apikeys = { "Bitfinex": ['key','secret','user_id','addr','version'], "Bitstamp": ['key','secret','user_id','addr','version'], ...... }

ajeep8 avatar Apr 19 '18 12:04 ajeep8

@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 ;)

firepol avatar Apr 21 '18 13:04 firepol

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.

deepbrook avatar Apr 24 '18 07:04 deepbrook