Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions ctapi/ctapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@
See https://cointracking.info/api/api.php
"""

try:
from urllib import urlencode
from urlparse import urljoin
except ImportError:
from urllib.parse import urlencode
from urllib.parse import urljoin

import time
import hashlib
import hmac
import logging
import hashlib
import time

import requests
import httpx

__author__ = "tehtbl"
__copyright__ = "(C) 2018 https://github.com/tehtbl"
Expand All @@ -26,9 +19,6 @@
logging.getLogger('urllib3.connectionpool').setLevel(logging.INFO)
logger = logging.getLogger(__name__)

# disable unsecure SSL warning
requests.packages.urllib3.disable_warnings()

URI_API = 'https://cointracking.info/api/v1/'


Expand Down Expand Up @@ -129,7 +119,7 @@ def _api_query(self, method, params={}):
for k in params.keys():
new_params[k] = (None, str(params[k]))

r = requests.post(URI_API, headers=hdrs, files=new_params, verify=False)
r = httpx.post(URI_API, headers=hdrs, files=new_params, verify=False)
ret_json = r.json()

return {
Expand Down
9 changes: 3 additions & 6 deletions ctapi/test/ctapi_tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import json
import yaml
import os
import unittest

from ctapi import CTAPI

try:
open("secrets.yml").close()
secrets = {"key": os.environ["key"], "secret": os.environ["secret"]}
IS_CI_ENV = False
except Exception:
IS_CI_ENV = True
Expand Down Expand Up @@ -34,9 +33,7 @@ class TestCTAPIBasicTests(unittest.TestCase):
"""

def setUp(self):
with open("secrets.yml") as f:
self.secrets = yaml.load(f)
f.close()
self.secrets = {"key": os.environ["key"], "secret": os.environ["secret"]}

# self.api = CTAPI(secrets['key'], secrets['secret'], debug=True)
self.api = CTAPI(self.secrets['key'], self.secrets['secret'])
Expand Down
27 changes: 12 additions & 15 deletions getMyBalances.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
import json
import yaml
import os

from ctapi import CTAPI

if __name__ == "__main__":

with open("secrets.yml") as f:
secrets = yaml.load(f)
f.close()
secrets = {"key": os.environ["key"], "secret": os.environ["secret"]}

# api = CTAPI(secrets['key'], secrets['secret'], debug=True)
api = CTAPI(secrets['key'], secrets['secret'])
balances = api.getBalance()

if balances['result']['success']:
sum = 0
print "+-------+------------+------------+------------+"
print "| SYM | amount | price_fiat | value_fiat |"
print "+-------+------------+------------+------------+"
print("+-------+------------+------------+------------+")
print("| SYM | amount | price_fiat | value_fiat |")
print("+-------+------------+------------+------------+")
for b in balances['result']['details']:
details = balances['result']['details'][b]
if float(details['value_fiat']) > 0.01:
sum = sum + float(details['value_fiat'])
print "| %5s | %10.2f | %10.2f | %10.2f |" % (b, float(details['amount']),
float(details['price_fiat']), float(details['value_fiat']) )
print("| %5s | %10.2f | %10.2f | %10.2f |" % (b, float(details['amount']),
float(details['price_fiat']), float(details['value_fiat']) ))

print "+-------+------------+------------+------------+"
print ""
print "Sum: %15.2f EUR" % (sum)
print "=" * 24
print("+-------+------------+------------+------------+")
print("")
print("Sum: %15.2f EUR" % (sum))
print("=" * 24)
else:
print "got no balances"
print("got no balances")
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
PyYAML==5.4.1
requests==2.25.1
httpx~=0.18.2