From 24ad9d845d893bc865051e6a1563850087dab47f Mon Sep 17 00:00:00 2001 From: andrewso <9V5f1FkzI2LD> Date: Fri, 26 Jun 2020 16:08:31 +0100 Subject: [PATCH] [26.06.20] Ask bid additions --- configuration/pipelines/build.groovy | 6 ++--- src/pricing/bitfinex.py | 7 +++-- src/pricing/collector.py | 27 +++++++++++++------ src/pricing/gemini.py | 5 +++- .../V1_INSERT_NEW_PRICE_RECORD_BTC.graphql | 2 +- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/configuration/pipelines/build.groovy b/configuration/pipelines/build.groovy index 47b1412..18587a0 100644 --- a/configuration/pipelines/build.groovy +++ b/configuration/pipelines/build.groovy @@ -41,7 +41,7 @@ try { )] ) { sh "doctl auth init --access-token ${DOCTL_TOKEN}" - sh "doctl kubernetes cluster kubeconfig save cryptosky-kubernetes-cluster-production" +// sh "doctl kubernetes cluster kubeconfig save cryptosky-kubernetes-cluster-production" } } @@ -87,8 +87,8 @@ try { } stage('Deploy') { - executeShellScript("configuration/scripts/deployToKubernetes.sh", - env.APPLICATION_NAME) +// executeShellScript("configuration/scripts/deployToKubernetes.sh", +// env.APPLICATION_NAME) } } } diff --git a/src/pricing/bitfinex.py b/src/pricing/bitfinex.py index 78d4ccd..954870b 100644 --- a/src/pricing/bitfinex.py +++ b/src/pricing/bitfinex.py @@ -9,7 +9,7 @@ def bitfinexPublicTicker(type, logger): response = requests.request("GET", uri) response = json.loads(response.text) - price = (float(response[0][1])+ float(response[0][3]) + float(response[0][7]))/3 + price = (float(response[0][7])+ float(response[0][9]) + float(response[0][10]))/3 price = round(price, 3) return price except KeyError as e: @@ -29,7 +29,10 @@ def bitfinexHighLowVol(type, logger): low = round(float(response[0][10]), 3) vol = round(float((response[0][8]))/24, 3) - return high, low, vol + ask = round(float(response[0][1]), 3) + bid = round(float(response[0][3]), 3) + + return high, low, vol, ask, bid except KeyError as e: logger.error("Bitfinex High Low Volume Error: {}".format(e)) return 0, 0, 0 \ No newline at end of file diff --git a/src/pricing/collector.py b/src/pricing/collector.py index 9f82945..e24cbd1 100644 --- a/src/pricing/collector.py +++ b/src/pricing/collector.py @@ -50,10 +50,11 @@ def averager(type): return averagePrice, timestamp def getHighLowVol(type): - bH, bL, bV = bitfinexHighLowVol(type, logger) - gH, gL, gV = geminiHighLowVol(type, logger) + bH, bL, bV, bA, bB = bitfinexHighLowVol(type, logger) + gH, gL, gV, gA, gB = geminiHighLowVol(type, logger) - if ( bH == 0 or bL == 0 or bV == 0 ) or ( gH == 0 or gL == 0 or gL == 0): + if ( bH == 0 or bL == 0 or bV == 0 or bA == 0, bB == 0 ) \ + or ( gH == 0 or gL == 0 or gL == 0 or gA == 0 or gB == 0): if bH == 0: high = gH elif gH == 0: @@ -66,14 +67,24 @@ def getHighLowVol(type): vol = gV elif gV == 0: vol = bV + if bA == 0: + ask = gA + elif gA == 0: + ask = bA + if bB == 0: + bid = gB + elif gB == 0: + bid = bB else: high = (bH + gH)/2 low = (bL + gL)/2 vol = (bV + gV)/2 + ask = (bA + gA)/2 + bid = (bB + gB)/2 - return high, low, vol + return high, low, vol, ask, bid -def sendToGateway(c_type, timestamp, av_price, high, low, vol, o_price, c_price): +def sendToGateway(c_type, timestamp, av_price, high, low, vol, ask, bid, o_price, c_price): with open(btc_usd, 'r') as file: data = file.read() @@ -81,7 +92,7 @@ def sendToGateway(c_type, timestamp, av_price, high, low, vol, o_price, c_price) timestamp = '"'+timestamp.strftime('%Y-%m-%dT%H:%M:%S')+'"' type = '"'+c_type+'"' - query = data % (timestamp, type, av_price, high, low, o_price, c_price, vol) + query = data % (timestamp, type, av_price, high, low, ask, bid, o_price, c_price, vol) logger.info("Query sending down to db-gateway -- ({})".format(query)) @@ -104,9 +115,9 @@ def collector(c_type): while True: av_price, timestamp = averager(c_type) - high, low, vol = getHighLowVol(c_type) + high, low, vol, ask, bid = getHighLowVol(c_type) o_price, c_price = getOpenClose(c_type) - sendToGateway(c_type, timestamp, av_price, high, low, vol, o_price, c_price) + sendToGateway(c_type, timestamp, av_price, high, low, vol, ask, bid, o_price, c_price) sleep(3596) \ No newline at end of file diff --git a/src/pricing/gemini.py b/src/pricing/gemini.py index bbbf889..91ebe12 100644 --- a/src/pricing/gemini.py +++ b/src/pricing/gemini.py @@ -28,12 +28,15 @@ def geminiHighLowVol(type, logger): high = float(response['high']) low = float(response['low']) + ask = float(response['ask']) + bid = float(response['bid']) + uri = "https://api.gemini.com/v1/pubticker/" + type.lower().replace('_', '') response = requests.request("GET", uri) response = json.loads(response.text) vol = float(response['volume']['BTC'])/24 - return high, low, vol + return high, low, vol, ask, bid except KeyError as e: logger.error("Gemini High Low Volume Error: {}".format(e)) return 0, 0, 0 diff --git a/src/resources/queries/V1_INSERT_NEW_PRICE_RECORD_BTC.graphql b/src/resources/queries/V1_INSERT_NEW_PRICE_RECORD_BTC.graphql index 7a47952..8f246fb 100644 --- a/src/resources/queries/V1_INSERT_NEW_PRICE_RECORD_BTC.graphql +++ b/src/resources/queries/V1_INSERT_NEW_PRICE_RECORD_BTC.graphql @@ -1 +1 @@ -mutation { createBtc(createdDate: %s, type: %s, average_price: %f, high_price: %f, low_price: %f, open_price: %f, close_price: %f, volume: %f){ id } } \ No newline at end of file +mutation { createBtc(createdDate: %s, type: %s, average_price: %f, high_price: %f, low_price: %f, ask_price: %f, bid_price: %f, open_price: %f, close_price: %f, volume: %f){ id } } \ No newline at end of file