This would also allow subtyped btceapi.keyhandler.KeyHandler instances. An example of a subtyped KeyHandler class might be one that defines a close() function so the KeyHandler can be used with the 'with' syntax.
#!/usr/bin/env python
from contextlib import closing
import btceapi
import mybtceconfig
class ClosableKeyHandler(btceapi.KeyHandler):
def __init__(self, filename):
super(ClosableKeyHandler, self).__init__(filename, True)
def close(self):
self.save(self.filename)
with closing(ClosableKeyHandler(mybtceconfig.keyFile())) as keyHandler:
tapi = btceapi.TradeAPI(mybtceconfig.key(), keyHandler)
info = tapi.getInfo()
print 'Current balance (USD): %s' % info.balance_usd
Thanks! I'm going to also go ahead and add close, enter, and exit to the KeyHandler class, because being able to use them in a with statement and having an explicit close method seems like a good idea.
This would also allow subtyped btceapi.keyhandler.KeyHandler instances. An example of a subtyped KeyHandler class might be one that defines a close() function so the KeyHandler can be used with the 'with' syntax.