it just look good

This commit is contained in:
2023-07-12 12:33:58 +02:00
parent 010d1b6d3c
commit 8d5ad7c62d
9 changed files with 61 additions and 16 deletions
+31 -1
View File
@@ -9,6 +9,10 @@ import uuid
import threading
software_start=int(time.time())
class Exchange():
"""
Basic Commodity exchange.
@@ -26,6 +30,9 @@ class Exchange():
self.order_account_map={}
self.orders={}
self.executed_trades=[]
self.trade_curser=0
self.account_business={}
self.order_trades_map={}
self.market_rate={}
self.best_ask={}
@@ -36,7 +43,11 @@ class Exchange():
#self.supply={}
self.traded_commoditys={}
self.lock=threading.Lock()
def register_account(self,account,business):
self.account_business[account]=business
def add_to_account(self,account_id,resource,amount):
"""
Adds resources to account escrow
@@ -320,6 +331,25 @@ class Exchange():
for item , value in self.market_rate.items():
if value!=None:
localStepDB[item]["market_rate"]=int(value)
#Trade
new_trades=self.executed_trades[self.trade_curser:]
self.trade_curser=len(self.executed_trades)-1
for t in new_trades:
if t.trade_side==1:
# will get logged twice so only log one side
#
account_id=self.order_account_map[t.order_id]
data={}
data["cxid"]=name
data["tstep"]=timepoint
data["episode"]=int(episode)
data["account"]=account_id
data["business"]=self.account_business[account_id]
data["order_id"]=t.order_id
data["instmt"]=t.instmt
data["price"]=int(t.trade_price)
data["qty"]=int(t.trade_qty)
log.EXTradeDataDetail.append(data)
if autolog:
for id,item in localStepDB.items():