websocket WIP 3
This commit is contained in:
91
src/arbus.py
91
src/arbus.py
@ -1,78 +1,19 @@
|
||||
import json
|
||||
|
||||
import options
|
||||
from random import randint
|
||||
|
||||
async def getLevels(amount, highPrice, lowPrice, roundDecimals):
|
||||
# Returns array of prices from low to high for each level
|
||||
levels = []
|
||||
delta = (highPrice - lowPrice)/amount
|
||||
|
||||
levelPrice = lowPrice
|
||||
for i in range(amount - 1):
|
||||
levels.append(levelPrice)
|
||||
levelPrice = round(levelPrice + delta, 2)
|
||||
levels.append(highPrice)
|
||||
return levels
|
||||
|
||||
|
||||
async def parseParams(params):
|
||||
paramsList = params.split()
|
||||
paramsDict = {}
|
||||
for i in range(len(options.paramsLines)):
|
||||
paramsDict[options.paramsLines[i]] = paramsList[i]
|
||||
return paramsDict
|
||||
|
||||
async def toDictPairParams(pair: str, params):
|
||||
paramsList = params.split()
|
||||
|
||||
if len(paramsList) != len(options.paramsLines):
|
||||
return -1
|
||||
|
||||
paramsDict = {pair: {}}
|
||||
for i in range(len(options.paramsLines)):
|
||||
paramsDict[pair][options.paramsLines[i]] = paramsList[i]
|
||||
return paramsDict
|
||||
|
||||
async def checkPair(pair: str):
|
||||
currentData = {}
|
||||
try:
|
||||
with open('data.json', 'r') as f:
|
||||
currentData = json.load(f)
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
print('WARNING: JSON file is empty! Ignore if your installation is fresh.')
|
||||
|
||||
if pair in currentData:
|
||||
print(pair, ' exists in data file.')
|
||||
return 1
|
||||
else:
|
||||
print(pair, ' not found in data file.')
|
||||
return 0
|
||||
|
||||
async def deletePair(pair: str):
|
||||
currentData = {}
|
||||
try:
|
||||
with open('data.json', 'r') as f:
|
||||
currentData = json.load(f)
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
print('WARNING: JSON file is empty! Ignore if your installation is fresh.')
|
||||
|
||||
if pair in currentData:
|
||||
print(pair, ' exists in data file.')
|
||||
del currentData[pair]
|
||||
with open('data.json', 'w', encoding = 'utf-8') as f:
|
||||
json.dump(currentData, f, ensure_ascii = False, indent = 4)
|
||||
return 0
|
||||
else:
|
||||
print(pair, ' not found in data file.')
|
||||
return -1
|
||||
|
||||
async def mainWrapper(pair: str, params):
|
||||
newData = await toDictPairParams(pair, params)
|
||||
|
||||
if newData == -1:
|
||||
return -1
|
||||
|
||||
currentData = {}
|
||||
try:
|
||||
with open('data.json', 'r') as f:
|
||||
currentData = json.load(f)
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
print('WARNING: JSON file is empty! Ignore if your installation is fresh.')
|
||||
|
||||
if pair in currentData:
|
||||
print(pair, ' already exists.')
|
||||
return -2
|
||||
else:
|
||||
with open('data.json', 'w', encoding = 'utf-8') as f:
|
||||
currentData.update(newData)
|
||||
json.dump(currentData, f, ensure_ascii = False, indent = 4)
|
||||
print(pair, ' was added!')
|
||||
return 0
|
||||
def getArbus():
|
||||
# Returnes n arbus (n is random 1 byte positive number)
|
||||
return ("arbus"*randint(0, 255))
|
||||
|
||||
Reference in New Issue
Block a user