Code Monkey home page Code Monkey logo

py-coinspot-api's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

py-coinspot-api's Issues

Incompatible with python3 - CoinSpot API also down

Hi geekpete,

I tried converting the coinspot.py to python3 compatible:

  • switching the httplib to requests
  • signature:
    -- encoding utf-8 for the secret
    -- encoding utf-8 for json payload

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

BeautifulSoup price extraction

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

of name and get its value
name_box = soup.find('h1', attrs={'class': 'price-title'})

-# strip() is used to remove starting and trailing
name = name_box.text.strip()
print name

Review/improve documentation example in readme

#!/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)

Add some exception handling

The Coinspot._request private function especailly needs some exception handling when communicating with the API endpoint.

Circular Dependency?

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'

config.yml loading breaks if yml file not put in same dir as module

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.

Add YAML config file capability with sensible location discovery options

As discussed

  • YAML file a capability but not a requirement.
    Allow users to just send creds directly at the library i they want. But strongly guide users away from this practice with warnings of them going broke if someone trawls their api keys out of github to pilfer their coinz.
  • environment variables
  • add dir of executing script to the PATH and try to find YAML file in the path

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.

Support for API V2

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

Nonce is time based, ensure it's always unique and incremented each time

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.

coinspot.py httplib Python 3 Deprecated

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.