Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

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

Open
ajeep8 opened this issue Apr 19, 2018 · 4 comments
Open

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

ajeep8 opened this issue Apr 19, 2018 · 4 comments

Comments

@ajeep8
Copy link

ajeep8 commented Apr 19, 2018

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
Copy link
Collaborator

  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
Copy link
Author

ajeep8 commented Apr 19, 2018

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

@firepol
Copy link

firepol commented Apr 21, 2018

@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
Copy link
Collaborator

deepbrook commented Apr 24, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants