moved things to a new place !
This commit is contained in:
49
market_trade/core/dealManager.py
Normal file
49
market_trade/core/dealManager.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import pandas as pd
|
||||
import datetime
|
||||
import numpy as np
|
||||
import uuid
|
||||
|
||||
class DealManager():
|
||||
|
||||
def __init__(self):
|
||||
#self.commission=0.04
|
||||
self.columns=['uuid','figi','amount','startPrice']
|
||||
self.deals = pd.DataFrame(columns=self.columns)
|
||||
self.deals = self.deals.set_index('uuid')
|
||||
|
||||
def findDealByPriceAndFig(self,price,figi):
|
||||
ans=None
|
||||
for i in range(self.deals.shape[0]):
|
||||
if self.deals.iloc[i].startPrice == price and self.deals.iloc[i].figi == figi:
|
||||
ans = self.deals.iloc[i].name
|
||||
break
|
||||
return ans
|
||||
|
||||
def openDeal(self,figi,startPrice,amount=1):
|
||||
desiredDeal=self.findDealByPriceAndFig(startPrice,figi)
|
||||
if desiredDeal == None:
|
||||
newDealDict={
|
||||
'uuid':[str(uuid.uuid4())],
|
||||
'figi':[figi],
|
||||
'startPrice':[startPrice],
|
||||
'amount':[amount]
|
||||
}
|
||||
|
||||
#newDealDict['profit']=[startPrice*pow(1+self.commission,2)]
|
||||
|
||||
|
||||
|
||||
newDeal=pd.DataFrame.from_dict(newDealDict).set_index('uuid')
|
||||
self.deals=pd.concat([self.deals, newDeal])
|
||||
else:
|
||||
self.deals.at[desiredDeal,'amount'] += amount
|
||||
|
||||
def closeDeal(self,uuid,amount):
|
||||
|
||||
desiredDeal=self.deals.loc[uuid]
|
||||
if desiredDeal.amount - amount == 0:
|
||||
self.deals = self.deals.drop(labels = [uuid],axis = 0)
|
||||
else:
|
||||
self.deals.at[uuid,'amount'] -= amount
|
||||
#self.deals.loc[uuid].amount = desiredDeal.amount - amount
|
||||
|
||||
Reference in New Issue
Block a user