/Mockups/Mock.Openquant.API.cs

https://github.com/DrKoch/StingrayOQ · C# · 399 lines · 339 code · 57 blank · 3 comment · 4 complexity · 9468c07ae41a1601ce2e9268c468aac8 MD5 · raw file

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace OpenQuant.API
  7. {
  8. #region enums
  9. #region InstrumentType
  10. public enum InstrumentType
  11. {
  12. Stock = 0, // Stock
  13. Futures = 1, // Futures contract
  14. Option = 2, // Option
  15. FutOpt = 3, // Future option
  16. Bond = 4, // Bond
  17. Index = 5, // Index
  18. ETF = 6, // Exchange traded fund
  19. FX = 7, // Foreign exchange contract
  20. MultiLeg = 8, // Multi leg instrument
  21. }
  22. #endregion
  23. public enum PutCall
  24. {
  25. Put,
  26. Call
  27. }
  28. #region TimeInForce
  29. public enum TimeInForce
  30. {
  31. Day = 0, // Day
  32. GTC = 1, // Good Till Cancel
  33. OPG = 2, // At the Opening
  34. IOC = 3, // Immediate or Cancel
  35. FOK = 4, // Fill or Kill
  36. GTX = 5, // Good Till Crossing
  37. GTD = 6, // Good Till Date
  38. ATC = 7, // At the Close
  39. GFS
  40. }
  41. #endregion
  42. public enum IBFaMethod
  43. {
  44. PctChange,
  45. AvailableEquity,
  46. NetLiq,
  47. EqualQuantity,
  48. Undefined
  49. }
  50. public enum OrderSide
  51. {
  52. Buy,
  53. Sell
  54. }
  55. #region OrderType
  56. public enum OrderType
  57. {
  58. Market = 0, // Market order
  59. Limit = 1, // Limit order
  60. Stop = 2, // Stop order
  61. StopLimit = 3, // Stop limit order
  62. Trail = 4, // Trailing stop order
  63. // This order type is valid for IB only. Use Order.TrailingAmt to set trailing stop amount. For more information, refer to 'Order Types' section on IB website (http://www.interactivebrokers.com/php/webhelp/webhelp.htm)
  64. TrailLimit = 5, // Trailing stop limit order
  65. // This order type is valid for IB only. Use Order.TrailingAmt to set trailing stop amount, Order.StopPrice and Order.Price to set limit offset. For more information, refer to 'Order Types' section on IB website (http://www.interactivebrokers.com/php/webhelp/webhelp.htm)
  66. MarketOnClose = 6, // Market-on-close order
  67. // This order type is valid for IB only
  68. }
  69. #endregion
  70. #region OrderStatus
  71. public enum OrderStatus
  72. {
  73. PendingNew = 0, // Pending New.
  74. New = 1, // New.
  75. PartiallyFilled = 2, // PartiallyFilled.
  76. Filled = 3, // Filled.
  77. PendingCancel = 4, // PendingCancel.
  78. Cancelled = 5, // Cancelled.
  79. Expired = 6, // Expired.
  80. PendingReplace = 7, // PendingReplace.
  81. Replaced = 8, // Replaced.
  82. Rejected = 9, // Rejected.
  83. }
  84. #endregion
  85. #endregion
  86. #region IBEx
  87. public class IBEx
  88. {
  89. public double DisplaySize { get; set; }
  90. public string FaGroup { get; set; }
  91. public IBFaMethod FaMethod { get; set; }
  92. public double FaPercentage { get; set; }
  93. public string FaProfile { get; set; }
  94. public bool Hidden { get; set; }
  95. }
  96. #endregion
  97. #region Instrument
  98. public class Instrument
  99. {
  100. public string Currency { get; set; }
  101. public string Exchange { get; set; }
  102. public double Factor { get; set; }
  103. public DateTime Maturity { get; set; }
  104. public double Strike { get; set; }
  105. public string Symbol;
  106. private InstrumentType _type;
  107. public InstrumentType Type
  108. {
  109. get { return _type; }
  110. set { _type = value; } // mock has a setter
  111. }
  112. }
  113. #endregion
  114. #region Order
  115. public class Order
  116. {
  117. public string Account { get; set; }
  118. public string ClientID { get; set; }
  119. private double _cumQty;
  120. public double CumQty
  121. {
  122. get { return _cumQty; }
  123. set // mock has setter
  124. {
  125. _cumQty = value;
  126. if (_cumQty < 0) throw new ArgumentException("must be positive", "CumQty");
  127. if (_cumQty > Qty) throw new ArgumentException("must be <= Qty", "CumQty");
  128. }
  129. }
  130. private IBEx _ibex;
  131. public IBEx IB
  132. {
  133. get { return _ibex; }
  134. private set { _ibex = value; }
  135. }
  136. public Instrument Instrument { get; set; }
  137. private double _lastQty;
  138. public double LastQty
  139. {
  140. get { return _lastQty; }
  141. set // mock has setter
  142. {
  143. _lastQty = value;
  144. if (_lastQty <= 0) throw new ArgumentException("must be positive", "LastQty");
  145. }
  146. }
  147. private double _leavesQty;
  148. public double LeavesQty
  149. {
  150. get { return _leavesQty; }
  151. set // mock has setter
  152. {
  153. _leavesQty = value;
  154. if (_leavesQty < 0) throw new ArgumentException("must not be negative", "LeavesQty");
  155. }
  156. }
  157. public string OCAGroup { get; set; }
  158. public string OrderID;
  159. public double Price { get; set; }
  160. public OrderSide Side;
  161. public double StopPrice { get; set; }
  162. public TimeInForce TimeInForce { get; set; }
  163. public string Text { get; set; }
  164. public OrderType Type;
  165. private double _qty;
  166. public double Qty
  167. {
  168. get { return _qty; }
  169. set
  170. {
  171. _qty = value;
  172. _leavesQty = value;
  173. }
  174. }
  175. public Order() // mock has a constructor
  176. {
  177. IB = new IBEx();
  178. }
  179. }
  180. #endregion
  181. #region BrokerAccount
  182. public class BrokerAccount
  183. {
  184. private BrokerAccountFieldList _fields;
  185. public BrokerAccountFieldList Fields
  186. {
  187. get { return _fields; }
  188. }
  189. public double BuyingPower { get; set; }
  190. public void AddField(
  191. string name,
  192. string value
  193. )
  194. {
  195. }
  196. public void AddField(
  197. string name,
  198. string currency,
  199. string value
  200. )
  201. {}
  202. public BrokerOrder AddOrder()
  203. {
  204. return new BrokerOrder();
  205. }
  206. public BrokerPosition AddPosition()
  207. {
  208. return new BrokerPosition();
  209. }
  210. }
  211. #endregion
  212. #region BrokerAccountFieldList
  213. public class BrokerAccountFieldList : ICollection
  214. {
  215. public bool Contains(
  216. string name
  217. )
  218. {
  219. return false;
  220. }
  221. public bool Contains(
  222. string name,
  223. string currency
  224. )
  225. {
  226. return false;
  227. }
  228. public void CopyTo(Array array, int index)
  229. {
  230. throw new NotImplementedException();
  231. }
  232. public int Count
  233. {
  234. get { throw new NotImplementedException(); }
  235. }
  236. public bool IsSynchronized
  237. {
  238. get { throw new NotImplementedException(); }
  239. }
  240. public object SyncRoot
  241. {
  242. get { throw new NotImplementedException(); }
  243. }
  244. public IEnumerator GetEnumerator()
  245. {
  246. throw new NotImplementedException();
  247. }
  248. }
  249. #endregion
  250. #region BrokerAccountList
  251. public class BrokerAccountList : ICollection
  252. {
  253. public BrokerAccount this[string n]
  254. {
  255. get { return new BrokerAccount(); }
  256. }
  257. public void CopyTo(Array array, int index)
  258. {
  259. throw new NotImplementedException();
  260. }
  261. public int Count
  262. {
  263. get { throw new NotImplementedException(); }
  264. }
  265. public bool IsSynchronized
  266. {
  267. get { throw new NotImplementedException(); }
  268. }
  269. public object SyncRoot
  270. {
  271. get { throw new NotImplementedException(); }
  272. }
  273. public IEnumerator GetEnumerator()
  274. {
  275. throw new NotImplementedException();
  276. }
  277. }
  278. #endregion
  279. #region BrokerOrder
  280. public class BrokerOrder
  281. {
  282. public string Currency { get; set; }
  283. public string Exchange { get; set; }
  284. private BrokerOrderFieldList _fields;
  285. public BrokerOrderFieldList Fields
  286. {
  287. get { return _fields; }
  288. }
  289. public InstrumentType InstrumentType { get; set; }
  290. public string OrderID { get; set; }
  291. public double Price { get; set; }
  292. public double Qty { get; set; }
  293. public OrderSide Side { get; set; }
  294. public OrderStatus Status { get; set; }
  295. public double StopPrice { get; set; }
  296. public string Symbol { get; set; }
  297. public OrderType Type { get; set; }
  298. public void AddCustomField(
  299. string name,
  300. string value
  301. )
  302. {}
  303. }
  304. #endregion
  305. public class BrokerOrderFieldList
  306. {
  307. }
  308. #region BrokerPosition
  309. public class BrokerPosition
  310. {
  311. public string Currency { get; set; }
  312. public string Exchange { get; set; }
  313. public InstrumentType InstrumentType { get; set; }
  314. public double LongQty { get; set; }
  315. public DateTime Maturity { get; set; }
  316. public PutCall PutCall { get; set; }
  317. public double Qty { get; set; }
  318. public double ShortQty { get; set; }
  319. public double Strike { get; set; }
  320. public string Symbol { get; set; }
  321. public void AddCustomField(
  322. string name,
  323. string value
  324. )
  325. {}
  326. }
  327. #endregion
  328. public class BrokerInfo
  329. {
  330. private BrokerAccountList _accounts;
  331. public BrokerAccountList Accounts
  332. {
  333. get { return _accounts; }
  334. }
  335. public BrokerAccount AddAccount(
  336. string name
  337. )
  338. {
  339. return new BrokerAccount();
  340. }
  341. }
  342. }