summaryrefslogtreecommitdiffstats
path: root/trading.py
diff options
context:
space:
mode:
authorraylu <lurayl@gmail.com>2015-02-28 03:46:09 -0800
committerraylu <lurayl@gmail.com>2015-02-28 03:46:09 -0800
commit0cfb1e3dcf038de6062ea7290767a31c6d285271 (patch)
tree18e08c9599887298ec1b41b0cfc63503e0e4127a /trading.py
parent281b71a52302c6645fd0317d44754616ee21f0d1 (diff)
downloadeve-master.tar.xz
station trading scriptHEADmaster
Diffstat (limited to 'trading.py')
-rwxr-xr-xtrading.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/trading.py b/trading.py
new file mode 100755
index 0000000..778e9a0
--- /dev/null
+++ b/trading.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python3
+
+from xml.etree import ElementTree
+
+import oursql
+import requests
+
+conn = oursql.connect(db='eve', user='eve', passwd='eve')
+rs = requests.session()
+
+def get_systemid(name):
+ with conn as c:
+ c.execute('SELECT solarSystemID FROM mapSolarSystems WHERE solarSystemName LIKE ?',
+ (name,))
+ return c.fetchone()[0]
+
+def iter_items():
+ with conn as c:
+ # metaGroupID's:
+ # NULL or 1: Tech I
+ # 2: Tech II
+ # 3: storyline
+ # 4: faction
+ # 5: officer
+ # 6: deadspace
+ # 14: Tech III
+ c.execute('''
+ SELECT invTypes.typeID, typeName FROM invTypes
+ LEFT JOIN invMetaTypes ON invMetaTypes.typeID = invTypes.typeID
+ WHERE marketGroupID IS NOT NULL AND metaGroupID != 5
+ ''')
+ while True:
+ r = c.fetchone()
+ if r is None:
+ break
+ yield r
+
+def get_prices(typeid, systemid):
+ url = 'http://api.eve-central.com/api/marketstat?typeid=%d&usesystem=%d' % (typeid, systemid)
+ response = rs.get(url, stream=True)
+ xml = ElementTree.fromstring(response.text)
+ parent = xml.find('marketstat').find('type')
+
+ buy = parent.findall('buy')[0].find('max')
+ bid = float(buy.text)
+
+ sell = parent.find('sell').find('min')
+ ask = float(sell.text)
+
+ volume = parent.find('all').find('volume')
+ vol = int(volume.text)
+
+ return bid, ask, vol
+
+def main():
+ for system in ['amarr', 'rens', 'dodixie', 'hek']:
+ systemid = get_systemid(system)
+ with open(system, 'w') as f:
+ for typeid, name in iter_items():
+ bid, ask, vol = get_prices(typeid, systemid)
+ score = (ask - bid) * vol
+ f.write('%f\t%f\t%f\t%d\t%s\n' % (score, ask, bid, vol, name))
+
+if __name__ == '__main__':
+ main()