Exemplo n.º 1
0
year = datetime.datetime.now().year
year = 2021
day_zero = datetime.datetime(year - 5, 1, 1, 0)
day_one = datetime.datetime(year, 1, 1, 0)
day_end = datetime.datetime(year + 1, 1, 1, 0)

start_time = day_one.timestamp()
end_time = day_end.timestamp()

cessions = []
cessions_raw = []

balances = {}
sleep = 4
trades_dict = {}
ledgers = functions.query_all_kraken("Ledgers", "ledger", user, day_zero,
                                     sleep).get("items")
for ledger in ledgers:
    trades_dict.setdefault(ledger.get("refid"), {})
    trade = trades_dict.get(ledger.get("refid"))
    trade["trades_id"] = ledger.get("refid")
    trade["time"] = ledger.get("time")
    if ledger.get("asset") == "ZEUR":
        trade["cost"] = abs(float(ledger.get("amount")))
        trade["fee"] = ledger["fee"]
        trade["pair"] = trade.get("pair", "") + "ZEUR"
        trade["type"] = "buy" if float(ledger.get("amount")) < 0 else "sell"
    else:
        trade["pair"] = ledger.get("asset") + trade.get("pair", "")
        trade["vol"] = abs(float(ledger.get("amount")))
trades = list(trades_dict.values())
Exemplo n.º 2
0
day_zero = datetime.datetime(year - 5, 1, 1, 0)
day_one = datetime.datetime(year, 1, 1, 0)
day_end = datetime.datetime(year + 1, 1, 1, 0)

start_time = day_one.timestamp()
end_time = day_end.timestamp()

user = "******"

cessions = []
cessions_raw = []

balances = {}
sleep = 4

trades = functions.query_all_kraken("TradesHistory", "trades", user, day_zero,
                                    sleep)
ledgers = functions.query_all_kraken("Ledgers", "ledger", user, day_zero,
                                     sleep)
translate = {
    "212": "Balance before selling",
    "213": "Value got from selling",
    "214": "Fees",
    "215": "Value net of fees",
    "216": "Soulte",
    "217": "Value net of soulte",
    "218": "Value net of soutle and fees",
    "219": "Sum of buys since last selling",
    "220": "Total cost of buys since start",
    "221": "Previous cessions included",
    "222": "Soultes included in buys",
    "223": "Cost of buys net",
Exemplo n.º 3
0
import json

import functions

user = "******"
user_alt = "thomas"

year = 2021
day_one = datetime.datetime(year, 1, 1, 0, tzinfo=datetime.timezone.utc)
day_end = datetime.datetime(year + 1, 1, 1, 0, tzinfo=datetime.timezone.utc)
try_adjust_when_no_data = True
sleep = 5
# my timestamps are gmt .. insert dates are utc

last_ledgers = functions.query_all_kraken("Ledgers", "ledger", user, day_one, 0, end_day=day_end, crawl_to=10,
                                          use_cache=False)

offsetmax = last_ledgers.get("meta").get("set_size") - 10

fisrt_ledgers = functions.query_all_kraken("Ledgers", "ledger", user, day_one, 0, end_day=day_end, offset=offsetmax,
                                           use_cache=False)

first_ledger_dt = datetime.datetime.utcfromtimestamp(fisrt_ledgers["items"][0].get("time")).isoformat()

best_date_doc = functions.search_tradebal("*-history_of_trade_balance-*",
                                          [{"match": {"user": user_alt}},
                                           {"range": {"insert_date": {"lte": first_ledger_dt}}},
                                           {"range": {"invested": {"lte": 30}}}])

print(first_ledger_dt)
print(best_date_doc.get("insert_date"))