-
Notifications
You must be signed in to change notification settings - Fork 1
/
globalToolsTransactions.py
89 lines (76 loc) · 2.66 KB
/
globalToolsTransactions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from globals import *
def isFiat(queryAsset):
return queryAsset == BT_DOLLAR or queryAsset == USDC_ASSET
def appendTransactionEnvelopeToArrayWithSourceAccount(transactionsArray, sourceAccount):
transactionsArray.append(
TransactionBuilder(
source_account = sourceAccount,
network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE,
base_fee = fee,
)
)
def prepTxn(transaction, memo, signer):
transaction = (
transaction
.add_text_memo(memo)
.set_timeout(DEF_TXN_TIMEOUT)
.build()
)
transaction.sign(signer)
return transaction
def toFullAddress(street, streetExtra, city, state, postal, country):
uncheckedArr = [street, streetExtra, city, state, postal, country]
cleanArr = []
for items in uncheckedArr:
if(items):
cleanArr.append(items)
return ", ".join(cleanArr)
async def submitTxnAndWait1(transaction):
async with ServerAsync(
horizon_url = HORIZON_INST,
client = AiohttpClient()
) as server:
return await server.submit_transaction(transaction)
def submitTxnGuaranteed(transaction):
return redundant(transaction, 0)
def redundant(transaction, attempt):
if(attempt > MAX_SUBMISSION_ATTEMPTS):
return submitTxnStd(transaction)
response, success = submitTxnStd(transaction)
if(success):
return response
else:
return redundant(transaction, attempt + 1)
def submitTxnStd(transaction):
try:
return server.submit_transaction(transaction), 1
except (BadRequestError, BadResponseError) as err:
return f"Tx submission failed: {err}", 0
def adjustNumSharesForStockSplits(numShares, purchaseTimestamp, queryAsset):
splitsDict = {}
CIK = getCIKforIssuerOfAsset(queryAsset)
for currencies in getAllBTcompanies():
assetCode = getAssetCodeFromTomlLink(currencies["attestation_of_reserve"])
if(assetCode == queryAsset):
data = loadTomlData(currencies["attestation_of_reserve"])
splitData = data["CURRENCIES"][0]["splits"].split("|") # bad match
for splits in splitData:
date = pandas.to_datetime(f"{splits.split('effective ')[1]}T00:00:00Z")
splits = splits.split(" ")
num = Decimal(splits[0])
denom = Decimal(splits[2])
splitsDict[date] = num / denom
return splitsDict
for splitTimestamps, splitRatios in splitsDict.items():
if(purchaseTimestamp < splitTimestamps):
numShares = numShares * splitRatios
return numShares
def epochFromDay(day):
return int((day - unix_base).total_seconds())
def dayFromEpoch(epoch):
try:
return datetime.utcfromtimestamp(epoch)
except ValueError:
return "Epoch out of range"
def divide(numerator, denominator):
return Decimal(numerator) / Decimal(denominator)