Skip to content

Commit b48758d

Browse files
committed
Initial commit
1 parent 6ae1635 commit b48758d

File tree

5 files changed

+120
-1
lines changed

5 files changed

+120
-1
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1-
# get_crypto_price
1+
# Get Crypto Price
2+
A library to getting crypto price.
3+
# Install
4+
```
5+
pip3 install get-crypto-price
6+
```
7+
# Using
8+
## In another script
9+
```python
10+
from get_crypto_price import get
11+
# get(source = "bitstamp", pair = "btcusdt")
12+
print(get())
13+
```
14+
## In command line
15+
```console
16+
-h, --help show this help message and exit
17+
-s SOURCE, --source SOURCE
18+
Source
19+
-p PAIR, --pair PAIR Pair
20+
```
21+
```console
22+
get_crypto_price
23+
```

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests==2.25.1

setup.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from setuptools import setup
2+
3+
4+
setup(name='get_crypto_price',
5+
version='0.1.0',
6+
description="""A library to getting crypto price.""",
7+
long_description="""
8+
# Get Crypto Price
9+
A library to getting crypto price.
10+
# Install
11+
```
12+
pip3 install get-crypto-price
13+
```
14+
# Using
15+
## In another script
16+
```python
17+
from get_crypto_price import get
18+
# get(source = "bitstamp", pair = "btcusdt")
19+
print(get())
20+
```
21+
## In command line
22+
```console
23+
-h, --help show this help message and exit
24+
-s SOURCE, --source SOURCE
25+
Source
26+
-p PAIR, --pair PAIR Pair
27+
```
28+
```console
29+
get_crypto_price
30+
```
31+
""",
32+
long_description_content_type='text/markdown',
33+
url='https://github.com/onuratakan/get_crypto_price',
34+
author='Onur Atakan ULUSOY',
35+
author_email='atadogan06@gmail.com',
36+
license='MIT',
37+
packages=["get_crypto_price"],
38+
package_dir={'':'src'},
39+
install_requires=[
40+
"requests==2.25.1"
41+
],
42+
entry_points = {
43+
'console_scripts': ['get_crypto_price=get_crypto_price.get_crypto_price:get'],
44+
},
45+
python_requires=">= 3",
46+
zip_safe=False)

src/get_crypto_price/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .get_crypto_price import get
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import requests
2+
import json
3+
import argparse
4+
5+
6+
sources = [
7+
"bitstamp"
8+
]
9+
10+
def get(source = "bitstamp", pair = "btcusdt"):
11+
12+
parser = argparse.ArgumentParser()
13+
parser.add_argument('-s', '--source', type=str, help='Source')
14+
parser.add_argument('-p', '--pair', type=str, help='Pair')
15+
16+
args = parser.parse_args()
17+
18+
if not args.source is None:
19+
source = args.source
20+
if not args.pair is None:
21+
pair = args.pair
22+
23+
24+
25+
if source in sources:
26+
URL = None
27+
28+
if source == "bitstamp":
29+
URL = f"https://www.bitstamp.net/api/v2/ticker/{pair}"
30+
31+
32+
if not URL is None:
33+
34+
try:
35+
r = requests.get(URL)
36+
priceFloat = float(json.loads(r.text)["last"])
37+
return priceFloat
38+
39+
except requests.ConnectionError:
40+
print("Error querying API")
41+
except json.decoder.JSONDecodeError:
42+
print("Error querying pair")
43+
44+
else:
45+
print("Availale sources: ")
46+
for each_source in sources:
47+
print(each_source)
48+
raise "Source is unavailable"
49+

0 commit comments

Comments
 (0)