-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcbpro-main-v1.4.py
99 lines (85 loc) · 4.28 KB
/
cbpro-main-v1.4.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
89
90
91
92
93
94
95
96
97
98
99
# CBP API trader v1.4
import cbpro
import time
import os
import MasterBot
import AuthenticationConstants
import CryptoAccount
from CryptoStates import CryptoCurrencyPercentageStates
import TransactionConstants
import sys
if __name__ == "__main__":
masterBot = MasterBot.MasterBot(accountKey=AuthenticationConstants.KEY,
accountB64secret=AuthenticationConstants.B64SECRET,
accountPassphrase=AuthenticationConstants.PASS_PHRASE,
usdAccountID=AuthenticationConstants.USD_ACCOUNT_ID,
operatingPath=".",
recordingLogFilename="record.txt",
exceptionsLogFilename="exceptions.txt",
transactionsLogFoldername="transactions",
cryptoBackupFoldername="crypto_records_backup",
cryptoSettingsFolderName="crypto_settings")
activeCryptoIDs = masterBot.GetCryptoIDs()
UpdateRecordingFile = True
counter = 0
# Before main loop evaluate and query all of the crypto accounts
# this is to get their price and calculate their total portfolio percentages
# before the main loop begins
for cryptoID in activeCryptoIDs:
masterBot.UpdateUSDAccountAndAccountHoldings()
masterBot.UpdateCryptoAccount(cryptoID)
masterBot.UpdateTotalHoldingsInUSDFromAllAccounts()
masterBot.UpdatePortfolioPercentagesOfAllAccounts()
while True:
for cryptoID in activeCryptoIDs:
masterBot.UpdateUSDAccountAndAccountHoldings()
masterBot.UpdateCryptoAccount(cryptoID)
masterBot.UpdateTotalHoldingsInUSDFromAllAccounts()
masterBot.UpdatePortfolioPercentagesOfAllAccounts()
if masterBot.ShouldRenewPriceForCryptoAccount(cryptoID):
masterBot.RenewPricesForCryptoAccount(cryptoID)
masterBot.SetRenewPriceFlagForCryptoAccount(cryptoID, False)
# Do some evaluation before determining buying or selling
masterBot.RunPercentageCalculationOfCryptoAccount(cryptoID)
masterBot.EvaluateAndAdjustBuyOrders(cryptoID)
if masterBot.IsCryptoDown(cryptoID):
if masterBot.ShouldBuy(cryptoID):
amountToBuyInUSD = masterBot.GetAmountToBuyInUSD(cryptoID)
amountToBuyInCoin = masterBot.GetAmountToBuyInCoin(cryptoID, amountToBuyInUSD)
if amountToBuyInCoin != 0.0:
masterBot.BuyIn(cryptoID, amountToBuyInCoin)
masterBot.WriteBuyTransactionToLogFile(cryptoID, amountToBuyInCoin)
masterBot.SetRenewPriceFlagForCryptoAccount(cryptoID, True)
UpdateRecordingFile = True
elif masterBot.ShouldAdjustFallingReferencePrice(cryptoID):
masterBot.AdjustFallingReferencePrice(cryptoID)
# If crypto is up check if we should readjust the price
if masterBot.IsCryptoUp(cryptoID):
if masterBot.ShouldAdjustIncreasingReferencePrice(cryptoID):
masterBot.AdjustIncreasingReferencePrice(cryptoID)
elif masterBot.IsGoingBackDown(cryptoID):
masterBot.SetCryptoNeutral(cryptoID)
# Check the active buy orders and see if we should sell
if masterBot.ShouldSell(cryptoID):
ordersToSell = masterBot.GetOrdersToSell(cryptoID)
masterBot.SellOut(cryptoID, ordersToSell)
for orderToSell in ordersToSell:
amountToSellInCoin = orderToSell[0]
masterBot.WriteSellTransactionToLogFile(cryptoID, amountToSellInCoin)
masterBot.SetRenewPriceFlagForCryptoAccount(cryptoID, True)
UpdateRecordingFile = True
masterBot.ExportCryptoBackup(cryptoID)
# if it is time to log...
if counter >= 100 or UpdateRecordingFile:
# Update everything before we log
masterBot.UpdateUSDAccountAndAccountHoldings()
for cryptoID in activeCryptoIDs:
masterBot.UpdateCryptoAccount(cryptoID)
masterBot.UpdateTotalHoldingsInUSDFromAllAccounts()
masterBot.UpdatePortfolioPercentagesOfAllAccounts()
masterBot.LogCryptoDataToRecordingFile()
UpdateRecordingFile = False
counter = 0
else:
counter = counter + 1
time.sleep(1)