From e0aa76568f98dcb77a74db89aac24da76b8ab539 Mon Sep 17 00:00:00 2001 From: "romeo.delta" Date: Tue, 4 Jan 2022 14:49:18 +1000 Subject: [PATCH 1/8] remove apiv1 functions --- coinspot/coinspot.py | 166 ------------------------------------------- 1 file changed, 166 deletions(-) diff --git a/coinspot/coinspot.py b/coinspot/coinspot.py index 44647df..41dcce6 100644 --- a/coinspot/coinspot.py +++ b/coinspot/coinspot.py @@ -164,169 +164,3 @@ def _request(self, path, postdata): exit("Unexpected error: {0}".format(sys.exc_info()[0])) return response_data - - def sendcoin(self, cointype, address, amount): - """ - Send coins - - :param cointype: - the coin shortname in uppercase, example value 'BTC', 'LTC', 'DOGE' - :param address: - the address to send the coins to - :param amount: - the amount of coins to send - :return: - - **status** - ok, error - - """ - request_data = {"cointype": cointype, "address": address, "amount": amount} - return self._request("/api/my/coin/send", request_data) - - def coindeposit(self, cointype): - """ - Deposit coins - - :param cointype: - the coin shortname in uppercase, example value 'BTC', 'LTC', 'DOGE' - :return: - - **status** - ok, error - - **address** - your deposit address for the coin - - """ - request_data = {"cointype": cointype} - return self._request("/api/my/coin/deposit", request_data) - - def quotebuy(self, cointype, amount): - """ - Quick buy quote - - Fetches a quote on rate per coin and estimated timeframe to buy an amount of coins - - :param cointype: - the coin shortname in uppercase, example value 'BTC', 'LTC', 'DOGE' - :param amount: - the amount of coins to sell - :return: - - **status** - ok, error - - **quote** - the rate per coin - - **timeframe** - estimate of hours to wait for trade to complete (0 = immediate trade) - - """ - request_data = {"cointype": cointype, "amount": amount} - return self._request("/api/quote/buy", request_data) - - def quotesell(self, cointype, amount): - """ - Quick sell quote - - Fetches a quote on rate per coin and estimated timeframe to sell an amount of coins - - :param cointype: - the coin shortname in uppercase, example value 'BTC', 'LTC', 'DOGE' - :param amount: - the amount of coins to sell - :return: - - **status** - ok, error - - **quote** - the rate per coin - - **timeframe** - estimate of hours to wait for trade to complete (0 = immediate trade) - - """ - request_data = {"cointype": cointype, "amount": amount} - return self._request("/api/quote/sell", request_data) - - def spot(self): - """ - Fetch the latest spot prices - - :return: - - **status** - ok, error - - **spot** - a list of the current spot price for each coin type - - """ - return self._request("/api/spot", {}) - - def balances(self): - """ - List my balances - - :return: - - **status** - ok, error - - **balances** - object containing one property for each coin with your balance for that coin. - - """ - return self._request("/api/my/balances", {}) - - def orderhistory(self, cointype): - """ - Lists the last 1000 completed orders - - :param cointype: - the coin shortname in uppercase, example value 'BTC', 'LTC', 'DOGE' - :return: - - **status** - ok, error - - **orders** - list of the last 1000 completed orders - - """ - request_data = {"cointype": cointype} - return self._request("/api/orders/history", request_data) - - def orders(self, cointype): - """ - Lists all open orders - - :param cointype: - the coin shortname in uppercase, example value 'BTC', 'LTC', 'DOGE' - :return: - - **status** - ok, error - - **buyorders** - array containing all the open buy orders - - **sellorders** - array containing all the open sell orders - - """ - request_data = {"cointype": cointype} - return self._request("/api/orders", request_data) - - def myorders(self): - """ - List my buy and sell orders - - :return: - - **status** - ok, error - - **buyorders** - array containing all your buy orders - - **sellorders** - array containing all your sell orders - - """ - return self._request("/api/my/orders", {}) - - def buy(self, cointype, amount, rate): - """ - Place buy orders - - :param cointype: - the coin shortname in uppercase, example value 'BTC', 'LTC', 'DOGE' - :param amount: - the amount of coins you want to buy, max precision 8 decimal places - :param rate: - the rate in AUD you are willing to pay, max precision 6 decimal places - :return: - - **status** - ok, error - - """ - request_data = {"cointype": cointype, "amount": amount, "rate": rate} - return self._request("/api/my/buy", request_data) - - def sell(self, cointype, amount, rate): - """ - Place sell orders - - :param cointype: - the coin shortname in uppercase, example value 'BTC', 'LTC', 'DOGE' - :param amount: - the amount of coins you want to sell, max precision 8 decimal places - :param rate: - the rate in AUD you are willing to sell for, max precision 6 decimal places - :return: - - **status** - ok, error - - """ - request_data = {"cointype": cointype, "amount": amount, "rate": rate} - self._request("/api/my/sell", request_data) From be1757006b8a6a533b0a90af271aa888ffacaebd Mon Sep 17 00:00:00 2001 From: "romeo.delta" Date: Tue, 4 Jan 2022 14:50:18 +1000 Subject: [PATCH 2/8] add apiv2 functions --- coinspot/coinspot.py | 709 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 709 insertions(+) diff --git a/coinspot/coinspot.py b/coinspot/coinspot.py index 41dcce6..c9cee8a 100644 --- a/coinspot/coinspot.py +++ b/coinspot/coinspot.py @@ -164,3 +164,712 @@ def _request(self, path, postdata): exit("Unexpected error: {0}".format(sys.exc_info()[0])) return response_data + + def latestprices(self): + """ + Latest Prices + + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **prices** - array of objects with one set of properties for each coin with latest buy and sell prices, non aud markets are symbolised by (e.g.) 'btc_usdt' + + """ + request_data = {} + return self._request_public("/pubapi/v2/latest/", request_data) + + def coinprices(self, cointype): + """ + Latest Coin Prices + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **prices** - object with set of properties for coin with latest buy, ask and last prices + + """ + request_data = {"cointype":cointype} + return self._request_public("/pubapi/v2/latest/", request_data) + + def coinmarketprices(self, cointype, markettype): + """ + Latest Coin / Market Prices + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :param markettype: + market coin short name, example value 'USDT' (only for available markets) + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **prices** - object with set of properties for coin with latest buy, ask and last prices + + """ + request_data = {"cointype":cointype, "markettype":markettype} + return self._request_public("/pubapi/v2/latest/", request_data) + + def buyprice(self, cointype): + """ + Latest Buy Price + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **rate** - latest buy price for that coin + - **market** - market coin is trading in + + """ + request_data = {"cointype":cointype} + return self._request_public("/pubapi/v2/buyprice/", request_data) + + def buymarketprice(self, cointype, markettype): + """ + Latest Buy Price / Market + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :param markettype: + coin market you wish to use to buy it, example value: USDT' (only for available markets) + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **rate** - latest buy price for that coin + - **market** - market coin is trading in + + """ + request_data = {"cointype":cointype, "markettype":markettype} + return self._request_public("/pubapi/v2/buyprice/", request_data) + + def sellprice(self, cointype): + """ + Latest Sell Price + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **rate** - latest sell price for that coin + - **market** - market coin is trading in + + """ + request_data = {"cointype":cointype} + return self._request_public("/pubapi/v2/sellprice/", request_data) + + def sellmarketprice(self, cointype, markettype): + """ + Latest Sell Price / Market + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :param markettype: + coin market you wish to sell it for, example value: 'USDT' (note: only for available markets) + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **rate** - latest sell price for that coin + - **market** - market coin is trading in + + """ + request_data = {"cointype":cointype, "markettype":markettype} + return self._request_public("/pubapi/v2/sellprice/", request_data) + + def openorders(self, cointype): + """ + Open Orders By Coin + + :param cointype: + the coin short name, example value 'BTC', 'LTC', 'DOGE' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **buyorders** - list of top 100 open AUD buy orders for the given coin + - **sellorders** - list of top 100 open AUD sell orders for the given coin + + """ + request_data = {"cointype":cointype} + return self._request_public("/pubapi/v2/orders/open/", request_data) + + def openmarketorders(self, cointype, markettype): + """ + Open Orders By Coin / Market + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :param markettype: + coin market, example values 'USDT' (note: only for available markets) + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **buyorders** - list of top 20 open buy order rates for the given coin / market + - **sellorders** - list of top 20 open sell order rates for the given coin / market + + """ + request_data = {"cointype":cointype, "markettype":markettype} + return self._request_public("/pubapi/v2/orders/open/", request_data) + + def completedorders(self, cointype): + """ + Completed Orders By Coin + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **buyorders** - list of top 100 completed AUD buy orders for the given coin + - **sellorders** - list of top 100 completed AUD sell orders for the given coin + + """ + request_data = {"cointype":cointype} + return self._request_public("/pubapi/v2/orders/completed/", request_data) + + def completedmarketorders(self, cointype, markettype): + """ + Completed Orders By Coin / Market + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :param markettype: + coin market, example values 'USDT' (note: only for available markets) + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **buyorders** - list of top 100 completed buy orders for the given coin / market + - **sellorders** - list of top 100 completed sell orders for the given coin / market + + """ + request_data = {"cointype":cointype, "markettype":markettype} + return self._request_public("/pubapi/v2/orders/completed/", request_data) + + def statuscheck(self): + """ + Full Access Status Check + + :return: + - **status** - ok + + """ + request_data = {} + return self._request("/api/v2/status/", request_data) + + def depositaddress(self, cointype): + """ + My Coin Deposit Address + + :param cointype: + short name, example value 'BTC', 'LTC', 'DOGE' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **networks** - list of available networks (fields below) + + """ + request_data = {"cointype":cointype} + return self._request("/api/v2/my/coin/deposit/", request_data) + + def buynowquote(self, cointype, amount, amounttype): + """ + Buy Now Quote + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :param amount: + amount to buy + :param amounttype: + 'coin' or 'aud' - whether the amount above is coin amount or AUD amount + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **rate** - rate per specified coin + + """ + request_data = {"cointype":cointype, "amount":amount, "amounttype":amounttype} + return self._request("/api/v2/quote/buy/now/", request_data) + + def sellnowquote(self, cointype, amount, amounttype): + """ + Sell Now Quote + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :param amount: + amount of coins to sell + :param amounttype: + 'coin' or 'aud' - whether the amount below is coin amount or AUD amount + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **rate** - rate per specified coin inclusive of fee + + """ + request_data = {"cointype":cointype, "amount":amount, "amounttype":amounttype} + return self._request("/api/v2/quote/sell/now/", request_data) + + def swapnowquote(self, cointypesell, cointypebuy, amount): + """ + Swap Now Quote + + :param cointypesell: + coin short name you would like to swap, example value 'BTC', 'LTC', 'DOGE' + :param cointypebuy: + coin short name you wuld like to swap it for, example value 'BTC', 'LTC', 'DOGE' + :param amount: + amount of coins to swap + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **rate** - rate per coin swapped exclusive of fee + + """ + request_data = {"cointypesell":cointypesell, "cointypebuy":cointypebuy, "amount":amount} + return self._request("/api/v2/quote/swap/now/", request_data) + + def buymarket(self, cointype, amount, rate, markettype): + """ + Place Markey Buy Order + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :param amount: + mount of coins you want to buy, max precision 8 decimal places + :param rate: + rate in market currency (e.g. AUD or USDT) you are willing to pay, max precision 8 decimal places + :param markettype: + (optional, available markets only, default 'AUD') market coin short name to use to buy the coin, example value 'USDT' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **coin** - coin short name, example value 'BTC', 'LTC', 'DOGE' + - **market** - market used to place buy order for the coin + - **amount** - coin amount that was placed + - **rate** - rate that order was placed at + - **id** - id of buy order created which can be used to cancel the order if desired + + """ + request_data = {"cointype":cointype, "amount":amount, "rate":rate, "markettype":markettype} + return self._request("/api/v2/my/buy/", request_data) + + def buynow(self, cointype, amounttype, amount): + """ + Place Buy Now Order + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :param amounttype: + 'coin' or 'aud' - whether the amount below is coin amount or AUD amount + :param amount: + amount to buy, max precision for coin is 8 decimal places and 2 decimal places for AUD + :param rate: + (optional) rate in AUD received from using Buy Now Quote or otherwise + :param threshold: + (optional) 0 to 1000 - buy request will terminate if not within percentage threshold for current rate to vary from submitted rate, max precision for percentage is 8 decimal places + :param direction: + (optional) UP, DOWN, or BOTH (default is UP) - direction the price has moved for the percentage threshold to apply + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **coin** - coin short name, example value 'BTC', 'LTC', 'DOGE' + - **market** - market used to place buy order for the coin + - **amount** - amount that was bought + - **total** - total amount in market currency + + """ + request_data = {"cointype":cointype, "amounttype":amounttype, "amount":amount} + return self._request("/api/v2/my/buy/now/", request_data) + + def sellmarket(self, cointype, amount, rate, markettype): + """ + Place Market Sell Order + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :param amount: + amount of coins you want to sell, max precision 8 decimal places + :param rate: + rate in AUD you are willing to sell for, max precision 8 decimal places + :param markettype: + (optional, available markets only, default 'AUD') market coin short name to use to sell the coin into, example value 'USDT' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **coin** - coin short name + - **market** - market used to place sell order for the coin + - **amount** - coin amount that was placed in order + - **rate** - rate that order was placed at + - **id** - id of sell order created which can be used to cancel the order if desired + + """ + request_data = {"cointype":cointype, "amount":amount, "rate":rate, "markettype":markettype} + return self._request("/api/v2/my/sell/", request_data) + + def sellnow(self, cointype, amounttype, amount): + """ + Place Sell Now Order + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :param amounttype: + 'coin' or 'aud' - whether the amount below is coin amount or AUD amount + :param amount: + amount of coins you want to sell, max precision 8 decimal places + :param rate: + (optional) rate in AUD received from using Sell Now Quote or otherwise + :param threshold: + (optional) 0 to 1000 - sell request will terminate if not within percentage threshold for current rate to vary from submitted rate, max precision for percentage is 8 decimal places + :param direction: + (optional) UP, DOWN, or BOTH (default is DOWN) - direction the price has moved for the percentage threshold to apply + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **coin** - coin short name, example value 'BTC', 'LTC', 'DOGE' + - **market** - market used to place sell order for the coin + - **amount** - amount that was sold + - **rate** - rate that order was placed at + - **total** - total amount in market currency + + """ + request_data = {"cointype":cointype, "amounttype":amounttype, "amount":amount} + return self._request("/api/v2/my/sell/now/", request_data) + + def swapnow(self, cointypesell, cointypebuy, amount): + """ + Place Swap Now Order + + :param cointypesell: + coin short name you would like to swap, example value 'BTC', 'LTC', 'DOGE' + :param cointypebuy: + coin short name you wuld like to swap it for, example value 'BTC', 'LTC', 'DOGE' + :param amount: + amount of (cointypesell) to swap, max precision for coin is 8 decimal places + :param rate: + (optional) rate received from using Swap Now Quote or otherwise + :param threshold: + (optional) 0 to 1000 - Swap request will terminate if not within percentage threshold for current rate to vary from submitted rate, max precision for percentage is 8 decimal places + :param direction: + (optional) UP, DOWN, or BOTH (default is DOWN) - direction the price has moved for the percentage threshold to apply + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **coin** - coin short name, example value 'BTC', 'LTC', 'DOGE' + - **market** - coin swapped and and coin it was swapped for + - **amount** - coin amount that was swapped + - **rate** - rate that order was placed at + - **total** - total amount in swapped coin currency + + """ + request_data = {"cointypesell":cointypesell, "cointypebuy":cointypebuy, "amount":amount} + return self._request("/api/v2/my/swap/now/", request_data) + + def cancelbuy(self, id): + """ + Cancel My Buy Order + + :param id: + id of the buy order to cancel + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + + """ + request_data = {"id":id} + return self._request("/api/v2/my/buy/cancel/", request_data) + + def cancelsell(self, id): + """ + Cancel My Sell Order + + :param id: + id of the sell order to cancel + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + + """ + request_data = {"id":id} + return self._request("/api/v2/my/sell/cancel/", request_data) + + def withdrawdetails(self, cointype): + """ + Get Coin Withdrawal Details + + + :param cointype: + coin short name you would like to withdraw, example value 'BTC', 'LTC', 'DOGE' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **networks** - list of available send networks + + """ + request_data = {"cointype":cointype} + return self._request("/api/v2/my/coin/withdraw/senddetails/", request_data) + + def withdraw(self, cointype, amount, address): + """ + Coin Withdrawal + + :param cointype: + coin short name you would like to withdraw, example values 'BTC', 'LTC', 'DOGE' + :param amount: + the amount (in coin currency) of coin you would like to withdraw + :param address: + the destination address for the coin amount' + :param emailconfirm: + (optional, default is 'NO') if 'YES' an email confirmation will be sent and withdraw will not complete until confirmation link within email is clicked, values: 'YES', 'NO' + :param network: + (optional) - network you would like to send using e.g. 'BNB', 'ETH' - omit for 'default' network + :param paymentid: + (optional) - the appropriate payment id/memo for the withdrawal where permitted + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + + """ + request_data = {"cointype": cointype, "amount": amount, "address": address} + return self._request("/api/v2/my/coin/withdraw/send/", request_data) + + def rostatuscheck(self): + """ + Read Only Status Check + + :return: + - **status** - ok + + """ + request_data = {} + return self._request("/api/v2/ro/status/", request_data) + + def marketorders(self, cointype, markettype): + """ + Open Market Orders + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :param markettype: + (optional, available markets only)) market coin short name, example values 'AUD', 'USDT' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **buyorders** - list of top 20 open buy order rates for the given coin + - **sellorders** - list of top 20 open sell orders rates for the given coin + + """ + request_data = {"cointype":cointype, "markettype":markettype} + return self._request("/api/v2/ro/orders/market/open/", request_data) + + def completedmarket(self, cointype, markettype, startdate, enddate, limit): + """ + Completed Market Orders + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :param markettype: + (optional, available markets only)) market coin short name, example values 'AUD', 'USDT' + :param startdate: + (optional, note: date is UTC date or UNIX EPOCH time) format 'YYYY-MM-DD' or e.g. 1614824116 + :param enddate: + (optional, note: date is UTC date or UNIX EPOCH time) format 'YYYY-MM-DD' or e.g. 1614824116 + :param limit: + (optional, default is 200 records, max is 500 records) + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **buyorders** - list of top 100 completed buy orders for the given coin + - **sellorders** - list of top 100 completed sell orders for the given coin + + """ + request_data = {"cointype":cointype, "markettype":markettype, "startdate":startdate, "enddate":enddate, "limit":limit} + return self._request("/api/v2/ro/orders/market/completed/", request_data) + + def my_balances(self): + """ + My Coin Balances + + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **balances** - array containing one object for each coin with your balance, AUD value and rate for that coin + + """ + request_data = {} + return self._request("/api/v2/ro/my/balances/", request_data) + + def my_coinbalance(self, cointype): + """ + My Coin Balance + + :param cointype: + coin short name, example value 'BTC', 'LTC', 'DOGE' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **balance** - object containing one property with your balance, AUD value and rate for that coin + + """ + request_data = {"cointype":cointype} + return self._request("/api/v2/ro/my/balance/", request_data) + + def my_marketorders(self, cointype, markettype): + """ + My Open Market Orders + + :param cointype: + (optional) coin short name, example value 'BTC', 'LTC', 'DOGE' + :param markettype: + (optional) market coin short name, example value 'USDT', 'AUD' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **buyorders** - array containing your open buy orders + - **sellorders** - array containing your open sell orders + + """ + request_data = {"cointype":cointype, "markettype":markettype} + return self._request("/api/v2/ro/my/orders/market/open/", request_data) + + def my_limitorders(self, cointype): + """ + My Open Limit Orders + + :param cointype: + (optional) coin short name, example value 'BTC', 'LTC', 'DOGE' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **buyorders** - array containing your open buy orders + - **sellorders** - array containing your open sell orders + + """ + request_data = {"cointype":cointype} + return self._request("/api/v2/ro/my/orders/limit/open/", request_data) + + def my_orderhistory(self, cointype, markettype, startdate, enddate, limit): + """ + My Order History + + :param cointype: + (optional) coin short name, example value 'BTC', 'LTC', 'DOGE' + :param markettype: + (optional, available markets only)) market coin short name, example values 'AUD', 'USDT' + :param startdate: + (optional, note: date is UTC date or UNIX EPOCH time) format 'YYYY-MM-DD' or e.g. 1614824116 + :param enddate: + (optional, note: date is UTC date or UNIX EPOCH time) format 'YYYY-MM-DD' or e.g. 1614824116 + :param limit: + (optional, default is 200 records, max is 500 records) + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **buyorders** - array containing your buy order history + - **sellorders** - array containing your sell order history + + """ + request_data = {"cointype":cointype, "markettype":markettype, "startdate":startdate, "enddate":enddate, "limit":limit} + return self._request("/api/v2/ro/my/orders/completed/", request_data) + + def my_markethistory(self, cointype, markettype, startdate, enddate, limit): + """ + My Market Order History + + :param cointype: + (optional) coin short name, example value 'BTC', 'LTC', 'DOGE' + :param markettype: + (optional, available markets only)) market coin short name, example values 'AUD', 'USDT' + :param startdate: + (optional, note: date is UTC date or UNIX EPOCH time) format 'YYYY-MM-DD' or e.g. 1614824116 + :param enddate: + ((optional, note: date is UTC date or UNIX EPOCH time) format 'YYYY-MM-DD' or e.g. 1614824116 + :param limit: + (optional, default is 200 records, max is 500 records) + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **buyorders** - array containing your buy order history + - **sellorders** - array containing your sell order history + + """ + request_data = {"cointype":cointype, "markettype":markettype, "startdate":startdate, "enddate":enddate, "limit":limit} + return self._request("/api/v2/ro/my/orders/market/completed/", request_data) + + def my_transferhistory(self, startdate, enddate): + """ + My Send & Receive History + + :param startdate: + (optional) format 'YYYY-MM-DD' + :param enddate: + (optional) format 'YYYY-MM-DD' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **sendtransactions** - array containing your coin send transaction history + - **receivetransactions** - array containing your coin receive transaction history + + """ + request_data = {"startdate":startdate, "enddate":enddate} + return self._request("/api/v2/ro/my/sendreceive/", request_data) + + def my_deposithistory(self, startdate, enddate): + """ + My Deposit History + + :param startdate: + (optional) format 'YYYY-MM-DD' + :param enddate: + (optional) format 'YYYY-MM-DD' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **deposits** - array containing your AUD deposit history + + """ + request_data = {"startdate":startdate, "enddate":enddate} + return self._request("/api/v2/ro/my/deposits/", request_data) + + def my_withdrawhistory(self, startdate, enddate): + """ + My Withdrawal History + + :param startdate: + (optional) format 'YYYY-MM-DD' + :param enddate: + (optional) format 'YYYY-MM-DD' + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **withdrawals** - array containing your AUD withdrawal history + + """ + request_data = {"startdate":startdate, "enddate":enddate} + return self._request("/api/v2/ro/my/withdrawals/", request_data) + + def my_affiliatepayments(self): + """ + My Affiliate Payments + + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **payments** - array containing one object for each completed affiliate payment + + """ + request_data = {} + return self._request("/api/v2/ro/my/affiliatepayments/", request_data) + + def my_referralpayment(self): + """ + My Referral Payments + + :return: + - **status** - ok, error + - **message** - ok, description of error if error occurred + - **payments** - array containing one object for each completed referral payment + + """ + request_data = {} + return self._request("/api/v2/ro/my/referralpayments/", request_data) \ No newline at end of file From 13c99a2bbfb09634a61a51c3dc61b2d1316ab419 Mon Sep 17 00:00:00 2001 From: "romeo.delta" Date: Tue, 4 Jan 2022 14:51:22 +1000 Subject: [PATCH 3/8] remove old _request method --- coinspot/coinspot.py | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/coinspot/coinspot.py b/coinspot/coinspot.py index c9cee8a..a8c2c69 100644 --- a/coinspot/coinspot.py +++ b/coinspot/coinspot.py @@ -122,49 +122,7 @@ def _get_signed_request(self, data): hashlib.sha512, ).hexdigest() - def _request(self, path, postdata): - nonce = int(time() * 1000000) - postdata["nonce"] = nonce - params = json.dumps(postdata, separators=(",", ":")) - signedMessage = self._get_signed_request(params) - headers = {} - headers["Content-type"] = "application/json" - headers["Accept"] = "text/plain" - headers["key"] = self._api_key - headers["sign"] = signedMessage - headers["User-Agent"] = ( - "py-coinspot-api/%s (https://github.com/geekpete/py-coinspot-api)" - % __version__ - ) - if self._debug: - logging.warning(self.timestamp + " " + str(headers)) - conn = http.client.HTTPSConnection(self._endpoint) - if self._debug: - conn.set_debuglevel(1) - response_data = '{"status":"invalid","error": "Did not make request"}' - try: - conn.request("POST", path, params, headers) - response = conn.getresponse() - if self._debug: - logging.warning(self.timestamp + " " + str(response)) - logging.warning(self.timestamp + " " + str(response.msg)) - # print response.status, response.reason - response_data = response.read() - if self._debug: - logging.warning(self.timestamp + " " + str(response_data)) - conn.close() - except IOError as error: - if self._debug: - error_text = "Attempting to make request I/O error({0}): {1}".format( - error.errno, error.strerror - ) - logging.warning(self.timestamp + " " + error_text) - response_data = '{"status":"invalid","error": "' + error_text + '"}' - except: - exit("Unexpected error: {0}".format(sys.exc_info()[0])) - - return response_data - + def latestprices(self): """ Latest Prices From 8042779cfe821dde1a069f36710d10fad57e963f Mon Sep 17 00:00:00 2001 From: "romeo.delta" Date: Tue, 4 Jan 2022 14:52:32 +1000 Subject: [PATCH 4/8] add _request and _request_public functions add usage of the python requests library --- coinspot/coinspot.py | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/coinspot/coinspot.py b/coinspot/coinspot.py index a8c2c69..e796ed2 100644 --- a/coinspot/coinspot.py +++ b/coinspot/coinspot.py @@ -122,7 +122,46 @@ def _get_signed_request(self, data): hashlib.sha512, ).hexdigest() - + def _request_public(self, path, postdata): + """ + The public API uses a GET method, while the Private API uses a POST method. + _request_public - is for the public API, requires no nonce, key or hash or data. + """ + + # Create base URL + path = self._endpoint + path + + # Add each parameter into the URL + for parameter in postdata: + path = path + postdata[parameter] + "/" + + # Request + response_data = requests.get(path) + return response_data + + def _request(self, path, postdata): + # Create URL + path = self._endpoint + path + + # Post data + nonce = int(time() * 1000000) + postdata["nonce"] = nonce + params = json.dumps(postdata, separators=(",", ":")) + signedMessage = self._get_signed_request(params) + + # Header + headers = {} + headers["Content-type"] = "application/json" + headers["Accept"] = "text/plain" + headers["key"] = self._api_key + headers["sign"] = signedMessage + + # Request + response_data = requests.post(path, data=params, headers=headers) + + return response_data + + def latestprices(self): """ Latest Prices From 4acc2ee6cd0346648b40b293184581bd5b02647a Mon Sep 17 00:00:00 2001 From: "romeo.delta" Date: Tue, 4 Jan 2022 14:57:15 +1000 Subject: [PATCH 5/8] change _endpoint URL from www to https://www --- coinspot/coinspot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coinspot/coinspot.py b/coinspot/coinspot.py index e796ed2..cd5f61b 100644 --- a/coinspot/coinspot.py +++ b/coinspot/coinspot.py @@ -48,7 +48,7 @@ class CoinSpot: _api_key = "" _api_secret = "" - _endpoint = "www.coinspot.com.au" + _endpoint = "https://www.coinspot.com.au" _logging = "coinspot.log" _debug = False From b12789057d94405e8bec4a3ea16cb04d18cc06ce Mon Sep 17 00:00:00 2001 From: "romeo.delta" Date: Thu, 6 Jan 2022 08:19:20 +1000 Subject: [PATCH 6/8] add optional parameters via **kwargs to API call functions --- coinspot/coinspot.py | 129 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 107 insertions(+), 22 deletions(-) diff --git a/coinspot/coinspot.py b/coinspot/coinspot.py index cd5f61b..6bbd7a0 100644 --- a/coinspot/coinspot.py +++ b/coinspot/coinspot.py @@ -158,7 +158,6 @@ def _request(self, path, postdata): # Request response_data = requests.post(path, data=params, headers=headers) - return response_data @@ -426,7 +425,7 @@ def swapnowquote(self, cointypesell, cointypebuy, amount): request_data = {"cointypesell":cointypesell, "cointypebuy":cointypebuy, "amount":amount} return self._request("/api/v2/quote/swap/now/", request_data) - def buymarket(self, cointype, amount, rate, markettype): + def buymarket(self, cointype, amount, rate, markettype="AUD", **kwargs): """ Place Markey Buy Order @@ -448,10 +447,17 @@ def buymarket(self, cointype, amount, rate, markettype): - **id** - id of buy order created which can be used to cancel the order if desired """ + # Required parameters request_data = {"cointype":cointype, "amount":amount, "rate":rate, "markettype":markettype} + + # Optional parameter + for key, value in kwargs.items(): + if key == "markettype": + request_data[key] = value + return self._request("/api/v2/my/buy/", request_data) - def buynow(self, cointype, amounttype, amount): + def buynow(self, cointype, amounttype, amount, **kwargs): """ Place Buy Now Order @@ -476,10 +482,17 @@ def buynow(self, cointype, amounttype, amount): - **total** - total amount in market currency """ + # Required parameter request_data = {"cointype":cointype, "amounttype":amounttype, "amount":amount} + + # Optional parameter + for key, value in kwargs.items(): + if key == "rate" or key == "threshold" or key == "direction": + request_data[key] = value + return self._request("/api/v2/my/buy/now/", request_data) - def sellmarket(self, cointype, amount, rate, markettype): + def sellmarket(self, cointype, amount, rate, **kwargs): """ Place Market Sell Order @@ -490,7 +503,7 @@ def sellmarket(self, cointype, amount, rate, markettype): :param rate: rate in AUD you are willing to sell for, max precision 8 decimal places :param markettype: - (optional, available markets only, default 'AUD') market coin short name to use to sell the coin into, example value 'USDT' + OPTIONAL use markettype='market', example: sellmarket('BTC', 10, 10, markettype='USDT') (optional, available markets only, default 'AUD') market coin short name to use to sell the coin into, example value 'USDT' :return: - **status** - ok, error - **message** - ok, description of error if error occurred @@ -501,10 +514,17 @@ def sellmarket(self, cointype, amount, rate, markettype): - **id** - id of sell order created which can be used to cancel the order if desired """ + # Required parameters request_data = {"cointype":cointype, "amount":amount, "rate":rate, "markettype":markettype} + + # Optional parameters + for key, value in kwargs.items(): + if key == "markettype": + request_data[key] = value + return self._request("/api/v2/my/sell/", request_data) - def sellnow(self, cointype, amounttype, amount): + def sellnow(self, cointype, amounttype, amount, **kwargs): """ Place Sell Now Order @@ -530,10 +550,17 @@ def sellnow(self, cointype, amounttype, amount): - **total** - total amount in market currency """ + # Required parameters request_data = {"cointype":cointype, "amounttype":amounttype, "amount":amount} + + # Optional parameters + for key, value in kwargs.items(): + if key == "rate" or key == "threshold" or key == "direction": + request_data[key] = value + return self._request("/api/v2/my/sell/now/", request_data) - def swapnow(self, cointypesell, cointypebuy, amount): + def swapnow(self, cointypesell, cointypebuy, amount, **kwargs): """ Place Swap Now Order @@ -559,7 +586,14 @@ def swapnow(self, cointypesell, cointypebuy, amount): - **total** - total amount in swapped coin currency """ + # Required parameters request_data = {"cointypesell":cointypesell, "cointypebuy":cointypebuy, "amount":amount} + + # Optional parameters + for key, value in kwargs.items(): + if key == "rate" or key == "threshold" or key == "direction": + request_data[key] = value + return self._request("/api/v2/my/swap/now/", request_data) def cancelbuy(self, id): @@ -606,7 +640,7 @@ def withdrawdetails(self, cointype): request_data = {"cointype":cointype} return self._request("/api/v2/my/coin/withdraw/senddetails/", request_data) - def withdraw(self, cointype, amount, address): + def withdraw(self, cointype, amount, address, **kwargs): """ Coin Withdrawal @@ -627,7 +661,14 @@ def withdraw(self, cointype, amount, address): - **message** - ok, description of error if error occurred """ + # Required parameters request_data = {"cointype": cointype, "amount": amount, "address": address} + + # Optional parameters + for key, value in kwargs.items(): + if key == "emailconfirm" or key == "network" or key == "paymentid": + request_data[key] = value + return self._request("/api/v2/my/coin/withdraw/send/", request_data) def rostatuscheck(self): @@ -641,7 +682,7 @@ def rostatuscheck(self): request_data = {} return self._request("/api/v2/ro/status/", request_data) - def marketorders(self, cointype, markettype): + def marketorders(self, cointype, markettype='AUD'): """ Open Market Orders @@ -656,10 +697,12 @@ def marketorders(self, cointype, markettype): - **sellorders** - list of top 20 open sell orders rates for the given coin """ + # Required parameter request_data = {"cointype":cointype, "markettype":markettype} + return self._request("/api/v2/ro/orders/market/open/", request_data) - def completedmarket(self, cointype, markettype, startdate, enddate, limit): + def completedmarket(self, cointype, markettype='AUD', **kwargs): """ Completed Market Orders @@ -680,7 +723,14 @@ def completedmarket(self, cointype, markettype, startdate, enddate, limit): - **sellorders** - list of top 100 completed sell orders for the given coin """ - request_data = {"cointype":cointype, "markettype":markettype, "startdate":startdate, "enddate":enddate, "limit":limit} + # Required parameter + request_data = {"cointype":cointype, "markettype":markettype} + + # Optional parameters + for key, value in kwargs.items(): + if key == "startdate" or key == "enddate" or key == "limit": + request_data[key] = value + return self._request("/api/v2/ro/orders/market/completed/", request_data) def my_balances(self): @@ -711,7 +761,7 @@ def my_coinbalance(self, cointype): request_data = {"cointype":cointype} return self._request("/api/v2/ro/my/balance/", request_data) - def my_marketorders(self, cointype, markettype): + def my_marketorders(self, cointype, markettype='AUD'): """ My Open Market Orders @@ -745,7 +795,7 @@ def my_limitorders(self, cointype): request_data = {"cointype":cointype} return self._request("/api/v2/ro/my/orders/limit/open/", request_data) - def my_orderhistory(self, cointype, markettype, startdate, enddate, limit): + def my_orderhistory(self, cointype, markettype='AUD', **kwargs): """ My Order History @@ -766,10 +816,17 @@ def my_orderhistory(self, cointype, markettype, startdate, enddate, limit): - **sellorders** - array containing your sell order history """ - request_data = {"cointype":cointype, "markettype":markettype, "startdate":startdate, "enddate":enddate, "limit":limit} + # Required Parameters + request_data = {"cointype":cointype, "markettype":markettype} + + # Optional parameters + for key, value in kwargs.items(): + if key == "startdate" or key == "enddate" or key == "limit": + request_data[key] = value + return self._request("/api/v2/ro/my/orders/completed/", request_data) - def my_markethistory(self, cointype, markettype, startdate, enddate, limit): + def my_markethistory(self, cointype, markettype="AUD", **kwargs): """ My Market Order History @@ -790,10 +847,17 @@ def my_markethistory(self, cointype, markettype, startdate, enddate, limit): - **sellorders** - array containing your sell order history """ - request_data = {"cointype":cointype, "markettype":markettype, "startdate":startdate, "enddate":enddate, "limit":limit} + # Required parameters + request_data = {"cointype":cointype, "markettype":markettype} + + # Optional parameters + for key, value in kwargs.items(): + if key == "startdate" or key == "enddate" or key == "limit": + request_data[key] = value + return self._request("/api/v2/ro/my/orders/market/completed/", request_data) - def my_transferhistory(self, startdate, enddate): + def my_transferhistory(self, **kwargs): """ My Send & Receive History @@ -808,10 +872,17 @@ def my_transferhistory(self, startdate, enddate): - **receivetransactions** - array containing your coin receive transaction history """ - request_data = {"startdate":startdate, "enddate":enddate} + # Required parameter + request_data = {} + + # Optional parameters + for key, value in kwargs.items(): + if key == "startdate" or key == "enddate": + request_data[key] = value + return self._request("/api/v2/ro/my/sendreceive/", request_data) - def my_deposithistory(self, startdate, enddate): + def my_deposithistory(self, **kwargs): """ My Deposit History @@ -825,10 +896,17 @@ def my_deposithistory(self, startdate, enddate): - **deposits** - array containing your AUD deposit history """ - request_data = {"startdate":startdate, "enddate":enddate} + # Required parameter + request_data = {} + + # Optional parameters + for key, value in kwargs.items(): + if key == "startdate" or key == "enddate": + request_data[key] = value + return self._request("/api/v2/ro/my/deposits/", request_data) - def my_withdrawhistory(self, startdate, enddate): + def my_withdrawhistory(self, **kwargs): """ My Withdrawal History @@ -842,7 +920,14 @@ def my_withdrawhistory(self, startdate, enddate): - **withdrawals** - array containing your AUD withdrawal history """ - request_data = {"startdate":startdate, "enddate":enddate} + # Required parameter + request_data = {} + + # Optional parameters + for key, value in kwargs.items(): + if key == "startdate" or key == "enddate": + request_data[key] = value + return self._request("/api/v2/ro/my/withdrawals/", request_data) def my_affiliatepayments(self): From 2cee2bd212ffaad33d9c6ba777990a5cc7b9798a Mon Sep 17 00:00:00 2001 From: "romeo.delta" Date: Thu, 6 Jan 2022 11:04:26 +1000 Subject: [PATCH 7/8] add comment that limit parameter must be int not string: --- coinspot/coinspot.py | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/coinspot/coinspot.py b/coinspot/coinspot.py index 6bbd7a0..f6adc54 100644 --- a/coinspot/coinspot.py +++ b/coinspot/coinspot.py @@ -114,7 +114,7 @@ def start_logging(self): ) def _get_signed_request(self, data): - print(self) + # print(self) # print(hmac.new(key.encode('utf-8'), data.encode('utf-8'), hashlib.sha512).hexdigest() return hmac.new( str((self._api_secret)).encode("utf-8"), @@ -761,7 +761,7 @@ def my_coinbalance(self, cointype): request_data = {"cointype":cointype} return self._request("/api/v2/ro/my/balance/", request_data) - def my_marketorders(self, cointype, markettype='AUD'): + def my_marketorders(self, **kwargs): """ My Open Market Orders @@ -776,10 +776,17 @@ def my_marketorders(self, cointype, markettype='AUD'): - **sellorders** - array containing your open sell orders """ - request_data = {"cointype":cointype, "markettype":markettype} + # Required Parameters + request_data = {} + + # Optional parameters + for key, value in kwargs.items(): + if key == "cointype" or key == "markettype": + request_data[key] = value + return self._request("/api/v2/ro/my/orders/market/open/", request_data) - def my_limitorders(self, cointype): + def my_limitorders(self, **kwargs): """ My Open Limit Orders @@ -792,10 +799,17 @@ def my_limitorders(self, cointype): - **sellorders** - array containing your open sell orders """ - request_data = {"cointype":cointype} + # Required Parameters + request_data = {} + + # Optional parameters + for key, value in kwargs.items(): + if key == "cointype": + request_data[key] = value + return self._request("/api/v2/ro/my/orders/limit/open/", request_data) - def my_orderhistory(self, cointype, markettype='AUD', **kwargs): + def my_orderhistory(self, **kwargs): """ My Order History @@ -808,7 +822,7 @@ def my_orderhistory(self, cointype, markettype='AUD', **kwargs): :param enddate: (optional, note: date is UTC date or UNIX EPOCH time) format 'YYYY-MM-DD' or e.g. 1614824116 :param limit: - (optional, default is 200 records, max is 500 records) + (optional, default is 200 records, max is 500 records). Must be in int format not string. :return: - **status** - ok, error - **message** - ok, description of error if error occurred @@ -817,16 +831,16 @@ def my_orderhistory(self, cointype, markettype='AUD', **kwargs): """ # Required Parameters - request_data = {"cointype":cointype, "markettype":markettype} + request_data = {} # Optional parameters for key, value in kwargs.items(): - if key == "startdate" or key == "enddate" or key == "limit": + if key == "cointype" or key == "markettype" or key == "startdate" or key == "enddate" or key == "limit": request_data[key] = value return self._request("/api/v2/ro/my/orders/completed/", request_data) - def my_markethistory(self, cointype, markettype="AUD", **kwargs): + def my_markethistory(self, **kwargs): """ My Market Order History @@ -848,11 +862,11 @@ def my_markethistory(self, cointype, markettype="AUD", **kwargs): """ # Required parameters - request_data = {"cointype":cointype, "markettype":markettype} + request_data = {} # Optional parameters for key, value in kwargs.items(): - if key == "startdate" or key == "enddate" or key == "limit": + if key == "cointype" or key == "markettype" or key == "startdate" or key == "enddate" or key == "limit": request_data[key] = value return self._request("/api/v2/ro/my/orders/market/completed/", request_data) From d711cf6bdf7ea2240c80e4020131005fff3e43e9 Mon Sep 17 00:00:00 2001 From: "romeo.delta" Date: Thu, 6 Jan 2022 11:08:35 +1000 Subject: [PATCH 8/8] minor changes to optional arguments --- coinspot/coinspot.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/coinspot/coinspot.py b/coinspot/coinspot.py index f6adc54..95a01f4 100644 --- a/coinspot/coinspot.py +++ b/coinspot/coinspot.py @@ -425,7 +425,7 @@ def swapnowquote(self, cointypesell, cointypebuy, amount): request_data = {"cointypesell":cointypesell, "cointypebuy":cointypebuy, "amount":amount} return self._request("/api/v2/quote/swap/now/", request_data) - def buymarket(self, cointype, amount, rate, markettype="AUD", **kwargs): + def buymarket(self, cointype, amount, rate, markettype="AUD"): """ Place Markey Buy Order @@ -450,11 +450,6 @@ def buymarket(self, cointype, amount, rate, markettype="AUD", **kwargs): # Required parameters request_data = {"cointype":cointype, "amount":amount, "rate":rate, "markettype":markettype} - # Optional parameter - for key, value in kwargs.items(): - if key == "markettype": - request_data[key] = value - return self._request("/api/v2/my/buy/", request_data) def buynow(self, cointype, amounttype, amount, **kwargs): @@ -515,7 +510,7 @@ def sellmarket(self, cointype, amount, rate, **kwargs): """ # Required parameters - request_data = {"cointype":cointype, "amount":amount, "rate":rate, "markettype":markettype} + request_data = {"cointype":cointype, "amount":amount, "rate":rate} # Optional parameters for key, value in kwargs.items(): @@ -702,7 +697,7 @@ def marketorders(self, cointype, markettype='AUD'): return self._request("/api/v2/ro/orders/market/open/", request_data) - def completedmarket(self, cointype, markettype='AUD', **kwargs): + def completedmarket(self, cointype, **kwargs): """ Completed Market Orders @@ -724,11 +719,11 @@ def completedmarket(self, cointype, markettype='AUD', **kwargs): """ # Required parameter - request_data = {"cointype":cointype, "markettype":markettype} + request_data = {"cointype":cointype} # Optional parameters for key, value in kwargs.items(): - if key == "startdate" or key == "enddate" or key == "limit": + if key == "markettype" or key == "startdate" or key == "enddate" or key == "limit": request_data[key] = value return self._request("/api/v2/ro/orders/market/completed/", request_data)