Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L5 #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

L5 #160

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
Binary file added .DS_Store
Binary file not shown.
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

2 changes: 0 additions & 2 deletions README.md

This file was deleted.

6 changes: 0 additions & 6 deletions l1

This file was deleted.

2 changes: 0 additions & 2 deletions l2

This file was deleted.

10 changes: 0 additions & 10 deletions l3

This file was deleted.

21 changes: 0 additions & 21 deletions l4

This file was deleted.

143 changes: 143 additions & 0 deletions l5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import requests
import time
from operator import itemgetter
import json

market_names = ['bitstamp.net','cex.io','bitbay.net','bittrex.com']

#operation_name np. "ticker" albo "orderbook" - zwraca odpowiedni slownik otrzymany od API
def get_resources(operation_name, market_name, trade_pair):

url = ""

if market_name == 'bitbay.net':
url = 'https://bitbay.net/API/Public/' + trade_pair + '/' + operation_name + '.json'

if market_name == 'bittrex.com':
url = 'https://api.bittrex.com/api/v1.1/public/get' + operation_name + '?market=' + trade_pair[:3]+ '-' + trade_pair[3:]
if operation_name == "orderbook":
url = url + "&type=both"

if market_name == 'bitstamp.net':
url = 'https://www.bitstamp.net/api/v2/'
if operation_name == "orderbook":
url = url + "order_book"
else:
url = url + operation_name
url = url + '/' + trade_pair[:3].lower() + trade_pair[3:].lower() + '/'

if market_name == 'cex.io':
url = 'https://cex.io/api/'
if operation_name == "orderbook":
url = url + "order_book"
else:
url = url + operation_name
url = url + '/' + trade_pair[:3] + "/" + trade_pair[3:]

if url == "":
return {}

try:
recieved_dict = json.loads(str(requests.get(url).json()).replace('\'', '\"'))
except ValueError as e:
return {}
return recieved_dict

def last_price(market, trade_pair):
resource_dict = get_resource("ticker",market, trade_pair)
if 'last' not in resource_dict.keys():
return -1
return resource_dict['last']

def input_base_currency():
ret = input("Please specify base currency: ")
return ret

def input_wallet():
wallet = {}
print("Print pairs of currency and ammount, or print END to submit your wallet")
print("Example:")
print("BTC 0.12365")
line = input()
while line != "END":
words = line.split(" ")
currency = words[0]
ammount = float(words[1])
if currency not in wallet.keys():
wallet[currency] = ammount
else:
wallet[currency] += ammount
line = input()
return wallet

#zwraca wartosc waluty bazowej po przeliczeniu
def to_base_currency_trivial(wallet, market, base_currency ):
sum_ammount= 0.0
for key in wallet.keys():
if key == base_currency:
sum_ammount += float(wallet[key])
else:
price = last_price(market, key+base_currency)
if price == -1:
print("No market for " + key + ":" + base_currency + " found on " + market)
print("Currency not added to total ammount")
else:
sum_ammount += float(wallet[key]) * price
return sum_ammount


def bids_sorted(market, trade_pair):
resource_dict = get_resources("orderbook",market, trade_pair)
# print(str(resource_dict))
if 'bids' not in resource_dict:
return []
bids = resource_dict['bids']
# print(str(bids))
return sorted(bids,key=itemgetter(0),reverse=True)

def switch_market(market):
return market_names[(market_names.index(market)+1)%len(market_names)]

def to_base_currency(wallet, market, base_currency):
sum_ammount = 0.0
for key in wallet.keys():
if key == base_currency:
sum_ammount += wallet[key]
else:
currency_to_sell = float(wallet[key])
bids = bids_sorted(market, (key+base_currency))
#print(str(bids))
if bids == []:
for x in range(len(market_names)-1):
market = switch_market(market)
bids = bids_sorted(market, key+base_currency)
if bids != []:
break
if bids == []:
print("No market for " + key + ":" + base_currency + " found on any market known")
print("Currency not added to total ammount")
if bids != []:
while currency_to_sell > 0:
#print(str(bids))
next_offer = bids.pop(0)
print("Next offer: " + str(next_offer))
next_ammount = min(currency_to_sell, float(next_offer[1]))
currency_to_sell -= next_ammount
sum_ammount += next_ammount * float(next_offer[0])
return sum_ammount

#Dodatek
#Sprawdzanie automatyczne co 2 sekundy wartosci portfela
def to_base_currency_loop(wallet, market, base_currency):
time.sleep(2)
answer = to_base_currency(wallet,market, base_currency)
print("Total: " + str(answer))

def main():
wallet = input_wallet()
base_currency = input_base_currency()
answer = to_base_currency(wallet, market_names[0], base_currency)
print("Total of " + base_currency + " after calculation = " + str(answer))

main()
#to_base_currency
28 changes: 0 additions & 28 deletions searching_methods/src/algorithms/bubble.java

This file was deleted.

37 changes: 0 additions & 37 deletions searching_methods/src/algorithms/insert.java

This file was deleted.

44 changes: 0 additions & 44 deletions searching_methods/src/algorithms/quick.java

This file was deleted.

38 changes: 0 additions & 38 deletions searching_methods/src/algorithms/select.java

This file was deleted.

Loading