API Usage

  1. How to pull raw data
In [30]:
import requests
apikey = '893a9b8d-b5f8-4786-b216-957b3bfef80b'
r = requests.get('http://dev.paxfinancial.ai:5000/api/autotrade/get/?apikey='+apikey)
assert r.status_code == 200
j = r.json()
print(j[0])
{'amount': 322, 'bottom_sell': 23.235, 'close_date': '2019-03-01T14:42:15.099000', 'command_sell': False, 'experiment_id': '033f8708-2f32-11e9-be18-062b1b6fe204', 'final_price': 31.29, 'high_sell': 31.2898, 'last_price': 30.98, 'order_id': 'o-8cf86682-b8b5-4537-a3f5-21e6630ad2c4', 'pl': 1.0100064557779211, 'purchase_date': '2019-03-01T14:34:12.462000', 'security': 'HAL', 'sell_event': 'high_sell', 'time_sell': '2019-03-03T14:34:12.462000'}
  1. prepare a dataframe and fix dates
In [32]:
import pandas as pd
import datetime
df = pd.DataFrame(j)
df['close_date'] = pd.to_datetime(df['close_date'], format='%Y-%m-%dT%H:%M:%S.%f')
df['purchase_date'] = pd.to_datetime(df['close_date'], format='%Y-%m-%dT%H:%M:%S.%f')
  1. Show the historical P/L
In [33]:
closeddf =  df[df['close_date'] < datetime.datetime.now()]
import matplotlib.pyplot as plt
plt.plot(closeddf['pl'])
Out[33]:
[<matplotlib.lines.Line2D at 0x7fcb3474b898>]
  1. Show Future Orders
In [34]:
opendf =  df[df['close_date'].isnull()]
display(opendf)
amount bottom_sell close_date command_sell experiment_id final_price high_sell last_price order_id pl purchase_date security sell_event time_sell
11 619 12.09750 NaT False 033f8708-2f32-11e9-be18-062b1b6fe204 NaN 16.29130 16.130 o-7945d9e2-5764-44f9-b64d-5dd899d8368b NaN NaT BBBY None 2019-03-06T15:07:08.613000
12 628 11.93250 NaT False 033f8708-2f32-11e9-be18-062b1b6fe204 NaN 16.06910 15.910 o-4ef865d0-0ad0-4bd5-9dc6-11a532ba3fa5 NaN NaT BBBY None 2019-03-07T14:32:11.225000
13 626 11.96250 NaT False 033f8708-2f32-11e9-be18-062b1b6fe204 NaN 16.10950 15.950 o-207ffe9d-ffa2-4229-9b80-af613d9f92f3 NaN NaT BBBY None 2019-03-07T14:33:11.615000
14 626 11.96625 NaT False 033f8708-2f32-11e9-be18-062b1b6fe204 NaN 16.11455 15.955 o-fe1ec78e-31bf-4d68-84a6-43e00f1a5a79 NaN NaT BBBY None 2019-03-07T14:34:12.041000