pyswordfish 3.0.4.0__cp312-cp312-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (644) hide show
  1. pyswordfish-3.0.4.0.dist-info/METADATA +53 -0
  2. pyswordfish-3.0.4.0.dist-info/RECORD +644 -0
  3. pyswordfish-3.0.4.0.dist-info/WHEEL +5 -0
  4. pyswordfish-3.0.4.0.dist-info/top_level.txt +1 -0
  5. swordfish/__init__.py +102 -0
  6. swordfish/_config.py +901 -0
  7. swordfish/_connection.py +1418 -0
  8. swordfish/_core.py +17 -0
  9. swordfish/_engine.py +1456 -0
  10. swordfish/_enums.py +142 -0
  11. swordfish/_function_bindings.py +23594 -0
  12. swordfish/_function_tools.py +124 -0
  13. swordfish/_helper.py +57 -0
  14. swordfish/_runtime.py +158 -0
  15. swordfish/_sqlbuilder.py +549 -0
  16. swordfish/_streaming.py +333 -0
  17. swordfish/_swordfishcpp.cp312-win_amd64.pyd +0 -0
  18. swordfish/_swordfishcpp.pyi +4784 -0
  19. swordfish/_translator.py +580 -0
  20. swordfish/asset/dolphindb.dos +71 -0
  21. swordfish/asset/tzdb/Africa/Abidjan +0 -0
  22. swordfish/asset/tzdb/Africa/Accra +0 -0
  23. swordfish/asset/tzdb/Africa/Addis_Ababa +0 -0
  24. swordfish/asset/tzdb/Africa/Algiers +0 -0
  25. swordfish/asset/tzdb/Africa/Asmara +0 -0
  26. swordfish/asset/tzdb/Africa/Asmera +0 -0
  27. swordfish/asset/tzdb/Africa/Bamako +0 -0
  28. swordfish/asset/tzdb/Africa/Bangui +0 -0
  29. swordfish/asset/tzdb/Africa/Banjul +0 -0
  30. swordfish/asset/tzdb/Africa/Bissau +0 -0
  31. swordfish/asset/tzdb/Africa/Blantyre +0 -0
  32. swordfish/asset/tzdb/Africa/Brazzaville +0 -0
  33. swordfish/asset/tzdb/Africa/Bujumbura +0 -0
  34. swordfish/asset/tzdb/Africa/Cairo +0 -0
  35. swordfish/asset/tzdb/Africa/Casablanca +0 -0
  36. swordfish/asset/tzdb/Africa/Ceuta +0 -0
  37. swordfish/asset/tzdb/Africa/Conakry +0 -0
  38. swordfish/asset/tzdb/Africa/Dakar +0 -0
  39. swordfish/asset/tzdb/Africa/Dar_es_Salaam +0 -0
  40. swordfish/asset/tzdb/Africa/Djibouti +0 -0
  41. swordfish/asset/tzdb/Africa/Douala +0 -0
  42. swordfish/asset/tzdb/Africa/El_Aaiun +0 -0
  43. swordfish/asset/tzdb/Africa/Freetown +0 -0
  44. swordfish/asset/tzdb/Africa/Gaborone +0 -0
  45. swordfish/asset/tzdb/Africa/Harare +0 -0
  46. swordfish/asset/tzdb/Africa/Johannesburg +0 -0
  47. swordfish/asset/tzdb/Africa/Juba +0 -0
  48. swordfish/asset/tzdb/Africa/Kampala +0 -0
  49. swordfish/asset/tzdb/Africa/Khartoum +0 -0
  50. swordfish/asset/tzdb/Africa/Kigali +0 -0
  51. swordfish/asset/tzdb/Africa/Kinshasa +0 -0
  52. swordfish/asset/tzdb/Africa/Lagos +0 -0
  53. swordfish/asset/tzdb/Africa/Libreville +0 -0
  54. swordfish/asset/tzdb/Africa/Lome +0 -0
  55. swordfish/asset/tzdb/Africa/Luanda +0 -0
  56. swordfish/asset/tzdb/Africa/Lubumbashi +0 -0
  57. swordfish/asset/tzdb/Africa/Lusaka +0 -0
  58. swordfish/asset/tzdb/Africa/Malabo +0 -0
  59. swordfish/asset/tzdb/Africa/Maputo +0 -0
  60. swordfish/asset/tzdb/Africa/Maseru +0 -0
  61. swordfish/asset/tzdb/Africa/Mbabane +0 -0
  62. swordfish/asset/tzdb/Africa/Mogadishu +0 -0
  63. swordfish/asset/tzdb/Africa/Monrovia +0 -0
  64. swordfish/asset/tzdb/Africa/Nairobi +0 -0
  65. swordfish/asset/tzdb/Africa/Ndjamena +0 -0
  66. swordfish/asset/tzdb/Africa/Niamey +0 -0
  67. swordfish/asset/tzdb/Africa/Nouakchott +0 -0
  68. swordfish/asset/tzdb/Africa/Ouagadougou +0 -0
  69. swordfish/asset/tzdb/Africa/Porto-Novo +0 -0
  70. swordfish/asset/tzdb/Africa/Sao_Tome +0 -0
  71. swordfish/asset/tzdb/Africa/Timbuktu +0 -0
  72. swordfish/asset/tzdb/Africa/Tripoli +0 -0
  73. swordfish/asset/tzdb/Africa/Tunis +0 -0
  74. swordfish/asset/tzdb/Africa/Windhoek +0 -0
  75. swordfish/asset/tzdb/America/Adak +0 -0
  76. swordfish/asset/tzdb/America/Anchorage +0 -0
  77. swordfish/asset/tzdb/America/Anguilla +0 -0
  78. swordfish/asset/tzdb/America/Antigua +0 -0
  79. swordfish/asset/tzdb/America/Araguaina +0 -0
  80. swordfish/asset/tzdb/America/Argentina/Buenos_Aires +0 -0
  81. swordfish/asset/tzdb/America/Argentina/Catamarca +0 -0
  82. swordfish/asset/tzdb/America/Argentina/ComodRivadavia +0 -0
  83. swordfish/asset/tzdb/America/Argentina/Cordoba +0 -0
  84. swordfish/asset/tzdb/America/Argentina/Jujuy +0 -0
  85. swordfish/asset/tzdb/America/Argentina/La_Rioja +0 -0
  86. swordfish/asset/tzdb/America/Argentina/Mendoza +0 -0
  87. swordfish/asset/tzdb/America/Argentina/Rio_Gallegos +0 -0
  88. swordfish/asset/tzdb/America/Argentina/Salta +0 -0
  89. swordfish/asset/tzdb/America/Argentina/San_Juan +0 -0
  90. swordfish/asset/tzdb/America/Argentina/San_Luis +0 -0
  91. swordfish/asset/tzdb/America/Argentina/Tucuman +0 -0
  92. swordfish/asset/tzdb/America/Argentina/Ushuaia +0 -0
  93. swordfish/asset/tzdb/America/Aruba +0 -0
  94. swordfish/asset/tzdb/America/Asuncion +0 -0
  95. swordfish/asset/tzdb/America/Atikokan +0 -0
  96. swordfish/asset/tzdb/America/Atka +0 -0
  97. swordfish/asset/tzdb/America/Bahia +0 -0
  98. swordfish/asset/tzdb/America/Bahia_Banderas +0 -0
  99. swordfish/asset/tzdb/America/Barbados +0 -0
  100. swordfish/asset/tzdb/America/Belem +0 -0
  101. swordfish/asset/tzdb/America/Belize +0 -0
  102. swordfish/asset/tzdb/America/Blanc-Sablon +0 -0
  103. swordfish/asset/tzdb/America/Boa_Vista +0 -0
  104. swordfish/asset/tzdb/America/Bogota +0 -0
  105. swordfish/asset/tzdb/America/Boise +0 -0
  106. swordfish/asset/tzdb/America/Buenos_Aires +0 -0
  107. swordfish/asset/tzdb/America/Cambridge_Bay +0 -0
  108. swordfish/asset/tzdb/America/Campo_Grande +0 -0
  109. swordfish/asset/tzdb/America/Cancun +0 -0
  110. swordfish/asset/tzdb/America/Caracas +0 -0
  111. swordfish/asset/tzdb/America/Catamarca +0 -0
  112. swordfish/asset/tzdb/America/Cayenne +0 -0
  113. swordfish/asset/tzdb/America/Cayman +0 -0
  114. swordfish/asset/tzdb/America/Chicago +0 -0
  115. swordfish/asset/tzdb/America/Chihuahua +0 -0
  116. swordfish/asset/tzdb/America/Coral_Harbour +0 -0
  117. swordfish/asset/tzdb/America/Cordoba +0 -0
  118. swordfish/asset/tzdb/America/Costa_Rica +0 -0
  119. swordfish/asset/tzdb/America/Creston +0 -0
  120. swordfish/asset/tzdb/America/Cuiaba +0 -0
  121. swordfish/asset/tzdb/America/Curacao +0 -0
  122. swordfish/asset/tzdb/America/Danmarkshavn +0 -0
  123. swordfish/asset/tzdb/America/Dawson +0 -0
  124. swordfish/asset/tzdb/America/Dawson_Creek +0 -0
  125. swordfish/asset/tzdb/America/Denver +0 -0
  126. swordfish/asset/tzdb/America/Detroit +0 -0
  127. swordfish/asset/tzdb/America/Dominica +0 -0
  128. swordfish/asset/tzdb/America/Edmonton +0 -0
  129. swordfish/asset/tzdb/America/Eirunepe +0 -0
  130. swordfish/asset/tzdb/America/El_Salvador +0 -0
  131. swordfish/asset/tzdb/America/Ensenada +0 -0
  132. swordfish/asset/tzdb/America/Fort_Nelson +0 -0
  133. swordfish/asset/tzdb/America/Fort_Wayne +0 -0
  134. swordfish/asset/tzdb/America/Fortaleza +0 -0
  135. swordfish/asset/tzdb/America/Glace_Bay +0 -0
  136. swordfish/asset/tzdb/America/Godthab +0 -0
  137. swordfish/asset/tzdb/America/Goose_Bay +0 -0
  138. swordfish/asset/tzdb/America/Grand_Turk +0 -0
  139. swordfish/asset/tzdb/America/Grenada +0 -0
  140. swordfish/asset/tzdb/America/Guadeloupe +0 -0
  141. swordfish/asset/tzdb/America/Guatemala +0 -0
  142. swordfish/asset/tzdb/America/Guayaquil +0 -0
  143. swordfish/asset/tzdb/America/Guyana +0 -0
  144. swordfish/asset/tzdb/America/Halifax +0 -0
  145. swordfish/asset/tzdb/America/Havana +0 -0
  146. swordfish/asset/tzdb/America/Hermosillo +0 -0
  147. swordfish/asset/tzdb/America/Indiana/Indianapolis +0 -0
  148. swordfish/asset/tzdb/America/Indiana/Knox +0 -0
  149. swordfish/asset/tzdb/America/Indiana/Marengo +0 -0
  150. swordfish/asset/tzdb/America/Indiana/Petersburg +0 -0
  151. swordfish/asset/tzdb/America/Indiana/Tell_City +0 -0
  152. swordfish/asset/tzdb/America/Indiana/Vevay +0 -0
  153. swordfish/asset/tzdb/America/Indiana/Vincennes +0 -0
  154. swordfish/asset/tzdb/America/Indiana/Winamac +0 -0
  155. swordfish/asset/tzdb/America/Indianapolis +0 -0
  156. swordfish/asset/tzdb/America/Inuvik +0 -0
  157. swordfish/asset/tzdb/America/Iqaluit +0 -0
  158. swordfish/asset/tzdb/America/Jamaica +0 -0
  159. swordfish/asset/tzdb/America/Jujuy +0 -0
  160. swordfish/asset/tzdb/America/Juneau +0 -0
  161. swordfish/asset/tzdb/America/Kentucky/Louisville +0 -0
  162. swordfish/asset/tzdb/America/Kentucky/Monticello +0 -0
  163. swordfish/asset/tzdb/America/Knox_IN +0 -0
  164. swordfish/asset/tzdb/America/Kralendijk +0 -0
  165. swordfish/asset/tzdb/America/La_Paz +0 -0
  166. swordfish/asset/tzdb/America/Lima +0 -0
  167. swordfish/asset/tzdb/America/Los_Angeles +0 -0
  168. swordfish/asset/tzdb/America/Louisville +0 -0
  169. swordfish/asset/tzdb/America/Lower_Princes +0 -0
  170. swordfish/asset/tzdb/America/Maceio +0 -0
  171. swordfish/asset/tzdb/America/Managua +0 -0
  172. swordfish/asset/tzdb/America/Manaus +0 -0
  173. swordfish/asset/tzdb/America/Marigot +0 -0
  174. swordfish/asset/tzdb/America/Martinique +0 -0
  175. swordfish/asset/tzdb/America/Matamoros +0 -0
  176. swordfish/asset/tzdb/America/Mazatlan +0 -0
  177. swordfish/asset/tzdb/America/Mendoza +0 -0
  178. swordfish/asset/tzdb/America/Menominee +0 -0
  179. swordfish/asset/tzdb/America/Merida +0 -0
  180. swordfish/asset/tzdb/America/Metlakatla +0 -0
  181. swordfish/asset/tzdb/America/Mexico_City +0 -0
  182. swordfish/asset/tzdb/America/Miquelon +0 -0
  183. swordfish/asset/tzdb/America/Moncton +0 -0
  184. swordfish/asset/tzdb/America/Monterrey +0 -0
  185. swordfish/asset/tzdb/America/Montevideo +0 -0
  186. swordfish/asset/tzdb/America/Montreal +0 -0
  187. swordfish/asset/tzdb/America/Montserrat +0 -0
  188. swordfish/asset/tzdb/America/Nassau +0 -0
  189. swordfish/asset/tzdb/America/New_York +0 -0
  190. swordfish/asset/tzdb/America/Nipigon +0 -0
  191. swordfish/asset/tzdb/America/Nome +0 -0
  192. swordfish/asset/tzdb/America/Noronha +0 -0
  193. swordfish/asset/tzdb/America/North_Dakota/Beulah +0 -0
  194. swordfish/asset/tzdb/America/North_Dakota/Center +0 -0
  195. swordfish/asset/tzdb/America/North_Dakota/New_Salem +0 -0
  196. swordfish/asset/tzdb/America/Ojinaga +0 -0
  197. swordfish/asset/tzdb/America/Panama +0 -0
  198. swordfish/asset/tzdb/America/Pangnirtung +0 -0
  199. swordfish/asset/tzdb/America/Paramaribo +0 -0
  200. swordfish/asset/tzdb/America/Phoenix +0 -0
  201. swordfish/asset/tzdb/America/Port-au-Prince +0 -0
  202. swordfish/asset/tzdb/America/Port_of_Spain +0 -0
  203. swordfish/asset/tzdb/America/Porto_Acre +0 -0
  204. swordfish/asset/tzdb/America/Porto_Velho +0 -0
  205. swordfish/asset/tzdb/America/Puerto_Rico +0 -0
  206. swordfish/asset/tzdb/America/Punta_Arenas +0 -0
  207. swordfish/asset/tzdb/America/Rainy_River +0 -0
  208. swordfish/asset/tzdb/America/Rankin_Inlet +0 -0
  209. swordfish/asset/tzdb/America/Recife +0 -0
  210. swordfish/asset/tzdb/America/Regina +0 -0
  211. swordfish/asset/tzdb/America/Resolute +0 -0
  212. swordfish/asset/tzdb/America/Rio_Branco +0 -0
  213. swordfish/asset/tzdb/America/Rosario +0 -0
  214. swordfish/asset/tzdb/America/Santa_Isabel +0 -0
  215. swordfish/asset/tzdb/America/Santarem +0 -0
  216. swordfish/asset/tzdb/America/Santiago +0 -0
  217. swordfish/asset/tzdb/America/Santo_Domingo +0 -0
  218. swordfish/asset/tzdb/America/Sao_Paulo +0 -0
  219. swordfish/asset/tzdb/America/Scoresbysund +0 -0
  220. swordfish/asset/tzdb/America/Shiprock +0 -0
  221. swordfish/asset/tzdb/America/Sitka +0 -0
  222. swordfish/asset/tzdb/America/St_Barthelemy +0 -0
  223. swordfish/asset/tzdb/America/St_Johns +0 -0
  224. swordfish/asset/tzdb/America/St_Kitts +0 -0
  225. swordfish/asset/tzdb/America/St_Lucia +0 -0
  226. swordfish/asset/tzdb/America/St_Thomas +0 -0
  227. swordfish/asset/tzdb/America/St_Vincent +0 -0
  228. swordfish/asset/tzdb/America/Swift_Current +0 -0
  229. swordfish/asset/tzdb/America/Tegucigalpa +0 -0
  230. swordfish/asset/tzdb/America/Thule +0 -0
  231. swordfish/asset/tzdb/America/Thunder_Bay +0 -0
  232. swordfish/asset/tzdb/America/Tijuana +0 -0
  233. swordfish/asset/tzdb/America/Toronto +0 -0
  234. swordfish/asset/tzdb/America/Tortola +0 -0
  235. swordfish/asset/tzdb/America/Vancouver +0 -0
  236. swordfish/asset/tzdb/America/Virgin +0 -0
  237. swordfish/asset/tzdb/America/Whitehorse +0 -0
  238. swordfish/asset/tzdb/America/Winnipeg +0 -0
  239. swordfish/asset/tzdb/America/Yakutat +0 -0
  240. swordfish/asset/tzdb/America/Yellowknife +0 -0
  241. swordfish/asset/tzdb/Antarctica/Casey +0 -0
  242. swordfish/asset/tzdb/Antarctica/Davis +0 -0
  243. swordfish/asset/tzdb/Antarctica/DumontDUrville +0 -0
  244. swordfish/asset/tzdb/Antarctica/Macquarie +0 -0
  245. swordfish/asset/tzdb/Antarctica/Mawson +0 -0
  246. swordfish/asset/tzdb/Antarctica/McMurdo +0 -0
  247. swordfish/asset/tzdb/Antarctica/Palmer +0 -0
  248. swordfish/asset/tzdb/Antarctica/Rothera +0 -0
  249. swordfish/asset/tzdb/Antarctica/South_Pole +0 -0
  250. swordfish/asset/tzdb/Antarctica/Syowa +0 -0
  251. swordfish/asset/tzdb/Antarctica/Troll +0 -0
  252. swordfish/asset/tzdb/Antarctica/Vostok +0 -0
  253. swordfish/asset/tzdb/Arctic/Longyearbyen +0 -0
  254. swordfish/asset/tzdb/Asia/Aden +0 -0
  255. swordfish/asset/tzdb/Asia/Almaty +0 -0
  256. swordfish/asset/tzdb/Asia/Amman +0 -0
  257. swordfish/asset/tzdb/Asia/Anadyr +0 -0
  258. swordfish/asset/tzdb/Asia/Aqtau +0 -0
  259. swordfish/asset/tzdb/Asia/Aqtobe +0 -0
  260. swordfish/asset/tzdb/Asia/Ashgabat +0 -0
  261. swordfish/asset/tzdb/Asia/Ashkhabad +0 -0
  262. swordfish/asset/tzdb/Asia/Atyrau +0 -0
  263. swordfish/asset/tzdb/Asia/Baghdad +0 -0
  264. swordfish/asset/tzdb/Asia/Bahrain +0 -0
  265. swordfish/asset/tzdb/Asia/Baku +0 -0
  266. swordfish/asset/tzdb/Asia/Bangkok +0 -0
  267. swordfish/asset/tzdb/Asia/Barnaul +0 -0
  268. swordfish/asset/tzdb/Asia/Beirut +0 -0
  269. swordfish/asset/tzdb/Asia/Bishkek +0 -0
  270. swordfish/asset/tzdb/Asia/Brunei +0 -0
  271. swordfish/asset/tzdb/Asia/Calcutta +0 -0
  272. swordfish/asset/tzdb/Asia/Chita +0 -0
  273. swordfish/asset/tzdb/Asia/Choibalsan +0 -0
  274. swordfish/asset/tzdb/Asia/Chongqing +0 -0
  275. swordfish/asset/tzdb/Asia/Chungking +0 -0
  276. swordfish/asset/tzdb/Asia/Colombo +0 -0
  277. swordfish/asset/tzdb/Asia/Dacca +0 -0
  278. swordfish/asset/tzdb/Asia/Damascus +0 -0
  279. swordfish/asset/tzdb/Asia/Dhaka +0 -0
  280. swordfish/asset/tzdb/Asia/Dili +0 -0
  281. swordfish/asset/tzdb/Asia/Dubai +0 -0
  282. swordfish/asset/tzdb/Asia/Dushanbe +0 -0
  283. swordfish/asset/tzdb/Asia/Famagusta +0 -0
  284. swordfish/asset/tzdb/Asia/Gaza +0 -0
  285. swordfish/asset/tzdb/Asia/Harbin +0 -0
  286. swordfish/asset/tzdb/Asia/Hebron +0 -0
  287. swordfish/asset/tzdb/Asia/Ho_Chi_Minh +0 -0
  288. swordfish/asset/tzdb/Asia/Hong_Kong +0 -0
  289. swordfish/asset/tzdb/Asia/Hovd +0 -0
  290. swordfish/asset/tzdb/Asia/Irkutsk +0 -0
  291. swordfish/asset/tzdb/Asia/Istanbul +0 -0
  292. swordfish/asset/tzdb/Asia/Jakarta +0 -0
  293. swordfish/asset/tzdb/Asia/Jayapura +0 -0
  294. swordfish/asset/tzdb/Asia/Jerusalem +0 -0
  295. swordfish/asset/tzdb/Asia/Kabul +0 -0
  296. swordfish/asset/tzdb/Asia/Kamchatka +0 -0
  297. swordfish/asset/tzdb/Asia/Karachi +0 -0
  298. swordfish/asset/tzdb/Asia/Kashgar +0 -0
  299. swordfish/asset/tzdb/Asia/Kathmandu +0 -0
  300. swordfish/asset/tzdb/Asia/Katmandu +0 -0
  301. swordfish/asset/tzdb/Asia/Khandyga +0 -0
  302. swordfish/asset/tzdb/Asia/Kolkata +0 -0
  303. swordfish/asset/tzdb/Asia/Krasnoyarsk +0 -0
  304. swordfish/asset/tzdb/Asia/Kuala_Lumpur +0 -0
  305. swordfish/asset/tzdb/Asia/Kuching +0 -0
  306. swordfish/asset/tzdb/Asia/Kuwait +0 -0
  307. swordfish/asset/tzdb/Asia/Macao +0 -0
  308. swordfish/asset/tzdb/Asia/Macau +0 -0
  309. swordfish/asset/tzdb/Asia/Magadan +0 -0
  310. swordfish/asset/tzdb/Asia/Makassar +0 -0
  311. swordfish/asset/tzdb/Asia/Manila +0 -0
  312. swordfish/asset/tzdb/Asia/Muscat +0 -0
  313. swordfish/asset/tzdb/Asia/Nicosia +0 -0
  314. swordfish/asset/tzdb/Asia/Novokuznetsk +0 -0
  315. swordfish/asset/tzdb/Asia/Novosibirsk +0 -0
  316. swordfish/asset/tzdb/Asia/Omsk +0 -0
  317. swordfish/asset/tzdb/Asia/Oral +0 -0
  318. swordfish/asset/tzdb/Asia/Phnom_Penh +0 -0
  319. swordfish/asset/tzdb/Asia/Pontianak +0 -0
  320. swordfish/asset/tzdb/Asia/Pyongyang +0 -0
  321. swordfish/asset/tzdb/Asia/Qatar +0 -0
  322. swordfish/asset/tzdb/Asia/Qyzylorda +0 -0
  323. swordfish/asset/tzdb/Asia/Rangoon +0 -0
  324. swordfish/asset/tzdb/Asia/Riyadh +0 -0
  325. swordfish/asset/tzdb/Asia/Saigon +0 -0
  326. swordfish/asset/tzdb/Asia/Sakhalin +0 -0
  327. swordfish/asset/tzdb/Asia/Samarkand +0 -0
  328. swordfish/asset/tzdb/Asia/Seoul +0 -0
  329. swordfish/asset/tzdb/Asia/Shanghai +0 -0
  330. swordfish/asset/tzdb/Asia/Singapore +0 -0
  331. swordfish/asset/tzdb/Asia/Srednekolymsk +0 -0
  332. swordfish/asset/tzdb/Asia/Taipei +0 -0
  333. swordfish/asset/tzdb/Asia/Tashkent +0 -0
  334. swordfish/asset/tzdb/Asia/Tbilisi +0 -0
  335. swordfish/asset/tzdb/Asia/Tehran +0 -0
  336. swordfish/asset/tzdb/Asia/Tel_Aviv +0 -0
  337. swordfish/asset/tzdb/Asia/Thimbu +0 -0
  338. swordfish/asset/tzdb/Asia/Thimphu +0 -0
  339. swordfish/asset/tzdb/Asia/Tokyo +0 -0
  340. swordfish/asset/tzdb/Asia/Tomsk +0 -0
  341. swordfish/asset/tzdb/Asia/Ujung_Pandang +0 -0
  342. swordfish/asset/tzdb/Asia/Ulaanbaatar +0 -0
  343. swordfish/asset/tzdb/Asia/Ulan_Bator +0 -0
  344. swordfish/asset/tzdb/Asia/Urumqi +0 -0
  345. swordfish/asset/tzdb/Asia/Ust-Nera +0 -0
  346. swordfish/asset/tzdb/Asia/Vientiane +0 -0
  347. swordfish/asset/tzdb/Asia/Vladivostok +0 -0
  348. swordfish/asset/tzdb/Asia/Yakutsk +0 -0
  349. swordfish/asset/tzdb/Asia/Yangon +0 -0
  350. swordfish/asset/tzdb/Asia/Yekaterinburg +0 -0
  351. swordfish/asset/tzdb/Asia/Yerevan +0 -0
  352. swordfish/asset/tzdb/Atlantic/Azores +0 -0
  353. swordfish/asset/tzdb/Atlantic/Bermuda +0 -0
  354. swordfish/asset/tzdb/Atlantic/Canary +0 -0
  355. swordfish/asset/tzdb/Atlantic/Cape_Verde +0 -0
  356. swordfish/asset/tzdb/Atlantic/Faeroe +0 -0
  357. swordfish/asset/tzdb/Atlantic/Faroe +0 -0
  358. swordfish/asset/tzdb/Atlantic/Jan_Mayen +0 -0
  359. swordfish/asset/tzdb/Atlantic/Madeira +0 -0
  360. swordfish/asset/tzdb/Atlantic/Reykjavik +0 -0
  361. swordfish/asset/tzdb/Atlantic/South_Georgia +0 -0
  362. swordfish/asset/tzdb/Atlantic/St_Helena +0 -0
  363. swordfish/asset/tzdb/Atlantic/Stanley +0 -0
  364. swordfish/asset/tzdb/Australia/ACT +0 -0
  365. swordfish/asset/tzdb/Australia/Adelaide +0 -0
  366. swordfish/asset/tzdb/Australia/Brisbane +0 -0
  367. swordfish/asset/tzdb/Australia/Broken_Hill +0 -0
  368. swordfish/asset/tzdb/Australia/Canberra +0 -0
  369. swordfish/asset/tzdb/Australia/Currie +0 -0
  370. swordfish/asset/tzdb/Australia/Darwin +0 -0
  371. swordfish/asset/tzdb/Australia/Eucla +0 -0
  372. swordfish/asset/tzdb/Australia/Hobart +0 -0
  373. swordfish/asset/tzdb/Australia/LHI +0 -0
  374. swordfish/asset/tzdb/Australia/Lindeman +0 -0
  375. swordfish/asset/tzdb/Australia/Lord_Howe +0 -0
  376. swordfish/asset/tzdb/Australia/Melbourne +0 -0
  377. swordfish/asset/tzdb/Australia/NSW +0 -0
  378. swordfish/asset/tzdb/Australia/North +0 -0
  379. swordfish/asset/tzdb/Australia/Perth +0 -0
  380. swordfish/asset/tzdb/Australia/Queensland +0 -0
  381. swordfish/asset/tzdb/Australia/South +0 -0
  382. swordfish/asset/tzdb/Australia/Sydney +0 -0
  383. swordfish/asset/tzdb/Australia/Tasmania +0 -0
  384. swordfish/asset/tzdb/Australia/Victoria +0 -0
  385. swordfish/asset/tzdb/Australia/West +0 -0
  386. swordfish/asset/tzdb/Australia/Yancowinna +0 -0
  387. swordfish/asset/tzdb/Brazil/Acre +0 -0
  388. swordfish/asset/tzdb/Brazil/DeNoronha +0 -0
  389. swordfish/asset/tzdb/Brazil/East +0 -0
  390. swordfish/asset/tzdb/Brazil/West +0 -0
  391. swordfish/asset/tzdb/CET +0 -0
  392. swordfish/asset/tzdb/CST6CDT +0 -0
  393. swordfish/asset/tzdb/Canada/Atlantic +0 -0
  394. swordfish/asset/tzdb/Canada/Central +0 -0
  395. swordfish/asset/tzdb/Canada/Eastern +0 -0
  396. swordfish/asset/tzdb/Canada/Mountain +0 -0
  397. swordfish/asset/tzdb/Canada/Newfoundland +0 -0
  398. swordfish/asset/tzdb/Canada/Pacific +0 -0
  399. swordfish/asset/tzdb/Canada/Saskatchewan +0 -0
  400. swordfish/asset/tzdb/Canada/Yukon +0 -0
  401. swordfish/asset/tzdb/Chile/Continental +0 -0
  402. swordfish/asset/tzdb/Chile/EasterIsland +0 -0
  403. swordfish/asset/tzdb/Cuba +0 -0
  404. swordfish/asset/tzdb/EET +0 -0
  405. swordfish/asset/tzdb/EST +0 -0
  406. swordfish/asset/tzdb/EST5EDT +0 -0
  407. swordfish/asset/tzdb/Egypt +0 -0
  408. swordfish/asset/tzdb/Eire +0 -0
  409. swordfish/asset/tzdb/Etc/GMT +0 -0
  410. swordfish/asset/tzdb/Etc/GMT+0 +0 -0
  411. swordfish/asset/tzdb/Etc/GMT+1 +0 -0
  412. swordfish/asset/tzdb/Etc/GMT+10 +0 -0
  413. swordfish/asset/tzdb/Etc/GMT+11 +0 -0
  414. swordfish/asset/tzdb/Etc/GMT+12 +0 -0
  415. swordfish/asset/tzdb/Etc/GMT+2 +0 -0
  416. swordfish/asset/tzdb/Etc/GMT+3 +0 -0
  417. swordfish/asset/tzdb/Etc/GMT+4 +0 -0
  418. swordfish/asset/tzdb/Etc/GMT+5 +0 -0
  419. swordfish/asset/tzdb/Etc/GMT+6 +0 -0
  420. swordfish/asset/tzdb/Etc/GMT+7 +0 -0
  421. swordfish/asset/tzdb/Etc/GMT+8 +0 -0
  422. swordfish/asset/tzdb/Etc/GMT+9 +0 -0
  423. swordfish/asset/tzdb/Etc/GMT-0 +0 -0
  424. swordfish/asset/tzdb/Etc/GMT-1 +0 -0
  425. swordfish/asset/tzdb/Etc/GMT-10 +0 -0
  426. swordfish/asset/tzdb/Etc/GMT-11 +0 -0
  427. swordfish/asset/tzdb/Etc/GMT-12 +0 -0
  428. swordfish/asset/tzdb/Etc/GMT-13 +0 -0
  429. swordfish/asset/tzdb/Etc/GMT-14 +0 -0
  430. swordfish/asset/tzdb/Etc/GMT-2 +0 -0
  431. swordfish/asset/tzdb/Etc/GMT-3 +0 -0
  432. swordfish/asset/tzdb/Etc/GMT-4 +0 -0
  433. swordfish/asset/tzdb/Etc/GMT-5 +0 -0
  434. swordfish/asset/tzdb/Etc/GMT-6 +0 -0
  435. swordfish/asset/tzdb/Etc/GMT-7 +0 -0
  436. swordfish/asset/tzdb/Etc/GMT-8 +0 -0
  437. swordfish/asset/tzdb/Etc/GMT-9 +0 -0
  438. swordfish/asset/tzdb/Etc/GMT0 +0 -0
  439. swordfish/asset/tzdb/Etc/Greenwich +0 -0
  440. swordfish/asset/tzdb/Etc/UCT +0 -0
  441. swordfish/asset/tzdb/Etc/UTC +0 -0
  442. swordfish/asset/tzdb/Etc/Universal +0 -0
  443. swordfish/asset/tzdb/Etc/Zulu +0 -0
  444. swordfish/asset/tzdb/Europe/Amsterdam +0 -0
  445. swordfish/asset/tzdb/Europe/Andorra +0 -0
  446. swordfish/asset/tzdb/Europe/Astrakhan +0 -0
  447. swordfish/asset/tzdb/Europe/Athens +0 -0
  448. swordfish/asset/tzdb/Europe/Belfast +0 -0
  449. swordfish/asset/tzdb/Europe/Belgrade +0 -0
  450. swordfish/asset/tzdb/Europe/Berlin +0 -0
  451. swordfish/asset/tzdb/Europe/Bratislava +0 -0
  452. swordfish/asset/tzdb/Europe/Brussels +0 -0
  453. swordfish/asset/tzdb/Europe/Bucharest +0 -0
  454. swordfish/asset/tzdb/Europe/Budapest +0 -0
  455. swordfish/asset/tzdb/Europe/Busingen +0 -0
  456. swordfish/asset/tzdb/Europe/Chisinau +0 -0
  457. swordfish/asset/tzdb/Europe/Copenhagen +0 -0
  458. swordfish/asset/tzdb/Europe/Dublin +0 -0
  459. swordfish/asset/tzdb/Europe/Gibraltar +0 -0
  460. swordfish/asset/tzdb/Europe/Guernsey +0 -0
  461. swordfish/asset/tzdb/Europe/Helsinki +0 -0
  462. swordfish/asset/tzdb/Europe/Isle_of_Man +0 -0
  463. swordfish/asset/tzdb/Europe/Istanbul +0 -0
  464. swordfish/asset/tzdb/Europe/Jersey +0 -0
  465. swordfish/asset/tzdb/Europe/Kaliningrad +0 -0
  466. swordfish/asset/tzdb/Europe/Kiev +0 -0
  467. swordfish/asset/tzdb/Europe/Kirov +0 -0
  468. swordfish/asset/tzdb/Europe/Lisbon +0 -0
  469. swordfish/asset/tzdb/Europe/Ljubljana +0 -0
  470. swordfish/asset/tzdb/Europe/London +0 -0
  471. swordfish/asset/tzdb/Europe/Luxembourg +0 -0
  472. swordfish/asset/tzdb/Europe/Madrid +0 -0
  473. swordfish/asset/tzdb/Europe/Malta +0 -0
  474. swordfish/asset/tzdb/Europe/Mariehamn +0 -0
  475. swordfish/asset/tzdb/Europe/Minsk +0 -0
  476. swordfish/asset/tzdb/Europe/Monaco +0 -0
  477. swordfish/asset/tzdb/Europe/Moscow +0 -0
  478. swordfish/asset/tzdb/Europe/Nicosia +0 -0
  479. swordfish/asset/tzdb/Europe/Oslo +0 -0
  480. swordfish/asset/tzdb/Europe/Paris +0 -0
  481. swordfish/asset/tzdb/Europe/Podgorica +0 -0
  482. swordfish/asset/tzdb/Europe/Prague +0 -0
  483. swordfish/asset/tzdb/Europe/Riga +0 -0
  484. swordfish/asset/tzdb/Europe/Rome +0 -0
  485. swordfish/asset/tzdb/Europe/Samara +0 -0
  486. swordfish/asset/tzdb/Europe/San_Marino +0 -0
  487. swordfish/asset/tzdb/Europe/Sarajevo +0 -0
  488. swordfish/asset/tzdb/Europe/Saratov +0 -0
  489. swordfish/asset/tzdb/Europe/Simferopol +0 -0
  490. swordfish/asset/tzdb/Europe/Skopje +0 -0
  491. swordfish/asset/tzdb/Europe/Sofia +0 -0
  492. swordfish/asset/tzdb/Europe/Stockholm +0 -0
  493. swordfish/asset/tzdb/Europe/Tallinn +0 -0
  494. swordfish/asset/tzdb/Europe/Tirane +0 -0
  495. swordfish/asset/tzdb/Europe/Tiraspol +0 -0
  496. swordfish/asset/tzdb/Europe/Ulyanovsk +0 -0
  497. swordfish/asset/tzdb/Europe/Uzhgorod +0 -0
  498. swordfish/asset/tzdb/Europe/Vaduz +0 -0
  499. swordfish/asset/tzdb/Europe/Vatican +0 -0
  500. swordfish/asset/tzdb/Europe/Vienna +0 -0
  501. swordfish/asset/tzdb/Europe/Vilnius +0 -0
  502. swordfish/asset/tzdb/Europe/Volgograd +0 -0
  503. swordfish/asset/tzdb/Europe/Warsaw +0 -0
  504. swordfish/asset/tzdb/Europe/Zagreb +0 -0
  505. swordfish/asset/tzdb/Europe/Zaporozhye +0 -0
  506. swordfish/asset/tzdb/Europe/Zurich +0 -0
  507. swordfish/asset/tzdb/Factory +0 -0
  508. swordfish/asset/tzdb/GB +0 -0
  509. swordfish/asset/tzdb/GB-Eire +0 -0
  510. swordfish/asset/tzdb/GMT +0 -0
  511. swordfish/asset/tzdb/GMT+0 +0 -0
  512. swordfish/asset/tzdb/GMT-0 +0 -0
  513. swordfish/asset/tzdb/GMT0 +0 -0
  514. swordfish/asset/tzdb/Greenwich +0 -0
  515. swordfish/asset/tzdb/HST +0 -0
  516. swordfish/asset/tzdb/Hongkong +0 -0
  517. swordfish/asset/tzdb/Iceland +0 -0
  518. swordfish/asset/tzdb/Indian/Antananarivo +0 -0
  519. swordfish/asset/tzdb/Indian/Chagos +0 -0
  520. swordfish/asset/tzdb/Indian/Christmas +0 -0
  521. swordfish/asset/tzdb/Indian/Cocos +0 -0
  522. swordfish/asset/tzdb/Indian/Comoro +0 -0
  523. swordfish/asset/tzdb/Indian/Kerguelen +0 -0
  524. swordfish/asset/tzdb/Indian/Mahe +0 -0
  525. swordfish/asset/tzdb/Indian/Maldives +0 -0
  526. swordfish/asset/tzdb/Indian/Mauritius +0 -0
  527. swordfish/asset/tzdb/Indian/Mayotte +0 -0
  528. swordfish/asset/tzdb/Indian/Reunion +0 -0
  529. swordfish/asset/tzdb/Iran +0 -0
  530. swordfish/asset/tzdb/Israel +0 -0
  531. swordfish/asset/tzdb/Jamaica +0 -0
  532. swordfish/asset/tzdb/Japan +0 -0
  533. swordfish/asset/tzdb/Kwajalein +0 -0
  534. swordfish/asset/tzdb/Libya +0 -0
  535. swordfish/asset/tzdb/MET +0 -0
  536. swordfish/asset/tzdb/MST +0 -0
  537. swordfish/asset/tzdb/MST7MDT +0 -0
  538. swordfish/asset/tzdb/Mexico/BajaNorte +0 -0
  539. swordfish/asset/tzdb/Mexico/BajaSur +0 -0
  540. swordfish/asset/tzdb/Mexico/General +0 -0
  541. swordfish/asset/tzdb/NZ +0 -0
  542. swordfish/asset/tzdb/NZ-CHAT +0 -0
  543. swordfish/asset/tzdb/Navajo +0 -0
  544. swordfish/asset/tzdb/PRC +0 -0
  545. swordfish/asset/tzdb/PST8PDT +0 -0
  546. swordfish/asset/tzdb/Pacific/Apia +0 -0
  547. swordfish/asset/tzdb/Pacific/Auckland +0 -0
  548. swordfish/asset/tzdb/Pacific/Bougainville +0 -0
  549. swordfish/asset/tzdb/Pacific/Chatham +0 -0
  550. swordfish/asset/tzdb/Pacific/Chuuk +0 -0
  551. swordfish/asset/tzdb/Pacific/Easter +0 -0
  552. swordfish/asset/tzdb/Pacific/Efate +0 -0
  553. swordfish/asset/tzdb/Pacific/Enderbury +0 -0
  554. swordfish/asset/tzdb/Pacific/Fakaofo +0 -0
  555. swordfish/asset/tzdb/Pacific/Fiji +0 -0
  556. swordfish/asset/tzdb/Pacific/Funafuti +0 -0
  557. swordfish/asset/tzdb/Pacific/Galapagos +0 -0
  558. swordfish/asset/tzdb/Pacific/Gambier +0 -0
  559. swordfish/asset/tzdb/Pacific/Guadalcanal +0 -0
  560. swordfish/asset/tzdb/Pacific/Guam +0 -0
  561. swordfish/asset/tzdb/Pacific/Honolulu +0 -0
  562. swordfish/asset/tzdb/Pacific/Johnston +0 -0
  563. swordfish/asset/tzdb/Pacific/Kiritimati +0 -0
  564. swordfish/asset/tzdb/Pacific/Kosrae +0 -0
  565. swordfish/asset/tzdb/Pacific/Kwajalein +0 -0
  566. swordfish/asset/tzdb/Pacific/Majuro +0 -0
  567. swordfish/asset/tzdb/Pacific/Marquesas +0 -0
  568. swordfish/asset/tzdb/Pacific/Midway +0 -0
  569. swordfish/asset/tzdb/Pacific/Nauru +0 -0
  570. swordfish/asset/tzdb/Pacific/Niue +0 -0
  571. swordfish/asset/tzdb/Pacific/Norfolk +0 -0
  572. swordfish/asset/tzdb/Pacific/Noumea +0 -0
  573. swordfish/asset/tzdb/Pacific/Pago_Pago +0 -0
  574. swordfish/asset/tzdb/Pacific/Palau +0 -0
  575. swordfish/asset/tzdb/Pacific/Pitcairn +0 -0
  576. swordfish/asset/tzdb/Pacific/Pohnpei +0 -0
  577. swordfish/asset/tzdb/Pacific/Ponape +0 -0
  578. swordfish/asset/tzdb/Pacific/Port_Moresby +0 -0
  579. swordfish/asset/tzdb/Pacific/Rarotonga +0 -0
  580. swordfish/asset/tzdb/Pacific/Saipan +0 -0
  581. swordfish/asset/tzdb/Pacific/Samoa +0 -0
  582. swordfish/asset/tzdb/Pacific/Tahiti +0 -0
  583. swordfish/asset/tzdb/Pacific/Tarawa +0 -0
  584. swordfish/asset/tzdb/Pacific/Tongatapu +0 -0
  585. swordfish/asset/tzdb/Pacific/Truk +0 -0
  586. swordfish/asset/tzdb/Pacific/Wake +0 -0
  587. swordfish/asset/tzdb/Pacific/Wallis +0 -0
  588. swordfish/asset/tzdb/Pacific/Yap +0 -0
  589. swordfish/asset/tzdb/Poland +0 -0
  590. swordfish/asset/tzdb/Portugal +0 -0
  591. swordfish/asset/tzdb/ROC +0 -0
  592. swordfish/asset/tzdb/ROK +0 -0
  593. swordfish/asset/tzdb/Singapore +0 -0
  594. swordfish/asset/tzdb/Turkey +0 -0
  595. swordfish/asset/tzdb/UCT +0 -0
  596. swordfish/asset/tzdb/US/Alaska +0 -0
  597. swordfish/asset/tzdb/US/Aleutian +0 -0
  598. swordfish/asset/tzdb/US/Arizona +0 -0
  599. swordfish/asset/tzdb/US/Central +0 -0
  600. swordfish/asset/tzdb/US/East-Indiana +0 -0
  601. swordfish/asset/tzdb/US/Eastern +0 -0
  602. swordfish/asset/tzdb/US/Hawaii +0 -0
  603. swordfish/asset/tzdb/US/Indiana-Starke +0 -0
  604. swordfish/asset/tzdb/US/Michigan +0 -0
  605. swordfish/asset/tzdb/US/Mountain +0 -0
  606. swordfish/asset/tzdb/US/Pacific +0 -0
  607. swordfish/asset/tzdb/US/Samoa +0 -0
  608. swordfish/asset/tzdb/UTC +0 -0
  609. swordfish/asset/tzdb/Universal +0 -0
  610. swordfish/asset/tzdb/W-SU +0 -0
  611. swordfish/asset/tzdb/WET +0 -0
  612. swordfish/asset/tzdb/Zulu +0 -0
  613. swordfish/asset/tzdb/iso3166.tab +274 -0
  614. swordfish/asset/tzdb/leapseconds +61 -0
  615. swordfish/asset/tzdb/posixrules +0 -0
  616. swordfish/asset/tzdb/tzdata.zi +4150 -0
  617. swordfish/asset/tzdb/tzmap_gen.py +27 -0
  618. swordfish/asset/tzdb/tzmapping +501 -0
  619. swordfish/asset/tzdb/windowsZones.xml +781 -0
  620. swordfish/asset/tzdb/zone.tab +448 -0
  621. swordfish/asset/tzdb/zone1970.tab +382 -0
  622. swordfish/connection.py +33 -0
  623. swordfish/data.py +806 -0
  624. swordfish/engine.py +28 -0
  625. swordfish/enums.py +32 -0
  626. swordfish/function.py +3 -0
  627. swordfish/infos.py +53 -0
  628. swordfish/io.py +11 -0
  629. swordfish/libSwordfish.dll +0 -0
  630. swordfish/libclucene-contribs-lib.dll +0 -0
  631. swordfish/libclucene-core.dll +0 -0
  632. swordfish/libclucene-shared.dll +0 -0
  633. swordfish/libgcc_s_seh-1.dll +0 -0
  634. swordfish/libstdc++-6.dll +0 -0
  635. swordfish/libwinpthread-1.dll +0 -0
  636. swordfish/module.py +57 -0
  637. swordfish/plugins/__init__.py +17 -0
  638. swordfish/plugins/backtest/__init__.py +38 -0
  639. swordfish/plugins/backtest/backtest.py +4228 -0
  640. swordfish/plugins/backtest/translator.py +820 -0
  641. swordfish/plugins/matching_engine_simulator.py +247 -0
  642. swordfish/streaming.py +19 -0
  643. swordfish/tools.py +71 -0
  644. swordfish/types.py +30 -0
@@ -0,0 +1,820 @@
1
+ from . import backtest
2
+
3
+ from ..._swordfishcpp import ( # type: ignore
4
+ ProgrammingError,
5
+ FunctionDef,
6
+ Constant,
7
+ check_is_nothing,
8
+ )
9
+
10
+ from ..._translator import (
11
+ Variable, VariableMode, VariableFrame,
12
+ StandardVisitor,
13
+ )
14
+
15
+ from ..._connection import connect as sf_connect
16
+
17
+ from ...data import (
18
+ dictionary as sf_dictionary,
19
+ DFLT as sf_DFLT,
20
+ create_partial,
21
+ )
22
+
23
+ from ... import data as sf_data
24
+
25
+ import ast
26
+ import inspect
27
+ import warnings
28
+ import sys
29
+
30
+ from types import FunctionType, FrameType
31
+ from typing import (
32
+ List, Union, Dict,
33
+ )
34
+
35
+ AccountType = backtest.AccountType
36
+ MarketDataType = backtest.MarketDataType
37
+
38
+
39
+ class FakeVariable(Variable):
40
+ def __init__(self, data=None):
41
+ super().__init__(data, VariableMode.FAKE)
42
+
43
+ def dot(self, o):
44
+ raise ProgrammingError("Cannot use self directly.")
45
+
46
+ def at(self, o):
47
+ raise ProgrammingError("Cannot use self directly.")
48
+
49
+ def call(self, args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
50
+ raise ProgrammingError("Cannot use self directly.")
51
+
52
+ def process(self, visitor):
53
+ raise ProgrammingError("Cannot use self directly.")
54
+
55
+
56
+ class TupleVariable(FakeVariable):
57
+ def __init__(self, data):
58
+ super().__init__(data)
59
+
60
+ def process(self, visitor):
61
+ return f"""({','.join([process(v, visitor) for v in self.data])})"""
62
+
63
+
64
+ class LiteralVariable(FakeVariable):
65
+ def __init__(self, data: str):
66
+ super().__init__(data)
67
+
68
+ def process(self, visitor):
69
+ return self.data
70
+
71
+
72
+ class DecorateArg(FakeVariable):
73
+ def __init__(self, real: Variable, type_method: str, type_args: List[str] = None):
74
+ super().__init__(real)
75
+ self.type_method = type_method
76
+ self.type_args = type_args or []
77
+
78
+ def process(self, visitor):
79
+ if isinstance(self.data, Variable):
80
+ var_str = self.data.process(visitor)
81
+ else:
82
+ var_str = str(self.data)
83
+ if self.type_args:
84
+ args_str = ", ".join(self.type_args)
85
+ return f"{self.type_method}({var_str}, {args_str})"
86
+ else:
87
+ return f"{self.type_method}({var_str})"
88
+
89
+
90
+ class AccountTypeVariable(FakeVariable):
91
+ def __init__(self, kind: AccountType):
92
+ super().__init__(kind)
93
+
94
+ def process(self, visitor):
95
+ return f'''"{self.data.value}"'''
96
+
97
+
98
+ class MarketDataTypeVariable(FakeVariable):
99
+ def __init__(self, kind: backtest.MarketDataType):
100
+ super().__init__(kind)
101
+
102
+ def process(self, visitor):
103
+ return f'''"{self.data.value}"'''
104
+
105
+
106
+ def _check_enum_type(v: Variable):
107
+ if isinstance(v, Variable) and v.mode == VariableMode.PYTHON:
108
+ if isinstance(v.data, AccountType):
109
+ return AccountTypeVariable(v.data)
110
+ if isinstance(v.data, backtest.MarketDataType):
111
+ return MarketDataTypeVariable(v.data)
112
+ return v
113
+
114
+
115
+ def _wrapper_submit_order(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
116
+ py_args = ["msg"]
117
+ py_kwargs = ["label", "order_type", "account_type"]
118
+ real_order = ["msg", "label", "order_type", "account_type"]
119
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
120
+ result = arg_map.apply(args, kwargs)
121
+ return result
122
+
123
+
124
+ def _wrapper_submit_limit_tp_sl_order(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
125
+ py_args = [
126
+ "code", "exchange", "time", "order_type", "order_price", "stop_loss_price",
127
+ "take_profit_price", "quantity", "direct", "slippage", "order_validity", "expiration_time"
128
+ ]
129
+ py_kwargs = ["label", "account_type"]
130
+ real_order = py_args + py_kwargs
131
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
132
+ result = arg_map.apply(args, kwargs)
133
+ return [TupleVariable(result[:12])] + result[12:13] + [LiteralVariable("5")] + result[13:]
134
+
135
+
136
+ def _wrapper_submit_market_tp_sl_order(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
137
+ py_args = [
138
+ "code", "exchange", "time", "order_type", "order_price", "stop_loss_price",
139
+ "take_profit_price", "quantity", "direct", "slippage", "order_validity", "expiration_time"
140
+ ]
141
+ py_kwargs = ["label", "account_type"]
142
+ real_order = py_args + py_kwargs
143
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
144
+ result = arg_map.apply(args, kwargs)
145
+ return [TupleVariable(result[:12])] + result[12:13] + [LiteralVariable("6")] + result[13:]
146
+
147
+
148
+ def _wrapper_submit_ask_bid_order(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
149
+ py_args = [
150
+ "code",
151
+ "exchange",
152
+ "time",
153
+ "order_type",
154
+ "bid_offset_flag",
155
+ "bid_price",
156
+ "bid_qty",
157
+ "ask_offset_flag",
158
+ "ask_price",
159
+ "ask_qty",
160
+ "bid_difftolerance",
161
+ "ask_difftolerance",
162
+ "quantity_allowed",
163
+ ]
164
+ py_kwargs = ["label", "account_type"]
165
+ real_order = py_args + py_kwargs
166
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
167
+ result = arg_map.apply(args, kwargs)
168
+ return [TupleVariable(result[:13])] + result[13:14] + [LiteralVariable("8")] + result[14:]
169
+
170
+
171
+ def _wrapper_submit_auto_order(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
172
+ py_args = [
173
+ "code",
174
+ "exchange",
175
+ "time",
176
+ "order_type",
177
+ "order_price",
178
+ "stop_price",
179
+ "quantity",
180
+ "direct",
181
+ "order_validity",
182
+ ]
183
+ py_kwargs = ["label", "account_type"]
184
+ real_order = py_args + py_kwargs
185
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
186
+ result = arg_map.apply(args, kwargs)
187
+ return [TupleVariable(result[:9])] + result[9:10] + [LiteralVariable("9")] + result[10:]
188
+
189
+
190
+ def _wrapper_cancel_order(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
191
+ py_args = []
192
+ py_kwargs = ["symbol", "orders", "label"]
193
+ real_order = py_args + py_kwargs
194
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
195
+ result = arg_map.apply(args, kwargs)
196
+ return result
197
+
198
+
199
+ def _wrapper_get_open_orders(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
200
+ py_args = []
201
+ py_kwargs = ["symbol", "orders", "label", "output_queue_position"]
202
+ real_order = py_args + py_kwargs
203
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
204
+ result = arg_map.apply(args, kwargs)
205
+ return result
206
+
207
+
208
+ def _wrapper_update_position(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
209
+ py_args = ["symbol", "quantity"]
210
+ py_kwargs = ["price"]
211
+ real_order = py_args + py_kwargs
212
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
213
+ result = arg_map.apply(args, kwargs)
214
+ return result
215
+
216
+
217
+ def _wrapper_subscribe_indicator(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
218
+ py_args = ["market_type", "metrics"]
219
+ py_kwargs = ["account_type"]
220
+ real_order = py_args + py_kwargs
221
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
222
+ result = arg_map.apply(args, kwargs)
223
+ return result
224
+
225
+
226
+ def _wrapper_submit_stock_order(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
227
+ py_args = ["code", "time", "order_type", "order_price", "quantity", "direct"]
228
+ py_kwargs = ["label", "account_type"]
229
+ real_order = ["code", "time", "order_type", "order_price", "quantity", "direct", "label", "account_type"]
230
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
231
+ result = arg_map.apply(args, kwargs)
232
+ return [TupleVariable(result[:6])] + result[6:7] + [LiteralVariable("0")] + result[7:]
233
+
234
+
235
+ def _wrapper_get_today_pnl(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
236
+ py_args = ["symbol"]
237
+ py_kwargs = []
238
+ real_order = py_args + py_kwargs
239
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
240
+ result = arg_map.apply(args, kwargs)
241
+ return result
242
+
243
+
244
+ def _wrapper_submit_futures_order(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
245
+ py_args = ["code", "exchange", "time", "order_type", "order_price", "stop_price", "quantity", "direct", "order_validity"]
246
+ py_kwargs = ["label", "account_type"]
247
+ real_order = py_args + py_kwargs
248
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
249
+ result = arg_map.apply(args, kwargs)
250
+ return [TupleVariable(result[:9])] + result[9:10] + [LiteralVariable("0")] + result[10:]
251
+
252
+
253
+ def _wrapper_submit_option_order(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
254
+ py_args = ["code", "exchange", "time", "order_type", "order_price", "stop_price", "quantity", "direct", "order_validity"]
255
+ py_kwargs = ["label", "account_type"]
256
+ real_order = py_args + py_kwargs
257
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
258
+ result = arg_map.apply(args, kwargs)
259
+ return [TupleVariable(result[:9])] + result[9:10] + [LiteralVariable("0")] + result[10:]
260
+
261
+
262
+ def _wrapper_submit_margin_order(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
263
+ py_args = ["code", "time", "order_type", "order_price", "quantity", "direct"]
264
+ py_kwargs = ["label", "account_type"]
265
+ real_order = py_args + py_kwargs
266
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
267
+ result = arg_map.apply(args, kwargs)
268
+ return [TupleVariable(result[:6])] + result[6:7] + [LiteralVariable("0")] + result[7:]
269
+
270
+
271
+ def _wrapper_get_margin_secu_position(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
272
+ py_args = []
273
+ py_kwargs = ["symbols"]
274
+ real_order = py_args + py_kwargs
275
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
276
+ result = arg_map.apply(args, kwargs)
277
+ return result
278
+
279
+
280
+ def _wrapper_get_margin_trading_position(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
281
+ py_args = []
282
+ py_kwargs = ["symbols"]
283
+ real_order = py_args + py_kwargs
284
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
285
+ result = arg_map.apply(args, kwargs)
286
+ return result
287
+
288
+
289
+ def _wrapper_get_secu_lending_position(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
290
+ py_args = []
291
+ py_kwargs = ["symbols"]
292
+ real_order = py_args + py_kwargs
293
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
294
+ result = arg_map.apply(args, kwargs)
295
+ return result
296
+
297
+
298
+ def _wrapper_submit_bond_order(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
299
+ py_args = ["code", "time", "order_type", "settlement_speed", "bid_price", "bid_quantity", "ask_price", "ask_quantity", "direct", "order_id", "channel"]
300
+ py_kwargs = ["label", "account_type"]
301
+ real_order = py_args + py_kwargs
302
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
303
+ result = arg_map.apply(args, kwargs)
304
+ return [TupleVariable(result[:11])] + result[11:12] + [LiteralVariable("0")] + result[12:]
305
+
306
+
307
+ def _wrapper_submit_crypto_order(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
308
+ py_args = ["code", "exchange", "time", "order_type", "order_price", "stop_loss_price", "take_profit_price", "quantity", "direct", "slippage", "order_validity", "expiration_time"]
309
+ py_kwargs = ["label", "account_type"]
310
+ real_order = py_args + py_kwargs
311
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
312
+ result = arg_map.apply(args, kwargs)
313
+ return [TupleVariable(result[:12])] + result[12:13] + [LiteralVariable("0")] + result[13:]
314
+
315
+
316
+ def _wrapper_get_position(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
317
+ py_args = []
318
+ py_kwargs = ["symbol"]
319
+ real_order = ["symbol"]
320
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
321
+ return arg_map.apply(args, kwargs)
322
+
323
+
324
+ def _wrapper_set_position(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
325
+ py_args = ["symbol", "qty", "order_price"]
326
+ py_kwargs = ["last_price"]
327
+ real_order = py_args + py_kwargs
328
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
329
+ result = arg_map.apply(args, kwargs)
330
+ result[1] = DecorateArg(result[1], "long")
331
+ return result
332
+
333
+
334
+ def _wrapper_get_daily_position(args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
335
+ py_args = []
336
+ py_kwargs = ["symbol"]
337
+ real_order = ["symbol"]
338
+ arg_map = ArgsMap(py_args, py_kwargs, real_order)
339
+ return arg_map.apply(args, kwargs)
340
+
341
+
342
+ class SelfVariable(FakeVariable):
343
+ """Self is StrategyTemplate.
344
+ """
345
+ def __init__(self, self_name: str, context_name: str):
346
+ self.self_name = self_name
347
+ super().__init__(f"""{context_name}["engine"]""")
348
+
349
+ def dot(self, o: str):
350
+ if o == "accounts":
351
+ return AccountsVariable(self)
352
+ if o == "submit_order":
353
+ return FunctionVariable(backtest.plugin_backtest_submitOrder, _wrapper_submit_order, self)
354
+ if o == "submit_limit_tp_sl_order":
355
+ return FunctionVariable(backtest.plugin_backtest_submitOrder, _wrapper_submit_limit_tp_sl_order, self)
356
+ if o == "submit_market_tp_sl_order":
357
+ return FunctionVariable(backtest.plugin_backtest_submitOrder, _wrapper_submit_market_tp_sl_order, self)
358
+ if o == "submit_ask_bid_order":
359
+ return FunctionVariable(backtest.plugin_backtest_submitOrder, _wrapper_submit_ask_bid_order, self)
360
+ if o == "submit_auto_order":
361
+ return FunctionVariable(backtest.plugin_backtest_submitOrder, _wrapper_submit_auto_order, self)
362
+ if o == "cancel_order":
363
+ return FunctionVariable(backtest.plugin_backtest_cancelOrder, _wrapper_cancel_order, self)
364
+ if o == "get_open_orders":
365
+ return FunctionVariable(backtest.plugin_backtest_backtestGetOpenOrders, _wrapper_get_open_orders, self)
366
+ if o == "update_position":
367
+ return FunctionVariable(backtest.plugin_backtest_updatePosition, _wrapper_update_position, self)
368
+ if o == "universe":
369
+ return AttributeVariable(None, backtest.plugin_backtest_setUniverse, self)
370
+ if o == "subscribe_indicator":
371
+ return FunctionVariable(backtest.plugin_backtest_subscribeIndicator, _wrapper_subscribe_indicator, self)
372
+ if o == "submit_stock_order":
373
+ return FunctionVariable(backtest.plugin_backtest_submitOrder, _wrapper_submit_stock_order, self)
374
+ if o == "get_today_pnl":
375
+ return FunctionVariable(backtest.plugin_backtest_getTodayPnl, _wrapper_get_today_pnl, self)
376
+ if o == "stock_total_portfolios":
377
+ return AttributeVariable(backtest.plugin_backtest_getStockTotalPortfolios, None, self)
378
+ if o == "submit_futures_order":
379
+ return FunctionVariable(backtest.plugin_backtest_submitOrder, _wrapper_submit_futures_order, self)
380
+ if o == "futures_total_portfolios":
381
+ return AttributeVariable(backtest.plugin_backtest_getFuturesTotalPortfolios, None, self)
382
+ if o == "submit_option_order":
383
+ return FunctionVariable(backtest.plugin_backtest_submitOrder, _wrapper_submit_option_order, self)
384
+ if o == "option_total_portfolios":
385
+ return AttributeVariable(backtest.plugin_backtest_getOptionTotalPortfolios, None, self)
386
+ if o == "submit_margin_order":
387
+ return FunctionVariable(backtest.plugin_backtest_submitOrder, _wrapper_submit_margin_order, self)
388
+ if o == "get_margin_secu_position":
389
+ return FunctionVariable(backtest.plugin_backtest_getMarginSecuPosition, _wrapper_get_margin_secu_position, self)
390
+ if o == "get_margin_trading_position":
391
+ return FunctionVariable(backtest.plugin_backtest_getMarginTradingPosition, _wrapper_get_margin_trading_position, self)
392
+ if o == "get_secu_lending_position":
393
+ return FunctionVariable(backtest.plugin_backtest_getSecuLendingPosition, _wrapper_get_secu_lending_position, self)
394
+ if o == "submit_bond_order":
395
+ return FunctionVariable(backtest.plugin_backtest_submitOrder, _wrapper_submit_bond_order, self)
396
+ if o == "submit_crypto_order":
397
+ return FunctionVariable(backtest.plugin_backtest_submitOrder, _wrapper_submit_crypto_order, self)
398
+ raise ProgrammingError("Unsupported self method: ", o)
399
+
400
+ def process(self, visitor):
401
+ return self.data
402
+
403
+
404
+ class DefaultVariable(FakeVariable):
405
+ def __init__(self):
406
+ super().__init__()
407
+
408
+ def process(self, visitor):
409
+ return " "
410
+
411
+
412
+ class ArgsMap(dict):
413
+ def __init__(self, args, kwargs, orders):
414
+ super().__init__()
415
+ params = []
416
+ for arg in args:
417
+ params.append(inspect.Parameter(arg, kind=inspect.Parameter.POSITIONAL_OR_KEYWORD))
418
+ for arg in kwargs:
419
+ params.append(inspect.Parameter(arg, kind=inspect.Parameter.POSITIONAL_OR_KEYWORD, default=DefaultVariable()))
420
+ self.sig = inspect.Signature(params)
421
+ self.orders = orders
422
+
423
+ def apply(self, args, kwargs):
424
+ bound = self.sig.bind(*args, **kwargs)
425
+ bound.apply_defaults()
426
+ result = {
427
+ v: None for v in self.orders
428
+ }
429
+ for k, v in bound.arguments.items():
430
+ result[k] = v
431
+ return [_ for _ in result.values()]
432
+
433
+
434
+ class FunctionVariable(FakeVariable):
435
+ def __init__(self, func: FunctionDef, args_wrapper: FunctionType, self_var: SelfVariable):
436
+ self.args_wrapper = args_wrapper
437
+ self.func = func
438
+ self.self_var = self_var
439
+ super().__init__(func)
440
+
441
+ def call(self, args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
442
+ # F(args, kwargs)
443
+ return FunctionCallVariable(self, self.args_wrapper(args, kwargs), self.self_var)
444
+
445
+
446
+ class FunctionCallVariable(FakeVariable):
447
+ def __init__(self, func: FunctionVariable, args, self_var: SelfVariable):
448
+ self.func = func
449
+ self.args = args
450
+ self.self_var = self_var
451
+ super().__init__()
452
+
453
+ def process(self, visitor: StandardVisitor):
454
+ name = visitor.update_argvar(self.func)
455
+ if self.args:
456
+ arg_str = ", ".join([process(v, visitor) for v in self.args])
457
+ return f"{name}({self.self_var.data}, {arg_str})"
458
+ else:
459
+ return f"{name}({self.self_var.data})"
460
+
461
+
462
+ class AttributeVariable(FakeVariable):
463
+ def __init__(self, getter: FunctionDef, setter: FunctionDef, self_var: SelfVariable):
464
+ self.getter = getter
465
+ self.setter = setter
466
+ self.self_var = self_var
467
+ super().__init__()
468
+
469
+ def assign(self, value: Variable):
470
+ # self.attr = value
471
+ return AttributeAssignVariable(self, value, self.self_var)
472
+
473
+ def process(self, visitor):
474
+ if self.getter is None:
475
+ raise ProgrammingError("Unsupported get attribute.")
476
+ name = visitor.update_argvar(Variable(self.getter, VariableMode.PYTHON))
477
+ return f"{name}({self.self_var.data})"
478
+
479
+
480
+ class AttributeAssignVariable(FakeVariable):
481
+ def __init__(self, attr: AttributeVariable, value: Variable, self_var: SelfVariable):
482
+ self.attr = attr
483
+ self.value = value
484
+ self.self_var = self_var
485
+ super().__init__()
486
+
487
+ def process(self, visitor):
488
+ if self.setter is None:
489
+ raise ProgrammingError("Unsupported set attribute.")
490
+ name = visitor.update_argvar(Variable(self.attr.setter, VariableMode.PYTHON))
491
+ return f"{name}({self.self_var.data}, {process(self.value, visitor)})"
492
+
493
+
494
+ class AccountsVariable(FakeVariable):
495
+ def __init__(self, self_var):
496
+ super().__init__()
497
+ self.self_var = self_var
498
+
499
+ def at(self, o: Union[Variable, str]):
500
+ if isinstance(o, Variable) and o.mode == VariableMode.PYTHON:
501
+ o = o.data
502
+ if isinstance(o, str):
503
+ o = AccountType(o)
504
+ if isinstance(o, AccountType):
505
+ o = AccountTypeVariable(o)
506
+ return ExactAccountVariable(o, self.self_var)
507
+
508
+
509
+ class ExactAccountVariable(FakeVariable):
510
+ def __init__(self, kind: AccountTypeVariable, self_var: SelfVariable):
511
+ super().__init__(kind)
512
+ self.self_var = self_var
513
+
514
+ def dot(self, o: str):
515
+ # self.accounts[AccountType].#o
516
+ if o == "cash":
517
+ return ExactAccountAttributeVariable(backtest.plugin_backtest_getAvailableCash, None, self)
518
+ if o == "trade_details":
519
+ return ExactAccountAttributeVariable(backtest.plugin_backtest_getTradeDetails, None, self)
520
+ if o == "get_position":
521
+ return ExactAccountFunctionVariable(backtest.plugin_backtest_getPosition, _wrapper_get_position, self)
522
+ if o == "set_position":
523
+ return ExactAccountFunctionVariable(backtest.plugin_backtest_setPosition, _wrapper_set_position, self)
524
+ if o == "get_daily_position":
525
+ return ExactAccountFunctionVariable(backtest.plugin_backtest_getDailyPosition, _wrapper_get_daily_position, self)
526
+ if o == "total_portfolios":
527
+ return ExactAccountAttributeVariable(backtest.plugin_backtest_getTotalPortfolios, None, self)
528
+ if o == "daily_total_portfolios":
529
+ return ExactAccountAttributeVariable(backtest.plugin_backtest_getDailyTotalPortfolios, None, self)
530
+ if o == "return_summary":
531
+ return ExactAccountAttributeVariable(backtest.plugin_backtest_getReturnSummary, None, self)
532
+ raise ProgrammingError("Unsupported account method: ", o)
533
+
534
+
535
+ class ExactAccountAttributeVariable(AttributeVariable):
536
+ def __init__(self, getter: FunctionDef, setter: FunctionDef, account: ExactAccountVariable):
537
+ super().__init__(getter, setter, account.self_var)
538
+ self.account = account
539
+
540
+ def assign(self, value: Variable):
541
+ raise ProgrammingError("Unsupported set account attribute.")
542
+
543
+ def process(self, visitor):
544
+ name = visitor.update_argvar(Variable(self.getter, VariableMode.PYTHON))
545
+ if self.account.data.data == AccountType.DEFAULT:
546
+ return f"{name}({self.self_var.data})"
547
+ else:
548
+ return f"{name}({self.self_var.data}, {process(self.account.data, visitor)})"
549
+
550
+
551
+ class ExactAccountFunctionVariable(FunctionVariable):
552
+ def __init__(self, func: FunctionDef, args_wrapper, account: ExactAccountVariable):
553
+ super().__init__(func, args_wrapper, account.self_var)
554
+ self.account = account
555
+
556
+ def call(self, args: List[Union[str, Variable]], kwargs: Dict[str, Union[str, Variable]]):
557
+ # F(args, kwargs)
558
+ return ExactAccountFunctionCallVariable(self, self.args_wrapper(args, kwargs), self.account)
559
+
560
+
561
+ class ExactAccountFunctionCallVariable(FunctionCallVariable):
562
+ def __init__(self, func: ExactAccountFunctionVariable, args, account: ExactAccountVariable):
563
+ super().__init__(func, args, account.self_var)
564
+ self.account = account
565
+
566
+ def process(self, visitor):
567
+ name = visitor.update_argvar(self.func)
568
+ if self.args:
569
+ args_str = ", ".join([process(v, visitor) for v in self.args])
570
+ if self.account.data.data == AccountType.DEFAULT:
571
+ if self.args:
572
+ return f"{name}({self.self_var.data}, {args_str})"
573
+ else:
574
+ return f"{name}({self.self_var.data})"
575
+ if self.args:
576
+ return f"{name}({self.self_var.data}, {args_str}, {process(self.account.data, visitor)})"
577
+ else:
578
+ return f"{name}({self.self_var.data}, {process(self.account.data, visitor)})"
579
+
580
+
581
+ def process(data, visitor) -> str:
582
+ if isinstance(data, Variable):
583
+ return data.process(visitor)
584
+ return str(data)
585
+
586
+
587
+ class MethodVisitor(StandardVisitor):
588
+ def __init__(self):
589
+ super().__init__()
590
+
591
+ def add_arguments(self, node):
592
+ if node.posonlyargs:
593
+ raise ValueError("Unsupported position only arguments.")
594
+ if node.kwonlyargs or node.kw_defaults:
595
+ raise ValueError("Unsupported keyword only arguments.")
596
+ args = [arg.arg for arg in node.args]
597
+ self_name = args[0]
598
+ self.self_var = SelfVariable(self_name, args[1])
599
+ args = set(args[1:])
600
+ frame = VariableFrame.createArgsFrame(args)
601
+ frame.update(self_name, self.self_var)
602
+ self.stack.push(frame)
603
+
604
+ def visit_arguments(self, node: ast.arguments):
605
+ if node.posonlyargs:
606
+ raise ValueError("Unsupported position only arguments.")
607
+ if node.kwonlyargs or node.kw_defaults:
608
+ raise ValueError("Unsupported keyword only arguments.")
609
+ all_args_len = len(node.args)
610
+ all_defaults_len = len(node.defaults)
611
+ index = 0
612
+ arg_statements = []
613
+ defaults = node.defaults
614
+ non_defaults = all_args_len - all_defaults_len
615
+ for arg in node.args:
616
+ if index < non_defaults:
617
+ arg_statements.append(arg.arg)
618
+ else:
619
+ arg_statements.append(f"{arg.arg} = {process(self.visit(defaults[index - non_defaults]), self)}")
620
+ index += 1
621
+ if not arg_statements:
622
+ return []
623
+ return arg_statements
624
+
625
+ def visit_Subscript(self, node: ast.Subscript):
626
+ value: Variable = self.visit(node.value) # a[1][2] -> subscript(subscript)
627
+ if isinstance(node.ctx, ast.Store):
628
+ if value.mode == VariableMode.PYTHON:
629
+ raise ValueError("Unsupported subscript assign.")
630
+ slice = self.visit(node.slice)
631
+ if isinstance(value, Variable) and value.mode == VariableMode.FAKE:
632
+ value: FakeVariable
633
+ return value.at(slice)
634
+ return f"{process(value, self)}[{process(slice, self)}]"
635
+
636
+ def visit_Name(self, node):
637
+ re = super().visit_Name(node)
638
+ return _check_enum_type(re)
639
+
640
+ def visit_Attribute(self, node):
641
+ re = super().visit_Attribute(node)
642
+ return _check_enum_type(re)
643
+
644
+ def visit_Call(self, node: ast.Call):
645
+ func: Variable = self.visit(node.func)
646
+ func_str = ""
647
+ if func.mode == VariableMode.PYTHON:
648
+ if isinstance(func.data, Constant):
649
+ func_str = process(func, self)
650
+ else:
651
+ raise ValueError("Unsupport other python variables.")
652
+ elif func.mode == VariableMode.SWORDFISH:
653
+ func_str = process(func, self)
654
+ elif func.mode == VariableMode.FAKE:
655
+ func: FakeVariable
656
+ args = [process(self.visit(_arg), self) for _arg in node.args]
657
+ kwargs = {k.arg: process(self.visit(k.value), self) for k in node.keywords}
658
+ func_call = func.call(args, kwargs)
659
+ return process(func_call, self)
660
+ else:
661
+ raise ValueError("Invalid variable mode.")
662
+ args = [process(self.visit(_arg), self) for _arg in node.args]
663
+ kwargs = [f"{k.arg}={process(self.visit(k.value), self)}" for k in node.keywords]
664
+ all_args = ",".join(args + kwargs)
665
+ return f"{func_str}({all_args})"
666
+
667
+ def visit_Assign(self, node: ast.Assign):
668
+ value = self.visit(node.value)
669
+ target_str: str = ""
670
+ for target in node.targets:
671
+ tmp_str: str
672
+ if isinstance(target, ast.Tuple):
673
+ lefts = [self.visit(sub_node) for sub_node in target.elts]
674
+ for left in lefts:
675
+ if isinstance(left, AttributeVariable):
676
+ raise ProgrammingError("Unsupported multi assign with self attribute.")
677
+ value_str = process(self.visit(node.value), self)
678
+ tmp_str = ", ".join([process(left, self) for left in lefts])
679
+ target_str += f"{tmp_str} = {value_str};\n"
680
+ elif isinstance(target, ast.Name) or isinstance(target, ast.Subscript):
681
+ left = self.visit(target)
682
+ if isinstance(left, AttributeVariable):
683
+ tmp = left.assign(value)
684
+ target_str += f"{process(tmp, self)};\n"
685
+ else:
686
+ value_str = process(self.visit(node.value), self)
687
+ tmp_str = process(self.visit(target), self)
688
+ target_str += f"{tmp_str} = {value_str};\n"
689
+ else:
690
+ raise RuntimeError("Unsupport Assign target.")
691
+ return target_str
692
+
693
+
694
+ class BacktestVisitor(MethodVisitor):
695
+ def __init__(self, cls, frame: FrameType):
696
+ super().__init__()
697
+ self.stack.push(VariableFrame(frame.f_globals))
698
+ self.stack.push(VariableFrame(frame.f_locals))
699
+ self.callback_d = sf_dictionary(key_type="STRING", val_type="ANY")
700
+ self.on_timer_d = sf_dictionary(key_type="SECOND", val_type="ANY")
701
+ self.callback_d["onTimer"] = self.on_timer_d
702
+ self.class_obj = cls
703
+
704
+ _callback_map = {
705
+ 'on_tick': 'onTick',
706
+ 'on_snapshot': 'onSnapshot',
707
+ 'on_bar': 'onBar',
708
+ 'on_transaction': 'onTransaction',
709
+ 'on_order': 'onOrder',
710
+ }
711
+
712
+ def generate_functiondef(self, node):
713
+ method_visitor = MethodVisitor()
714
+ method_visitor.stack = self.stack
715
+ method_visitor.add_arguments(node.args)
716
+ self.stack.push()
717
+ args = method_visitor.visit_arguments(node.args)
718
+ args = args[1:]
719
+ args[0] = "mutable " + args[0]
720
+
721
+ lines = []
722
+ for stmt in node.body:
723
+ line = method_visitor.visit(stmt)
724
+ lines.append(line)
725
+
726
+ vars_args = list(method_visitor.var_dict.keys())
727
+ args_str = ",".join(vars_args + args)
728
+
729
+ function_code = f"""
730
+ def ({args_str}) {{
731
+ {"".join(lines)}
732
+ }}
733
+ """
734
+ functiondef = FunctionDef(function_code)
735
+ args = list(method_visitor.var_dict.values())
736
+ if args:
737
+ args = [sf_DFLT if isinstance(arg, Constant) and check_is_nothing(arg) else arg for arg in args]
738
+ functiondef = create_partial(functiondef, *args)
739
+ self.stack.pop()
740
+ self.stack.pop()
741
+ return functiondef
742
+
743
+ def visit_FunctionDef(self, node):
744
+ if node.name in self.class_obj._timer_funcs:
745
+ # on_timer
746
+ functiondef = self.generate_functiondef(node)
747
+ trigger_time = self.class_obj._timer_funcs[node.name]
748
+ if isinstance(trigger_time, sf_data.Vector):
749
+ for t in trigger_time:
750
+ self.on_timer_d[t] = functiondef
751
+ else:
752
+ self.on_timer_d[trigger_time] = functiondef
753
+ else:
754
+ all_methods = dir(backtest.StrategyInterface)
755
+ all_methods = [m for m in all_methods if not m.startswith('__') and not m.endswith('__')]
756
+
757
+ if node.name not in all_methods:
758
+ return
759
+ if node.name not in self._callback_map:
760
+ return
761
+
762
+ functiondef = self.generate_functiondef(node)
763
+ self.callback_d[self._callback_map[node.name]] = functiondef
764
+
765
+
766
+ class ContextVisitor(StandardVisitor):
767
+ def __init__(self, cls, frame: FrameType):
768
+ super().__init__()
769
+ self.stack.push(VariableFrame(frame.f_globals))
770
+ self.stack.push(VariableFrame(frame.f_locals))
771
+ self.context = sf_dictionary(key_type="STRING", val_type="ANY")
772
+
773
+ def visit_Assign(self, node: ast.Assign):
774
+ conn = sf_connect()
775
+ sess = conn.impl.session()
776
+ value_str = process(self.visit(node.value), self)
777
+ for target in node.targets:
778
+ if isinstance(target, ast.Tuple):
779
+ tmps = [process(self.visit(sub_node), self) for sub_node in target.elts]
780
+ sess.variable(self.var_dict)
781
+ tmp_str = ", ".join(tmps) + " = " + value_str
782
+ sess.exec(tmp_str)
783
+ for tmp in tmps:
784
+ self.context[tmp] = sess.exec(tmp)
785
+ elif isinstance(target, ast.Name):
786
+ tmp_str = process(self.visit_Name(target), self)
787
+ sess.variable(self.var_dict)
788
+ self.context[tmp_str] = sess.exec(value_str)
789
+
790
+
791
+ def translator(cls):
792
+ if sys.version_info.major == 3 and sys.version_info.minor == 8:
793
+ warnings.warn("Classes with the same name may cause translation errors in Python 3.8.")
794
+ frame = inspect.currentframe()
795
+ frame = inspect.getouterframes(frame)[1].frame
796
+
797
+ source_lines, line_nums = inspect.getsourcelines(cls)
798
+ if source_lines:
799
+ s = source_lines[0]
800
+ if s.startswith(" "):
801
+ num_spaces = len(s) - len(s.lstrip(' '))
802
+ source_lines = [line[num_spaces:] for line in source_lines]
803
+ cls_code = "".join(source_lines)
804
+
805
+ cls_node: ast.ClassDef = ast.parse(cls_code).body[0]
806
+
807
+ cls_visitor = BacktestVisitor(cls, frame)
808
+
809
+ context_visitor = ContextVisitor(cls, frame)
810
+
811
+ for stmt in cls_node.body:
812
+ if isinstance(stmt, ast.FunctionDef):
813
+ cls_visitor.visit(stmt)
814
+ else:
815
+ context_visitor.visit(stmt)
816
+
817
+ cls.callback_d = cls_visitor.callback_d
818
+ cls.context = context_visitor.context
819
+
820
+ return cls