-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dfab840
Showing
38 changed files
with
4,279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
MIT License http://www.opensource.org/licenses/mit-license.php | ||
|
||
Copyright (c) 2011 Glen Zangirolami | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
associated documentation files (the "Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject | ||
to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial | ||
portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
====== | ||
CampBX | ||
====== | ||
|
||
About | ||
===== | ||
|
||
This library provides python bindings for the `CampBX bitcoin trading platform <http://campbx.com>`_. | ||
To obtain API access please `see the documenation at CampBX <https://campbx.com/api.php>`_. | ||
|
||
Installation | ||
============ | ||
|
||
``pip install campbx`` | ||
|
||
Documentation | ||
============= | ||
|
||
Read the full documentation on `ReadTheDocs <http://campbx.readthedocs.org/>`_. | ||
|
||
Quick Usage | ||
=========== | ||
|
||
The API does not require a username and password, however you will have limited access | ||
to only the public endpoints. | ||
|
||
Initializing the API:: | ||
|
||
from campbx import CampBX | ||
c = CampBX('username', 'password') | ||
|
||
Getting market ticker:: | ||
|
||
c.xticker() | ||
|
||
{'Best Ask': '5.17', 'Best Bid': '5.07', 'Last Trade': '5.07'} | ||
|
||
Check your account balance:: | ||
|
||
c.my_funds() | ||
|
||
{'Liquid BTC': '0.00000000', | ||
'Liquid USD': '2.19', | ||
'Margin Account BTC': '0.00000000', | ||
'Margin Account USD': '0.00', | ||
'Total BTC': '15.00000000', | ||
'Total USD': '74.58'} | ||
|
||
Check your open orders:: | ||
|
||
c.my_orders() | ||
|
||
{'Buy': [{'Dark Pool': 'No', | ||
'Fill Type': 'Incremental', | ||
'Margin Percent': 'None', | ||
'Order Entered': '2012-04-10 08:59:51', | ||
'Order Expiry': '2012-05-11 00:00:00', | ||
'Order ID': '239801', | ||
'Order Type': 'Quick Buy', | ||
'Price': '4.50', | ||
'Quantity': '16.00000000', | ||
'Stop-loss': 'No'}], | ||
'Sell': [{'Dark Pool': 'No', | ||
'Fill Type': 'Incr', | ||
'Margin Percent': 'None', | ||
'Order Entered': '2012-04-05 22:07:05', | ||
'Order Expiry': '2012-05-06 00:00:00', | ||
'Order ID': '215603', | ||
'Order Type': 'Quick Sell', | ||
'Price': '5.20', | ||
'Quantity': '15.00000000', | ||
'Stop-loss': 'No'}]} | ||
|
||
License | ||
======= | ||
|
||
`MIT License <http://www.opensource.org/licenses/mit-license.php>`_ | ||
|
||
Copyright (c) 2011 Glen Zangirolami | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
associated documentation files (the "Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject | ||
to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial | ||
portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from campbx import CampBX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import urllib2 | ||
import base64 | ||
import simplejson as json | ||
import logging | ||
from urllib import urlencode | ||
from functools import partial | ||
|
||
log = logging.getLogger(__name__) | ||
log_formatter = logging.Formatter('%(name)s - %(message)s') | ||
log_handler = logging.StreamHandler() | ||
|
||
log_handler.setFormatter(log_formatter) | ||
log.addHandler(log_handler) | ||
log.setLevel(logging.ERROR) | ||
|
||
|
||
class CampBX(object): | ||
""" | ||
Camp BX API Class | ||
""" | ||
username = None | ||
password = None | ||
api_url = 'https://campbx.com/api/' | ||
log = None | ||
|
||
# API endpoints | ||
# { python_call : (url_php_call, requires_auth) } | ||
endpoints = { | ||
'xdepth': ('xdepth', False), | ||
'xticker': ('xticker', False), | ||
'my_funds': ('myfunds', True), | ||
'my_orders': ('myorders', True), | ||
'my_margins': ('mymargins', True), | ||
'get_btc_address': ('getbtcaddr', True), | ||
'send_instant': ('sendinstant', True), | ||
'send_btc': ('sendbtc', True), | ||
'trade_cancel': ('tradecancel', True), | ||
'trade_enter': ('tradeenter', True), | ||
'trade_advanced': ('tradeadv', True), | ||
} | ||
|
||
def __init__(self, username=None, password=None): | ||
self.username = username | ||
self.password = password | ||
|
||
# setup logging | ||
self.log = log | ||
|
||
# append all the enpoints to the class dictionary | ||
self._create_endpoints() | ||
|
||
def debug_mode(self, toggle): | ||
""" | ||
Toddle debug mode for more detailed output | ||
obj.debug_mode(True) - Turn debug mode on | ||
obj.debug_mode(False) - Turn debug mode off | ||
""" | ||
if toggle: | ||
self.log.setLevel(logging.DEBUG) | ||
else: | ||
self.log.setLevel(logging.ERROR) | ||
|
||
def _make_request(self, conf, *args, **kwargs): | ||
"""Make a request to the API and return data in a pythonic object""" | ||
endpoint, requires_auth = conf | ||
|
||
# setup the url and the request objects | ||
url = '%s%s.php' % (self.api_url, endpoint) | ||
log.debug('Setting url to %s' % url) | ||
request = urllib2.Request(url) | ||
|
||
# tack on authentication if needed | ||
if requires_auth: | ||
log.debug('Applying credentials for username %s' % self.username) | ||
kwargs.update({ | ||
'user': self.username, | ||
'pass': self.password | ||
}) | ||
|
||
# url encode all parameters | ||
data = urlencode(kwargs) | ||
|
||
# gimme some bitcoins! | ||
try: | ||
log.debug('Requesting data from %s' % url) | ||
response = urllib2.urlopen(request, data) | ||
return json.loads(response.read()) | ||
except urllib2.URLError, e: | ||
log.debug('Full error: %s' % e) | ||
if hasattr(e, 'reason'): | ||
self.log.error('Could not reach host. Reason: %s' % e.reason) | ||
elif hasattr(e, 'code'): | ||
self.log.error('Could not fulfill request. Error Code: %s' % e.code) | ||
return None | ||
|
||
def _create_endpoints(self): | ||
"""Create all api endpoints using self.endpoint and partial from functools""" | ||
for k, v in self.endpoints.items(): | ||
self.__dict__[k] = partial(self._make_request, v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
# Makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line. | ||
SPHINXOPTS = | ||
SPHINXBUILD = sphinx-build | ||
PAPER = | ||
BUILDDIR = build | ||
|
||
# Internal variables. | ||
PAPEROPT_a4 = -D latex_paper_size=a4 | ||
PAPEROPT_letter = -D latex_paper_size=letter | ||
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source | ||
# the i18n builder cannot share the environment and doctrees with the others | ||
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source | ||
|
||
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext | ||
|
||
help: | ||
@echo "Please use \`make <target>' where <target> is one of" | ||
@echo " html to make standalone HTML files" | ||
@echo " dirhtml to make HTML files named index.html in directories" | ||
@echo " singlehtml to make a single large HTML file" | ||
@echo " pickle to make pickle files" | ||
@echo " json to make JSON files" | ||
@echo " htmlhelp to make HTML files and a HTML help project" | ||
@echo " qthelp to make HTML files and a qthelp project" | ||
@echo " devhelp to make HTML files and a Devhelp project" | ||
@echo " epub to make an epub" | ||
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" | ||
@echo " latexpdf to make LaTeX files and run them through pdflatex" | ||
@echo " text to make text files" | ||
@echo " man to make manual pages" | ||
@echo " texinfo to make Texinfo files" | ||
@echo " info to make Texinfo files and run them through makeinfo" | ||
@echo " gettext to make PO message catalogs" | ||
@echo " changes to make an overview of all changed/added/deprecated items" | ||
@echo " linkcheck to check all external links for integrity" | ||
@echo " doctest to run all doctests embedded in the documentation (if enabled)" | ||
|
||
clean: | ||
-rm -rf $(BUILDDIR)/* | ||
|
||
html: | ||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html | ||
@echo | ||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html." | ||
|
||
dirhtml: | ||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml | ||
@echo | ||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." | ||
|
||
singlehtml: | ||
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml | ||
@echo | ||
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." | ||
|
||
pickle: | ||
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle | ||
@echo | ||
@echo "Build finished; now you can process the pickle files." | ||
|
||
json: | ||
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json | ||
@echo | ||
@echo "Build finished; now you can process the JSON files." | ||
|
||
htmlhelp: | ||
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp | ||
@echo | ||
@echo "Build finished; now you can run HTML Help Workshop with the" \ | ||
".hhp project file in $(BUILDDIR)/htmlhelp." | ||
|
||
qthelp: | ||
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp | ||
@echo | ||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \ | ||
".qhcp project file in $(BUILDDIR)/qthelp, like this:" | ||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/CampBX.qhcp" | ||
@echo "To view the help file:" | ||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/CampBX.qhc" | ||
|
||
devhelp: | ||
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp | ||
@echo | ||
@echo "Build finished." | ||
@echo "To view the help file:" | ||
@echo "# mkdir -p $$HOME/.local/share/devhelp/CampBX" | ||
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/CampBX" | ||
@echo "# devhelp" | ||
|
||
epub: | ||
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub | ||
@echo | ||
@echo "Build finished. The epub file is in $(BUILDDIR)/epub." | ||
|
||
latex: | ||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex | ||
@echo | ||
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." | ||
@echo "Run \`make' in that directory to run these through (pdf)latex" \ | ||
"(use \`make latexpdf' here to do that automatically)." | ||
|
||
latexpdf: | ||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex | ||
@echo "Running LaTeX files through pdflatex..." | ||
$(MAKE) -C $(BUILDDIR)/latex all-pdf | ||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." | ||
|
||
text: | ||
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text | ||
@echo | ||
@echo "Build finished. The text files are in $(BUILDDIR)/text." | ||
|
||
man: | ||
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man | ||
@echo | ||
@echo "Build finished. The manual pages are in $(BUILDDIR)/man." | ||
|
||
texinfo: | ||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo | ||
@echo | ||
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." | ||
@echo "Run \`make' in that directory to run these through makeinfo" \ | ||
"(use \`make info' here to do that automatically)." | ||
|
||
info: | ||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo | ||
@echo "Running Texinfo files through makeinfo..." | ||
make -C $(BUILDDIR)/texinfo info | ||
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." | ||
|
||
gettext: | ||
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale | ||
@echo | ||
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." | ||
|
||
changes: | ||
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes | ||
@echo | ||
@echo "The overview file is in $(BUILDDIR)/changes." | ||
|
||
linkcheck: | ||
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck | ||
@echo | ||
@echo "Link check complete; look for any errors in the above output " \ | ||
"or in $(BUILDDIR)/linkcheck/output.txt." | ||
|
||
doctest: | ||
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest | ||
@echo "Testing of doctests in the sources finished, look at the " \ | ||
"results in $(BUILDDIR)/doctest/output.txt." |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: 486e3d5e95979990f3a30a0fc0d2c6f0 | ||
tags: fbb0d17656682115ca4d033fb2f83ba1 |
Oops, something went wrong.