【发布时间】:2020-07-18 20:03:36
【问题描述】:
网络逻辑
- 用户创建一个新的交易对象(输入代码、经纪人、票据等数据)
- 交易还是空的
- 用户现在为此交易创建条目(例如 100 股 @ 5 美元买入)
- 交易必须至少有 2 个整体才能成为平仓交易
- 条目添加在与使用 inlineformset_factory 创建交易相同的表单页面上
Model.py
class Trade(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True)
status = models.CharField(max_length=2, choices=STATUS_CHOICES, default='cl')
type = models.CharField(max_length=5, choices=TYPE_CHOICES, default=LONG)
broker = models.ForeignKey(Broker, on_delete=models.CASCADE, blank=True, null=True)
asset = models.ForeignKey(Asset, default=DEFAULT_ASSET_ID, on_delete=models.CASCADE, null=True)
symbol = models.ForeignKey(Symbol, on_delete=models.CASCADE, blank=True, null=True)
patterns = models.ManyToManyField(Pattern, blank=True)
notes = RichTextUploadingField(blank=True, null=True)
created = models.DateTimeField(editable=False)
modified = models.DateTimeField(editable=False)
associated_portfolios = models.ManyToManyField(Portfolio, blank=True)
image = models.FileField(default='no-image-available-icon.jpg', upload_to=user_directory_path, null=True, blank=True)
class Entry(models.Model):
trade = models.ForeignKey(Trade, on_delete=models.CASCADE)
date = models.DateTimeField(null=True, blank=True, default=datetime.datetime.now)
amount = models.FloatField(null=True)
price = models.FloatField(null=True)
fee = models.FloatField(null=True, blank=True)
entry_type = models.CharField(max_length=5, choices=ENTRY_TYPE_CHOICES, default=ENTRY)
reg_fee = models.FloatField(null=True, blank=True)
transaction_id = models.CharField(max_length=100, null=True, blank=True)
CSV 数据示例(我添加了空格而不是“,”以便更轻松地显示数据)
Date/Time Description Amount Commission RegFee NetCashBalance
07/17/2020 7:42:39 Bought 40 APDN @ 14.56 -582.4 0 0 25,755.84
07/17/2020 7:47:16 Bought 40 APDN @ 14.78 -591.2 0 0 25,164.64
07/17/2020 7:53:36 Bought 20 APDN @ 14.27 -285.4 0 0 24,879.24
07/17/2020 8:04:01 Bought 100 VRNA @ 9.58 -958 0 0 23,921.24
07/17/2020 8:05:01 Bought 20 VRNA @ 9.47 -189.4 0 0 23,731.84
07/17/2020 8:05:27 Sold 21 APDN @ 14.885 312.58 0 0.01 24,044.42
07/17/2020 8:05:27 Sold 79 APDN @ 14.87 1,174.69 0 0.04 25,219.11
07/17/2020 8:06:43 Sold 120 VRNA @ 10.08 1,209.56 0 0.04 26,428.67
如果根据代理导出的 CSV 文件,它还没有击中你,这将是一个超级混乱的过程,我们需要分析大量数据,正确匹配它,创建新对象,并创建多个基于新创建的对象的新的 forieng 关键对象。
CSV 导入逻辑
为了节省时间,用户最好只导入经纪商提供的交易数据。这是一个example site(不是我的项目)也可以。
1. Create an Entry class object (user may need to manually make csv file for cleaner data import)
2. find Trade object where Status == Open and symbol == symbol
3. if step 2 == None then create a new Trade class & assign status to open
4. Def & set Set Symbol_Share_Count == 0
5. Increment or Decrease Symbol_Share_Count by shares
6. Once Symbol_Share_Count == 0 close the trade
3. if step 2 retuns a Trade object then..
4. Def & set Set Symbol_Share_Count == "# of total open shares"
5. Increment or Decrease Symbol_Share_Count by shares of newly imported transaction
6. Once Symbol_Share_Count == 0 close the trade
7. At this point the new or found Trade object is done and a new Trade object can be created or found based on the next transaction
这个逻辑有意义吗?是否存在我忽略的严重问题?
非常感谢任何反馈!
【问题讨论】:
标签: django postgresql csv import django-import-export