Python client for CoinPayments API

Overview

pyCoinPayments - Python API client for CoinPayments

Updates

This library has now been converted to work with python3

This is an unofficial client for CoinPayments, a website that exposes an API which allows you to accept over 75 cryptocurrencies.

The Absolute Basics

CoinPayments has the following API routes available to POST against. This is a POST only api where API calls are made using a 'cmd' parameter.

Their official API endpoint is https://www.coinpayments.net/api.php all calls are made against the same URL. Normally (without this client) you'd need to pass a 'cmd' parameter like below to the endpoint to distinguish between the API calls. This client simplifies things so calling each API method automatically does this for you.

{'cmd':'get_basic_info'}

is how you would call the 'Get Basic Account Information' API, this is handled automatically by the methods in this API so calling

CryptoPayments().getBasicInfo()

does this for you.

Basic Program

To show you a basic using of the program I'm going to be calling the create_transaction method on the CoinPaymentsAPI

## Parameters for your call, these are defined in the CoinPayments API Docs
## https://www.coinpayments.net/apidoc

create_transaction_params = {
    'amount' : 10,
    'currency1' : 'USD',
    'currency2' : 'BTC'
}

#Client instance
client = CryptoPayments(API_KEY, API_SECRET, IPN_URL)

#make the call to createTransaction crypto payments API
transaction = client.createTransaction(create_transaction_params)


if transaction['error'] == 'ok':  #check error status 'ok' means the API returned with desired result
    print (transaction['amount']) #print some values from the result
    print (transaction['address'])
else:
    print (transaction['error'])


#Use previous tx Id returned from the previous createTransaction method to test the getTransactionInfo call
post_params1 = {
    'txid' : transaction['txn_id'],
}


transactionInfo = client.getTransactionInfo(post_params1) #call coinpayments API using instance

if transactionInfo['error'] == 'ok': #check error status 'ok' means the API returned with desired result
    print (transactionInfo['amountf'])
    print (transactionInfo['payment_address'])
else:
    print (transactionInfo['error'])

You can reference any of their return fields within the json as a field on the variable. For example the transaction.amount would print out the amount of requested cryptocurrency, same with the address. Their documentation outlines what it returned for fields in each request. The rest of the API client is very similar. Parameters are passed into the API method using a python dictionary, order in this case does not matter because the HMAC and encoded URL are generated at the same time.

Comments
  • Adding Python3 Support

    Adding Python3 Support

    Hello thanks for making this script ,if you have time can you convert the code to be usable in python3 since per my understanding urllib2 was combined to urrlib in python 3 and when i try to run use the code i get errors. Thanks

    opened by codingsett 5
  • getTransactionInfo issue

    getTransactionInfo issue

    Hi there,

    I tried to pull a transaction using getTransactionInfo. I used a correct TXID however it is not returning anything to me. All I get is []. Any idea why that is happeing?

    Thanks.

    opened by bitog 4
  • import error

    import error

    Hi there,

    I am getting the following error ImportError: cannot import name 'CryptoPayments'.

    Module has been importet with from CryptoPayments import CryptoPayments.

    opened by bitog 4
  • JSON expecting value: line 1 column 1

    JSON expecting value: line 1 column 1

    :   File "/home/pei/Documents/all/./__init__.py", line 67, in <module>
    :     MAIN_BOT = MainBot(
    :   File "/home/pei/Documents/all/./components/models.py", line 54, in __init__
    :     coins = self.coin_payments.rates({"accepted": 1})
    :   File "/home/pi/.local/lib/python3.10/site-packages/pycoinpayments/coinpayments.py", line 47, in rates
    :     return self._handle_request('POST', url, params)
    :   File "/home/pei/.local/lib/python3.10/site-packages/pycoinpayments/apiConfig.py", line 92, in _handle_request
    :     response_body_decoded = json.loads(
    :   File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    :     return _default_decoder.decode(s)
    :   File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
    :     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    :   File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
    :     raise JSONDecodeError("Expecting value", s, err.value) from None
    : json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
    

    I get this when using this code:

    self.coin_payments = CoinPayments(
                private_config["coinpayments_private_key"],
                private_config["coinpayments_public_key"],
            )
    
            # get coins data
            coins = self.coin_payments.rates({"accepted": 1})
    

    This started happening out of nowhere. Help would be highly appreciated.

    opened by peepo5 0
  • KeyError

    KeyError

    I am getting the following error

    C:\Users\Admin\PycharmProjects\paying\main.py:57: DeprecationWarning: The SafeConfigParser class has been renamed to ConfigParser in Python 3.2. This alias will be removed in future versions. Use ConfigParser di
    rectly instead.
      parser = SafeConfigParser()
    No 'buyer_email' set! If you cannot obtain the buyer's email and want to handle refunds on your own you can use your own email instead.
    Traceback (most recent call last):
      File "C:\Users\Admin\PycharmProjects\paying\main.py", line 97, in <module>
        bot.polling()
      File "C:\Python310\lib\site-packages\telebot\__init__.py", line 658, in polling
        self.__threaded_polling(non_stop, interval, timeout, long_polling_timeout, allowed_updates)
      File "C:\Python310\lib\site-packages\telebot\__init__.py", line 720, in __threaded_polling
        raise e
      File "C:\Python310\lib\site-packages\telebot\__init__.py", line 680, in __threaded_polling
        self.worker_pool.raise_exceptions()
      File "C:\Python310\lib\site-packages\telebot\util.py", line 135, in raise_exceptions
        raise self.exception_info
      File "C:\Python310\lib\site-packages\telebot\util.py", line 87, in run
        task(*args, **kwargs)
      File "C:\Users\Admin\PycharmProjects\paying\main.py", line 84, in r1day
        'txid': getrday['txn_id'],
    KeyError: 'txn_id'
    
    
    
    

    Below is my code

    @bot.message_handler(content_types=["text"], func=lambda message: message.text == "🚀 1 Day")
    def r1day(message):
        buyrday = {
            'amount': 50,
            'currency1': 'USD',
            'currency2': 'BTC'
        }
        client = CryptoPayments(API_KEY, API_SECRET, IPN_URL)
        getrday = client.createTransaction(buyrday)
    
        if getrday['error'] == 'ok':  # check error status 'ok' means the API returned with desired result
            print(getrday['amount'])  # print some values from the result
            print(getrday['address'])
            bot.send_message(message.chat.id, (getrday['amount']), (getrday['address']))
        else:
            print(getrday['error'])
            bot.send_message(message.chat.id, (getrday['error']))
    
            post_params1 = {
                'txid': getrday['txn_id'],
            }
    
            getrdayInfo = client.getTransactionInfo(post_params1)  # call coinpayments API using instance
            if getrdayInfo['error'] == 'ok':  # check error status 'ok' means the API returned with desired result
                print(getrdayInfo['amountf'])
                print(getrdayInfo['payment_address'])
                bot.send_message(message.chat.id, (getrdayInfo['amountf']), (getrdayInfo['payment_address']))
            else:
                print(getrdayInfo['error'])
                bot.send_message(message.chat.id, (getrdayInfo['error']))
    
    opened by prodplug 0
Owner
James
James
Beyonic API Python official client library simplified examples using Flask, Django and Fast API.

Beyonic API Python official client library simplified examples using Flask, Django and Fast API.

Harun Mbaabu Mwenda 46 Sep 1, 2022
Python API Client for Twitter API v2

?? Python Client For Twitter API v2 ?? Why Twitter Stream ? Twitter-Stream.py a python API client for Twitter API v2 now supports FilteredStream, Samp

Twitivity 31 Nov 19, 2022
Dns-Client-Server - Dns Client Server For Python

Dns-client-server DNS Server: supporting all types of queries and replies. Shoul

Nishant Badgujar 1 Feb 15, 2022
Raphtory-client - The python client for the Raphtory project

Raphtory Client This is the python client for the Raphtory project Install via p

Raphtory 5 Apr 28, 2022
Drcom-pt-client - Drcom Pt version client with refresh timer

drcom-pt-client Drcom Pt version client with refresh timer Dr.com Pt版本客户端 可用于网页认

null 4 Nov 16, 2022
Official Python client for the MonkeyLearn API. Build and consume machine learning models for language processing from your Python apps.

MonkeyLearn API for Python Official Python client for the MonkeyLearn API. Build and run machine learning models for language processing from your Pyt

MonkeyLearn 157 Nov 22, 2022
🖥️ Python - P1 Monitor API Asynchronous Python Client

??️ Asynchronous Python client for the P1 Monitor

Klaas Schoute 9 Dec 12, 2022
Python API Client for Close

Close API A convenient Python wrapper for the Close API. API docs: http://developer.close.com Support: [email protected] Installation pip install clos

Close 56 Nov 30, 2022
DEPRECATED - Official Python Client for the Discogs API

⚠️ DEPRECATED This repository is no longer maintained. You can still use a REST client like Requests or other third-party Python library to access the

Discogs 483 Dec 31, 2022
The Foursquare API client for Python

foursquare Python client for the foursquare API. Philosophy: Map foursquare's endpoints one-to-one Clean, simple, Pythonic calls Only handle raw data,

Mike Lewis 400 Dec 19, 2022
Python Client for Instagram API

This project is not actively maintained. Proceed at your own risk! python-instagram A Python 2/3 client for the Instagram REST and Search APIs Install

Facebook Archive 2.9k Dec 30, 2022
A Python Client for News API

newsapi-python A Python client for the News API. License Provided under MIT License by Matt Lisivick. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRAN

Matt Lisivick 281 Dec 29, 2022
SmartFile API Client (Python).

A SmartFile Open Source project. Read more about how SmartFile uses and contributes to Open Source software. Summary This library includes two API cli

SmartFile 19 Jan 11, 2022
Python client for the Socrata Open Data API

sodapy sodapy is a python client for the Socrata Open Data API. Installation You can install with pip install sodapy. If you want to install from sour

Cristina 368 Dec 9, 2022
Python client for the Echo Nest API

Pyechonest Tap into The Echo Nest's Musical Brain for the best music search, information, recommendations and remix tools on the web. Pyechonest is an

The Echo Nest 655 Dec 29, 2022
A Python Tumblr API v2 Client

PyTumblr Installation Install via pip: $ pip install pytumblr Install from source: $ git clone https://github.com/tumblr/pytumblr.git $ cd pytumblr $

Tumblr 677 Dec 21, 2022
A super awesome Twitter API client for Python.

birdy birdy is a super awesome Twitter API client for Python in just a little under 400 LOC. TL;DR Features Future proof dynamic API with full REST an

Inueni 259 Dec 28, 2022
Cord Python API Client

Cord Python API Client The data programming platform for AI ?? Features Minimal low-level Python client that allows you to interact with Cord's API Su

Cord 52 Nov 25, 2022
Pure Python 3 MTProto API Telegram client library, for bots too!

Telethon ⭐️ Thanks everyone who has starred the project, it means a lot! Telethon is an asyncio Python 3 MTProto library to interact with Telegram's A

LonamiWebs 7.3k Jan 1, 2023