Open ajeep8 opened 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 ;)
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.
Nils,
Your advise?