hello i have a programme write on python the programme have to download all the sell order and all the buy order make a comparaison of their price and send a result when it find a great benefit.
But it have a probleme because the sell order are compare of the referral price this one is not complete and the goal is to compare the buy and the sell order.
So i search someone for help me to finish the programm because i am not able to replace the referralitem by the buy order i know how to download it but the problem is about the refferral i give you the source code
try:
import urllib.request
import ast
import decimal
import requests
import json
import time
except Exception as error:
print(“ERROR: this {} module is messing”.format(error));
exit(1);
class Transformer(ast.NodeTransformer):
NAMES = set([‘Decimal’, ‘None’, ‘False’, ‘True’]);
NODE_TYPES = set([‘Expression’,‘Tuple’,‘Call’,‘Name’,‘Load’,‘Str’,‘Num’,‘List’,‘Dict’,]);
def visit_Name(self, node):
if not node.id in self.NAMES:
raise RuntimeError("Name access to {} is not allowed".format(node.id));
return self.generic_visit(node);
def generic_visit(self, node):
nodetype = type(node).__name__;
if nodetype not in self.NODE_TYPES:
raise RuntimeError("Invalid expression: {} not allowed".format(nodetype));
return ast.NodeTransformer.generic_visit(self, node);
def fromTXT_toSTRUCT(txtStream=""):
parserTree = ast.parse(txtStream, mode=‘eval’);
transformer = Transformer();
transformer.visit(parserTree);
clause = compile(parserTree, ‘’, ‘eval’);
return eval(clause, dict(Decimal=decimal.Decimal));
def get_url_content(urlLink=“https://www.google.com”):
url = urllib.request.urlopen(urlLink);
return url;
def compare(currPage,refItems,currItems):
print(“REGION NUMBER : %d” % currPage)
for i in range(len(currItems)):
for i2 in range(len(refItems)):
if currItems[i][“type_id”] == refItems[i2][“type_id”]:
ide = currItems[i][“type_id”]
try:
if (refItems[i2][“average_price”] - currItems[i][“price”]) > 10000000:
print("======================")
print(“REF_ITEM number %d :” % (ide))
for key in refItems[i2].keys():
if key != “type_id”:
print("\t%s : %s" % (key,refItems[i2][key]))
print("----------------------")
print(“COMPARED_ITEM number %d :” % (ide))
for key in currItems[i].keys():
if key != “type_id”:
print("\t%s : %s" % (key,currItems[i][key]))
print("----------------------")
print(“DIFF:”)
print("\t%d diff price" % (refItems[i2][“average_price”]-currItems[i][“price”]))
print("======================")
except KeyError:
print("======================")
print(“REF_ITEM number %d :” % (ide))
print("\t no ref price or price NULL")
print("======================")
time.sleep(3.5)
print("||||||||||||||||||||||||||||||||||||||||||||||")
print("[INFO] refItems contain %d items" % (len(refItems)))
print("[INFO] currItems contain %d items" % (len(currItems)))
print("||||||||||||||||||||||||||||||||||||||||||||||")
def load_market_id(identifier):
print (“Load market with id : %s” %str(identifier))
url = “https://esi.tech.ccp.is/v1/markets/%s/orders/?datasource=tranquility&order_type=sell” %identifier
data = []
page_id = 0
while True :
res = requests.get(url, params={‘page’: page_id}).json()
if not res : break
data.extend(res)
page_id += 1
return data
def load_all_market_id(identifier):
data = {}
values = load_market_id(identifier)
if values :
data[identifier] = values
return data
def main():
count = 0
try:
while True:
refUrl = get_url_content(“https://esi.tech.ccp.is/latest/markets/prices/?datasource=tranquility”);
refStructuredContent = fromTXT_toSTRUCT(refUrl.read());
refUrl.close()
for nRegion in range(10000003,10000023):
values = list(load_all_market_id(nRegion).values());
if len(values) > 0:
values = values[0]
compare(nRegion,refStructuredContent,values);
print("[INFO]: REFRESH number (%d) … " % count);
coutn += 1;
except KeyboardInterrupt:
print("[INFO] the program has been stopped…")
exit(0)
return 0;
main();