示例#1
0
def _binanceTickerOps():
    # DESCR:    get tickers (xCoin-To-Bitcoin-Rate) for binance mainstream coins, spit them to splunk, update gsheet
    # ARGS:     none
    # UPDATES:  gSheet ([InterMarketLoop] tab ONLY
    # RETURNS:  nothing
    #
    BINcoinList = [
        "ETH", "LTC", "ETC", "XRP"
    ]  #NOTE THERE IS NO BITCOIN (AS WE ARE COMPARING TO BITCOIN!)
    BINdict = _BINANCE._BINapiNoAuth_getTickr("GET",
                                              "/api/v1/ticker/allPrices",
                                              BINcoinList)
    _OUTPUT._spitJSONoutToSplunk(BINdict)
    BINxCoinToBitcoinRatelist = [
        [
            "N/A",
            BINdict['ETH-BTC']['lastPrice'],
            BINdict['LTC-BTC']['lastPrice'],
            BINdict['ETC-BTC']['lastPrice'],
            "N/A",
            BINdict['XRP-BTC']['lastPrice'],
        ],
    ]
    _GOOGLE._publishToGoogleSheet(BINxCoinToBitcoinRatelist, 'USER_ENTERED',
                                  '[InterMarketLoop]!G8', 'COLUMNS')
    return
示例#2
0
def _btcmTickerOps():
    #COINS TO AUD
    btcmTkDict = {"kCryptoDictType": 'BTCMticker'}
    btcmTkDict.update(
        {"BTC-DATA": _BTCMARKETS._BTCMapiNoAuth_getTickr("BTC", "AUD")})
    btcmTkDict.update(
        {"ETH-DATA": _BTCMARKETS._BTCMapiNoAuth_getTickr("ETH", "AUD")})
    btcmTkDict.update(
        {"LTC-DATA": _BTCMARKETS._BTCMapiNoAuth_getTickr("LTC", "AUD")})
    btcmTkDict.update(
        {"ETC-DATA": _BTCMARKETS._BTCMapiNoAuth_getTickr("ETC", "AUD")})
    btcmTkDict.update(
        {"BCHABC-DATA": _BTCMARKETS._BTCMapiNoAuth_getTickr("BCHABC", "AUD")})
    btcmTkDict.update(
        {"XRP-DATA": _BTCMARKETS._BTCMapiNoAuth_getTickr("XRP", "AUD")})
    _OUTPUT._spitJSONoutToSplunk(btcmTkDict)
    #UPDATE GSHEETS WITH ABOVE
    btcmTickList_AUD = [
        [
            btcmTkDict['BTC-DATA']['lastPrice'],
            btcmTkDict['ETH-DATA']['lastPrice'],
            btcmTkDict['LTC-DATA']['lastPrice'],
            btcmTkDict['ETC-DATA']['lastPrice'],
            btcmTkDict['BCHABC-DATA']['lastPrice'],
            btcmTkDict['XRP-DATA']['lastPrice'],
        ],
    ]
    _GOOGLE._publishToGoogleSheet(btcmTickList_AUD, 'USER_ENTERED',
                                  '[CryptoSum]!C8:C13', 'COLUMNS')

    return
示例#3
0
def _btcmAccountOps():
    balancesDict = _BTCMARKETS._BTCMapiAuth_getBal("GET", "/account/balance",
                                                   BTCMapiKeyPub_m,
                                                   BTCMapiKeyPri_m)
    _OUTPUT._spitJSONoutToSplunk(balancesDict)
    BTCMBalList = [
        [
            balancesDict['BTC-BAL']['balance'],
            balancesDict['ETH-BAL']['balance'],
            balancesDict['LTC-BAL']['balance'],
            balancesDict['ETC-BAL']['balance'],
            balancesDict['BCHABC-BAL']['balance'],
            balancesDict['XRP-BAL']['balance'],
            balancesDict['AUD-BAL']['balance'],
        ],
    ]
    BTCMPendList = [
        [
            balancesDict['BTC-BAL']['pending'],
            balancesDict['ETH-BAL']['pending'],
            balancesDict['LTC-BAL']['pending'],
            balancesDict['ETC-BAL']['pending'],
            balancesDict['BCHABC-BAL']['pending'],
            balancesDict['XRP-BAL']['pending'],
            balancesDict['AUD-BAL']['pending'],
        ],
    ]
    _GOOGLE._publishToGoogleSheet(BTCMBalList, 'USER_ENTERED',
                                  '[CryptoSum]!I8', 'COLUMNS')
    _GOOGLE._publishToGoogleSheet(BTCMPendList, 'USER_ENTERED',
                                  '[CryptoSum]!J8', 'COLUMNS')
    return
示例#4
0
def _marketDeltaOps():
    # DESCR:    read market delta % from gSheet, pass to parse fucntion (alerting done there), spit parsed delta to splunk
    # ARGS:     none
    # UPDATES:  splunk
    # RETURNS:  nothing
    #
    googleSheetBlock = _GOOGLE._readFromGoogleSheet('[InterMarketLoop]!P1:R13')
    deltaDictParsed = _exchLoopDeltaParseLogic(googleSheetBlock)
    _OUTPUT._spitJSONoutToSplunk(deltaDictParsed)
    return
示例#5
0
def _main():
    scriptStartTime = time.time()

    _btcmTickerOps()
    _binanceTickerOps()
    _marketDeltaOps()

    scriptRunTime = {
        "ScriptRunTime_MARKEYLOOPVIZ.py": time.time() - scriptStartTime
    }
    _OUTPUT._spitJSONoutToSplunk(scriptRunTime)
    _timestampGsheet()
示例#6
0
def _main():
    scriptStartTime = time.time()

    _btcmTickerOps()
    _arbKrakenEUR()
    _arbKrakenGBP()
    _forexRates()
    _timestampGsheet()
    _readDeltaSpitToSplunk()

    scriptRunTime = {"ScriptRunTime_ARBVIZ.py":  time.time() - scriptStartTime}
    _OUTPUT._spitJSONoutToSplunk(scriptRunTime)
示例#7
0
def _nanoPoolOps():
    nanoDict = {"NanoPool": _collectNANOPOOLdata()}
    nanoDict.update({"kCryptoDictType": 'nanopool'})
    _OUTPUT._spitJSONoutToSplunk(nanoDict)
    if nanoDict['NanoPool']['status']:
        nanoValues = [
            [
                nanoDict['NanoPool']['ETHminingBal'],
            ],
        ]
        _GOOGLE._publishToGoogleSheet(nanoValues, 'USER_ENTERED',
                                      '[CryptoSum]!C21', 'COLUMNS')
    return
示例#8
0
def _main():
    scriptStartTime = time.time()

    _btcmTickerOps()
    _btcmAccountOps()
    #    _binanceAccountOps()
    _portfolioOps()
    _thresholdOps()
    _NANOPOOL._nanoPoolOps()
    _timestampGsheet()

    #_OUTPUT_logToFile()
    scriptRunTime = {
        "ScriptRunTime_CRYPTOVIZ.py": time.time() - scriptStartTime
    }
    _OUTPUT._spitJSONoutToSplunk(scriptRunTime)
示例#9
0
def _readDeltaSpitToSplunk():
    googleSheetBlock    = _GOOGLE._readFromGoogleSheet('[arbFIAT]!F8:F13')
    deltaDict = {"kCryptoDictType": 'exchArbDeltas'}
    #SLOPPY CODE HERE (TO DO WITH THE FACT THE googleSheetBlock IS A LIST OF LISTS THAT NEED TO BE POP'd).... COME BACK AND FIXUP (MAKE A LOOP, ITERATING COINLIST) WHEN I HAVE TIME.....
    innerList = googleSheetBlock[0]
    deltaDict.update ( {"BTC": {"remoteExchange": "kracken", "currencyBase" : "EUR", "delta": float(innerList[0])} } )
    innerList = googleSheetBlock[1]
    deltaDict.update ( {"ETH": {"remoteExchange": "kracken", "currencyBase" : "EUR", "delta": float(innerList[0])} } )
    innerList = googleSheetBlock[2]
    deltaDict.update ( {"LTC": {"remoteExchange": "kracken", "currencyBase" : "EUR", "delta": float(innerList[0])} } )
    innerList = googleSheetBlock[3]
    deltaDict.update ( {"ETC": {"remoteExchange": "kracken", "currencyBase" : "EUR", "delta": float(innerList[0])} } )
    innerList = googleSheetBlock[4]
    deltaDict.update ( {"BCHABC": {"remoteExchange": "kracken", "currencyBase" : "EUR", "delta": float(innerList[0])} } )
    innerList = googleSheetBlock[5]
    deltaDict.update ( {"XRP": {"remoteExchange": "kracken", "currencyBase" : "EUR", "delta": float(innerList[0])} } )
    _OUTPUT._spitJSONoutToSplunk(deltaDict)
    return
示例#10
0
def _portfolioOps():
    # DESCR:    read in portfolio and summary values from gSheet (hardword has already been done there), so it can be spat to splunk for graphing
    # ARGS:     none
    # UPDATES:  splunk
    # RETURNS:  structure like below:
    #    {
    #        "KM-PORTFOLIO": {
    #            "AUDbtcmAUD": 20349.69,
    #            "BCHbinAUD": 0.0,
    #            "BCHbtcmAUD": 0.0,
    #            "BTCbinAUD": 843.83,
    #            "BTCbtcmAUD": 0.0,
    #            "ETCbinAUD": 0.1,
    #            "ETCbtcmAUD": 0.0,
    #            "ETHbinAUD": 0.0,
    #            "ETHbtcmAUD": 49909.26,
    #            "LTCbinAUD": 0.52,
    #            "LTCbtcmAUD": 0.0,
    #            "XRPbinAUD": 2.96,
    #            "XRPbtcmAUD": 0.0
    #        },
    #        "KM-PORTFOLIO-SUM": {
    #            "profitPercent": 68.7,
    #            "totalALL": 77590.47,
    #            "totalBINalt": 6484.1,
    #            "totalBINmain": 847.42,
    #            "totalBTCMmain": 70258.95,
    #            "totalCashIn": 46000.0,
    #            "totalProfit": 31590.47
    #        },
    #        "kCryptoDictType": "portfolio"
    #    }
    myPortfolioStartTime = time.time()

    #READ GSHEET RANGE CONTAINING MAINSTREAM COINS-----------------------------------
    gSheetBlockMainCoins = _GOOGLE._readFromGoogleSheet('[CryptoSum]!B8:Q14')

    #ITERATE THROUGH THE RANGE, EXTRACTING RELEVANT VALUES, PLACING THEM IN JSON DICTIONARY
    portValDictOuter = {"kCryptoDictType": 'portfolio'}
    portValDictOuter.update(
        {"zzPortfolioTime": time.time() - myPortfolioStartTime})
    portValDictInner = {}
    for row in gSheetBlockMainCoins:
        coin = row[0]
        btcmVal = float(row[9])
        portValDictInner.update({
            coin + "btcmAUD": btcmVal,
        })
        if coin != "AUD":  #DONT ATTEMPT TO FIND AUD IN BINANCE... ITS NOT THERE
            binVal = float(row[14])
            portValDictInner.update({
                coin + "binAUD": binVal,
            })
    portValDictOuter.update({
        "KM-PORTFOLIO": portValDictInner,
    })

    #READ GSHEET RANGE CONTAINING SUMMARY----------------------------------------------
    gSheetBlockSumList = _GOOGLE._readFromGoogleSheet('[CryptoSum]!K16:X20')

    #ITERATE THROUGH THE RANGE, EXTRACTING RELEVANT VALUES, PLACING THEM IN JSON DICTIONARY
    portSumDictInner = {}

    totalBTCMmain = float(gSheetBlockSumList[0][0])
    totalBINmain = float(gSheetBlockSumList[0][5])
    totalBINalt = float(gSheetBlockSumList[1][5])
    totalALL = float(gSheetBlockSumList[1][0])
    totalCashIn = float(gSheetBlockSumList[2][0])
    totalProfit = float(gSheetBlockSumList[3][0])
    profitPercent = float(gSheetBlockSumList[4][0])

    portSumDictInner.update({
        "totalBTCMmain": totalBTCMmain,
        "totalBINmain": totalBINmain,
        "totalBINalt": totalBINalt,
        "totalALL": totalALL,
        "totalCashIn": totalCashIn,
        "totalProfit": totalProfit,
        "profitPercent": profitPercent,
    })
    portValDictOuter.update({
        "KM-PORTFOLIO-SUM": portSumDictInner,
    })

    #SPIT THE PORTFOLIO VALUES TO SPLUNK
    _OUTPUT._spitJSONoutToSplunk(portValDictOuter)

    return
示例#11
0
def _binanceAccountOps():
    #GET MAINSTREAM COIN ACCOUNT/BALANCE DETAILS - MAINSTREAM COINS
    BINcoinList = ["BTC", "ETH", "LTC", "ETC", "XRP"]
    #    BINcoinList         = ["BTC"]
    BINacDict = _BINANCE._BINapiAuth_getAccount("GET", "/api/v3/account",
                                                BINapiKeyPub_m, BINapiKeyPri_m,
                                                BINcoinList)

    _OUTPUT._spitJSONoutToSplunk(BINacDict)
    BINaclist = [
        [
            BINacDict['BTC']['balance'],
            BINacDict['ETH']['balance'],
            BINacDict['LTC']['balance'],
            BINacDict['ETC']['balance'],
            "N/A",
            BINacDict['XRP']['balance'],
        ],
    ]
    BINpendlist = [
        [
            BINacDict['BTC']['pending'],
            BINacDict['ETH']['pending'],
            BINacDict['LTC']['pending'],
            BINacDict['ETC']['pending'],
            "N/A",
            BINacDict['XRP']['pending'],
        ],
    ]
    _GOOGLE._publishToGoogleSheet(BINaclist, 'USER_ENTERED', '[CryptoSum]!N8',
                                  'COLUMNS')
    _GOOGLE._publishToGoogleSheet(BINpendlist, 'USER_ENTERED',
                                  '[CryptoSum]!O8', 'COLUMNS')

    #GET ALT-COIN ACCOUNT/BALANCE DETAILS (these vary, hence allow to be driven by user input on the gsheet)
    #GET LIST OF COINS FIRST
    googleSheetBlock = _GOOGLE._readFromGoogleSheet('[CryptoSum]!S8:S21')
    myBINaltCoinList = _BINANCE._makeBINaltCoinsOfInterestList(
        googleSheetBlock)

    #NEXT GET BALANCES OF THOSE COINS
    BINaltAcDict = _BINANCE._BINapiAuth_getAccount("GET", "/api/v3/account",
                                                   BINapiKeyPub_m,
                                                   BINapiKeyPri_m,
                                                   myBINaltCoinList)

    _OUTPUT._spitJSONoutToSplunk(BINaltAcDict)
    BINaltBalList = []
    BINaltPenList = []
    for i in range(len(myBINaltCoinList)):
        BINaltBalList.append(BINaltAcDict[myBINaltCoinList[i]]['balance'])
        BINaltPenList.append(BINaltAcDict[myBINaltCoinList[i]]['pending'])

    gSheetListOfListsBal = [
        BINaltBalList,
    ]
    gSheetListOfListsPen = [
        BINaltPenList,
    ]
    _GOOGLE._publishToGoogleSheet(gSheetListOfListsBal, 'USER_ENTERED',
                                  '[CryptoSum]!T8', 'COLUMNS')
    _GOOGLE._publishToGoogleSheet(gSheetListOfListsPen, 'USER_ENTERED',
                                  '[CryptoSum]!U8', 'COLUMNS')

    #GET VALUES OF THOSE COINS AGAINST BITCOIN (BINANCE DOES NOT DO AUD)
    BINaltDict = _BINANCE._BINapiNoAuth_getTickr("GET",
                                                 "/api/v1/ticker/allPrices",
                                                 myBINaltCoinList)
    #    _OUTPUT._spitJSONoutToSplunk(BINaltDict)
    BINaltExRateList = []
    for i in range(len(myBINaltCoinList)):
        coinBTC = myBINaltCoinList[i] + "-BTC"
        BINaltExRateList.append(BINaltDict[coinBTC]['lastPrice'])

    gSheetListOfLists = [
        BINaltExRateList,
    ]
    _GOOGLE._publishToGoogleSheet(gSheetListOfLists, 'USER_ENTERED',
                                  '[CryptoSum]!V8', 'COLUMNS')

    return