summaryrefslogtreecommitdiff
path: root/app/trading/importer.py
blob: a975ff5ee559aae63ba6cf55fbc2966fdbb86bf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import csv
from datetime import datetime

from .models import Ticker

with open(FILENAME, 'r' ) as theFile:
    reader = csv.DictReader(theFile)
    for line in reader:
        dt = datetime.strptime(line['Date/Time'], '%m/%d/%Y %H:%M %p')
        expiration_date = datetime.strptime(line['Expiration Date'], '%m/%d/%Y')
        ticker, created = Ticker.objects.get_or_create(
            symbol=line['Symbol']
        )
        print(ticker)
        t, created = OptionsTrade.objects.get_or_create(
            date=dt,
            transaction_code=line['Transaction Code'],
            transaction_subcode=line['Transaction Subcode'],
            symbol=ticker,
            buy_sell=line['Buy/Sell'],
            open_close=line['Open/Close'],
            quantity=int(line['Quantity']),
            expiration_date = expiration_date,
            strike = line['Strike'],
            call_put = line['Call/Put'],
            price = line['Price'],
            fees = line['Fees'],
            amount = line['Amount'],
            description = line['Description']
        )
        if created:
            print(t)