geekpete / py-coinspot-api Goto Github PK
View Code? Open in Web Editor NEWA python library for the Coinspot API.
License: Other
A python library for the Coinspot API.
License: Other
Hi geekpete,
I tried converting the coinspot.py to python3 compatible:
but it always returns a {"status":"invalid"}. is there something else that needs to be done to make this python3 compatible?
Sample code:
import hashlib
import json
import hmac
import requests
def apiRequest(apiModel, method, apiKey, secret):
postdata = {}
nonce = int(time()*1000000)
postdata['nonce'] = nonce
sign = hmac.new(secret.encode('utf-8'), json.dumps(postdata).encode('utf-8'), hashlib.sha512).hexdigest()
headers = {}
headers['Content-type'] = 'application/json'
headers['Accept'] = 'text/plain'
headers['key'] = apiKey
headers['sign'] = sign
response = requests.post('https://www.coinbase.com.au/api/my/balances', headers=headers, data=json.dumps(postdata))
return response.text
In coinspot.py httplib has been deprecated in Python 3.
Recommend changing from:
import hmac
import hashlib
import httplib
import json
import yaml
import os
import sys
import logging
from time import time, strftime
to:
import hmac
import hashlib
try:
import httplib
except:
import http.client
import json
import yaml
import os
import sys
import logging
from time import time, strftime
Tested working in 3.6.2
Would have worked in dev when the config.yml was in the same dir using:
os.path.dirname(file)
but breaks if installed via PyPi and yml file is inside user's local homedir folder.
Needs to work wherever you want to put the config.yml file.
So test case is a user does the following:
-installs py-coinspot-api module with pip
-configures a config.yml file in their current dir
-takes example python file and saves in their current dir
-runs the script and hits this error:
./test.py
Attempting to load config.yml I/O error(2): No such file or directory
The required location of the config.yml file as it sits in the code now has to be in the library install path.
I'm leaning towards a low level library not needing to manage yaml files, and just have the user's script have a yaml file if the user want's to store their creds that way.
The library only needs to know what those creds are, when it gets initialised.
#!/usr/bin/python
__author__ = 'Peter Dyson <[email protected]>'
"""
Script to test the coinspot-api module.
"""
from coinspot import Coinspot
api_key = '' # Add your Coinspot API Key
api_secret = '' # Add your Coinspot API Secret
# Test it out:
client = Coinspot(api_key, api_secret)
# get the spot prices
print client.spot()
# get your coin wallet balances
print client.balances()
# get the last 1000 orders for Dogecoins
print client.orderhistory('DOGE')
# get a list of all the current buy and sell orders
print client.orders('DOGE')
# put an order in to sell 20 Dogecoins at 0.000280 per coin
print client.sell('DOGE', '20', '0.000280')
# Get a quote on buying a billion Dogecoins, with estimation of timeframe
print client.quotebuy('DOGE', 1000000000)
# Donate a craptonne of Dogecoins to the author of this library! Much Appreciate!!!
print client.send('DOGE', 'DJrHRxurwQoBUe7r9RsMkMrTxj92wXd5gs', 1000)
When running many calls in quick succession (ie, without a pause) the time nonce may not be granular enough to ensure uniqueness between calls.
Sending two api calls using the same nonce will result in the subsequent calls returning a status invalid.
Add some other extra salt or use a more granular time value.
As pointed out by http://www.reddit.com/user/helix09 there should be a way to request only specific coin detail for any API call that currently returns multiple coin result data.
balances()
myorders()
spot()
Hi,
Thanks for making this package. Is anyone else getting a circular dependency issue when trying to import the CoinSpot package?
I am using Python3.5 and I get an import error:
from coinspot import CoinSpot
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-d10b2caa352c> in <module>()
----> 1 from coinspot import CoinSpot as CS
~/.local/lib/python3.5/site-packages/coinspot/__init__.py in <module>()
----> 1 from coinspot import CoinSpot
2
ImportError: cannot import name 'CoinSpot'
CoinSpot have released the new API V2 in BETA format (https://www.coinspot.com.au/v2/api). According to CoinSpot the new API provides additional functionality as well as enhancements of existing processes.
This is a request to implement all of the API calls from v2
This is rough code, but it seems to work for getting prices. Something like this should be in the API if it isn't already.
-# import libraries
import urllib2
from bs4 import BeautifulSoup
-# specify the url
quote_page = "https://www.coinspot.com.au/buy/dgb"
-# query the website and return the html to the variable page
hdr = {'User-Agent': 'Mozilla/5.0'}
req = urllib2.Request(quote_page,headers=hdr)
page = urllib2.urlopen(req)
-# parse the html using beautiful soup and store in variable soup
soup = BeautifulSoup(page, "html.parser")
-# Take out the
-# strip() is used to remove starting and trailing
name = name_box.text.strip()
print name
Log responses using:
logger.debug('Response: %s' % response)
The Coinspot._request private function especailly needs some exception handling when communicating with the API endpoint.
As discussed
I suggest we also give the config file a fairly unique name to avoid collision such as:
coinspot.yml
to avoid loading any old config.yml find we find.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.