{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "class Trade:\n",
    "    def __init__(self, symbol, date, qty, price, fee = 0., commission = 0., order = None):\n",
    "        '''Args:\n",
    "            symbol: a string\n",
    "            date: Trade execution datetime\n",
    "            qty: Number of contracts or shares filled\n",
    "            price: Trade price\n",
    "            fee: Fees paid to brokers or others. Default 0\n",
    "            commision: Commission paid to brokers or others. Default 0\n",
    "            order: A reference to the order that created this trade. Default None\n",
    "        '''\n",
    "        assert(isinstance(symbol, str) and len(symbol) > 0)\n",
    "        assert(np.isfinite(qty))\n",
    "        assert(np.isfinite(price))\n",
    "        assert(np.isfinite(fee))\n",
    "        assert(np.isfinite(commission))\n",
    "        \n",
    "        self.symbol = symbol\n",
    "        self.date = date\n",
    "        self.qty = qty\n",
    "        self.price = price\n",
    "        self.fee = fee\n",
    "        self.commission = commission\n",
    "        self.order = order\n",
    "        \n",
    "    def __repr__(self):\n",
    "        return '{} {:%Y-%m-%d %H:%M} qty: {} prc: {}{}{} order: {}'.format(self.symbol, pd.Timestamp(self.date).to_pydatetime(), \n",
    "                                                self.qty, self.price, \n",
    "                                                ' ' + str(self.fee) if self.fee != 0 else '', \n",
    "                                                ' ' + str(self.commission) if self.commission != 0 else '', \n",
    "                                                self.order)\n",
    "    \n",
    "class Contract:\n",
    "    '''A Contract can be a real or virtual instrument. For example, for futures you may wish to create a single continous contract instead of\n",
    "       a contract for each future series\n",
    "    '''\n",
    "    def __init__(self, symbol, multiplier = 1.):\n",
    "        '''\n",
    "        Args:\n",
    "            symbol: A unique string reprenting this contract. e.g IBM or WTI_FUTURE\n",
    "            multiplier: If you have to multiply price to get price per contract, set that multiplier there.\n",
    "        '''\n",
    "        assert(isinstance(symbol, str) and len(symbol) > 0)\n",
    "        assert(multiplier > 0)\n",
    "        self.symbol = symbol\n",
    "        self.multiplier = multiplier\n",
    "        \n",
    "    def __repr__(self):\n",
    "        return f'{self.symbol} multiplier: {self.multiplier}'"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
