unageanu-jiji 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (564) hide show
  1. data/ChangeLog +0 -0
  2. data/README +0 -0
  3. data/bin/jiji.rb +6 -0
  4. data/html/css/calendar.css +432 -0
  5. data/html/css/datatable.css +299 -0
  6. data/html/css/default.css +557 -0
  7. data/html/css/dialog.css +77 -0
  8. data/html/img/auto_trade_off.gif +0 -0
  9. data/html/img/auto_trade_on.gif +0 -0
  10. data/html/img/back_bottom.gif +0 -0
  11. data/html/img/back_middle.gif +0 -0
  12. data/html/img/back_top.gif +0 -0
  13. data/html/img/bt-create-title-1.gif +0 -0
  14. data/html/img/bt-create-title-2.gif +0 -0
  15. data/html/img/bt-create-title-3.gif +0 -0
  16. data/html/img/button_add.gif +0 -0
  17. data/html/img/button_add_gray.gif +0 -0
  18. data/html/img/button_add_over.gif +0 -0
  19. data/html/img/button_apply.gif +0 -0
  20. data/html/img/button_apply_gray.gif +0 -0
  21. data/html/img/button_apply_over.gif +0 -0
  22. data/html/img/button_calendar.gif +0 -0
  23. data/html/img/button_calendar_over.gif +0 -0
  24. data/html/img/button_cancel.gif +0 -0
  25. data/html/img/button_cancel.jpg +0 -0
  26. data/html/img/button_cancel_gray.gif +0 -0
  27. data/html/img/button_cancel_over.gif +0 -0
  28. data/html/img/button_cancel_over.jpg +0 -0
  29. data/html/img/button_close.gif +0 -0
  30. data/html/img/button_close_gray.gif +0 -0
  31. data/html/img/button_close_over.gif +0 -0
  32. data/html/img/button_ok.gif +0 -0
  33. data/html/img/button_ok_gray.gif +0 -0
  34. data/html/img/button_ok_over.gif +0 -0
  35. data/html/img/button_remove.gif +0 -0
  36. data/html/img/button_remove_gray.gif +0 -0
  37. data/html/img/button_remove_over.gif +0 -0
  38. data/html/img/button_start.gif +0 -0
  39. data/html/img/button_start_over.gif +0 -0
  40. data/html/img/button_update.gif +0 -0
  41. data/html/img/button_update_gray.gif +0 -0
  42. data/html/img/button_update_over.gif +0 -0
  43. data/html/img/circle.gif +0 -0
  44. data/html/img/delta.gif +0 -0
  45. data/html/img/dialog_info.jpg +0 -0
  46. data/html/img/dialog_input.jpg +0 -0
  47. data/html/img/dialog_warn.jpg +0 -0
  48. data/html/img/dt-arrow-dn.png +0 -0
  49. data/html/img/dt-arrow-up.png +0 -0
  50. data/html/img/foot.jpg +0 -0
  51. data/html/img/h3_bt-create_0.gif +0 -0
  52. data/html/img/h3_bt-create_1.gif +0 -0
  53. data/html/img/h3_bt-create_2.gif +0 -0
  54. data/html/img/h3_result_0.gif +0 -0
  55. data/html/img/h3_result_1.gif +0 -0
  56. data/html/img/h3_result_2.gif +0 -0
  57. data/html/img/h3_result_3.gif +0 -0
  58. data/html/img/h3_result_4.gif +0 -0
  59. data/html/img/h3_result_5.gif +0 -0
  60. data/html/img/h3_result_6.gif +0 -0
  61. data/html/img/h3_rt-setting_0.gif +0 -0
  62. data/html/img/h3_rt-setting_1.gif +0 -0
  63. data/html/img/head.jpg +0 -0
  64. data/html/img/line_white.gif +0 -0
  65. data/html/img/loading.gif +0 -0
  66. data/html/img/panel_100_bottom.gif +0 -0
  67. data/html/img/panel_100_middle.gif +0 -0
  68. data/html/img/panel_100_top.gif +0 -0
  69. data/html/img/panel_140_650_b.gif +0 -0
  70. data/html/img/panel_140_650_m.gif +0 -0
  71. data/html/img/panel_140_650_t.gif +0 -0
  72. data/html/img/panel_140_660_b.gif +0 -0
  73. data/html/img/panel_140_660_m.gif +0 -0
  74. data/html/img/panel_140_660_t.gif +0 -0
  75. data/html/img/panel_140_b.gif +0 -0
  76. data/html/img/panel_140_m.gif +0 -0
  77. data/html/img/panel_140_t.gif +0 -0
  78. data/html/img/panel_260_b.gif +0 -0
  79. data/html/img/panel_260_m.gif +0 -0
  80. data/html/img/panel_260_t.gif +0 -0
  81. data/html/img/panel_300_b.gif +0 -0
  82. data/html/img/panel_300_m.gif +0 -0
  83. data/html/img/panel_300_t.gif +0 -0
  84. data/html/img/panel_320_b.gif +0 -0
  85. data/html/img/panel_320_m.gif +0 -0
  86. data/html/img/panel_320_t.gif +0 -0
  87. data/html/img/panel_360_b.gif +0 -0
  88. data/html/img/panel_360_m.gif +0 -0
  89. data/html/img/panel_360_t.gif +0 -0
  90. data/html/img/panel_380_b.gif +0 -0
  91. data/html/img/panel_380_m.gif +0 -0
  92. data/html/img/panel_380_t.gif +0 -0
  93. data/html/img/panel_500_b.gif +0 -0
  94. data/html/img/panel_500_m.gif +0 -0
  95. data/html/img/panel_500_t.gif +0 -0
  96. data/html/img/panel_620_b.gif +0 -0
  97. data/html/img/panel_620_m.gif +0 -0
  98. data/html/img/panel_620_t.gif +0 -0
  99. data/html/img/panel_780_b.gif +0 -0
  100. data/html/img/panel_780_m.gif +0 -0
  101. data/html/img/panel_780_t.gif +0 -0
  102. data/html/img/problem.gif +0 -0
  103. data/html/img/progressbar.gif +0 -0
  104. data/html/img/result-title-1-1.gif +0 -0
  105. data/html/img/result-title-1-2.gif +0 -0
  106. data/html/img/result-title-2-1.gif +0 -0
  107. data/html/img/result-title-2-2.gif +0 -0
  108. data/html/img/result-title-3-1.gif +0 -0
  109. data/html/img/result-title-4-1.gif +0 -0
  110. data/html/img/rt-setting-title-1.gif +0 -0
  111. data/html/img/rt-setting-title-2.gif +0 -0
  112. data/html/img/s.gif +0 -0
  113. data/html/img/scroll.gif +0 -0
  114. data/html/img/separator.gif +0 -0
  115. data/html/img/sidebar_agent.png +0 -0
  116. data/html/img/sidebar_agent_edit.png +0 -0
  117. data/html/img/sidebar_agent_edit_agent.png +0 -0
  118. data/html/img/sidebar_agent_edit_agent_over.png +0 -0
  119. data/html/img/sidebar_agent_edit_agent_s.png +0 -0
  120. data/html/img/sidebar_agent_edit_over.png +0 -0
  121. data/html/img/sidebar_agent_edit_s.png +0 -0
  122. data/html/img/sidebar_agent_edit_shared_lib.png +0 -0
  123. data/html/img/sidebar_agent_edit_shared_lib_over.png +0 -0
  124. data/html/img/sidebar_agent_edit_shared_lib_s.png +0 -0
  125. data/html/img/sidebar_back.gif +0 -0
  126. data/html/img/sidebar_bt.png +0 -0
  127. data/html/img/sidebar_bt_create.png +0 -0
  128. data/html/img/sidebar_bt_create_over.png +0 -0
  129. data/html/img/sidebar_bt_create_s.png +0 -0
  130. data/html/img/sidebar_bt_result.png +0 -0
  131. data/html/img/sidebar_bt_result_over.png +0 -0
  132. data/html/img/sidebar_bt_result_s.png +0 -0
  133. data/html/img/sidebar_result_rmt.png +0 -0
  134. data/html/img/sidebar_result_rmt_over.png +0 -0
  135. data/html/img/sidebar_result_rmt_s.png +0 -0
  136. data/html/img/sidebar_rt.png +0 -0
  137. data/html/img/sidebar_rt_setting.png +0 -0
  138. data/html/img/sidebar_rt_setting_over.png +0 -0
  139. data/html/img/sidebar_rt_setting_s.png +0 -0
  140. data/html/img/sprite.png +0 -0
  141. data/html/img/submenu_agents.png +0 -0
  142. data/html/img/submenu_agents_over.png +0 -0
  143. data/html/img/submenu_agents_s.png +0 -0
  144. data/html/img/submenu_graph.png +0 -0
  145. data/html/img/submenu_graph_over.png +0 -0
  146. data/html/img/submenu_graph_s.png +0 -0
  147. data/html/img/submenu_info.png +0 -0
  148. data/html/img/submenu_info_over.png +0 -0
  149. data/html/img/submenu_info_s.png +0 -0
  150. data/html/img/submenu_log.png +0 -0
  151. data/html/img/submenu_log_over.png +0 -0
  152. data/html/img/submenu_log_s.png +0 -0
  153. data/html/img/submenu_operation.png +0 -0
  154. data/html/img/submenu_operation_over.png +0 -0
  155. data/html/img/submenu_operation_s.png +0 -0
  156. data/html/img/submenu_trade.png +0 -0
  157. data/html/img/submenu_trade_over.png +0 -0
  158. data/html/img/submenu_trade_s.png +0 -0
  159. data/html/img/td_over.gif +0 -0
  160. data/html/img/td_over_d.gif +0 -0
  161. data/html/img/td_selected.gif +0 -0
  162. data/html/img/thead.gif +0 -0
  163. data/html/img/transparent.gif +0 -0
  164. data/html/index.html +480 -0
  165. data/html/js/W3CDTF.js +131 -0
  166. data/html/js/agent-editor-page.js +350 -0
  167. data/html/js/agent-selector.js +642 -0
  168. data/html/js/app.js +226 -0
  169. data/html/js/bt-create-page.js +186 -0
  170. data/html/js/codepress/codepress.css +21 -0
  171. data/html/js/codepress/codepress.html +35 -0
  172. data/html/js/codepress/codepress.js +138 -0
  173. data/html/js/codepress/engines/gecko.js +293 -0
  174. data/html/js/codepress/engines/khtml.js +0 -0
  175. data/html/js/codepress/engines/msie.js +304 -0
  176. data/html/js/codepress/engines/older.js +0 -0
  177. data/html/js/codepress/engines/opera.js +260 -0
  178. data/html/js/codepress/images/line-numbers.gif +0 -0
  179. data/html/js/codepress/images/line-numbers.png +0 -0
  180. data/html/js/codepress/index.html +443 -0
  181. data/html/js/codepress/languages/asp.css +71 -0
  182. data/html/js/codepress/languages/asp.js +117 -0
  183. data/html/js/codepress/languages/autoit.css +13 -0
  184. data/html/js/codepress/languages/autoit.js +32 -0
  185. data/html/js/codepress/languages/csharp.css +9 -0
  186. data/html/js/codepress/languages/csharp.js +25 -0
  187. data/html/js/codepress/languages/css.css +10 -0
  188. data/html/js/codepress/languages/css.js +23 -0
  189. data/html/js/codepress/languages/generic.css +9 -0
  190. data/html/js/codepress/languages/generic.js +25 -0
  191. data/html/js/codepress/languages/html.css +13 -0
  192. data/html/js/codepress/languages/html.js +59 -0
  193. data/html/js/codepress/languages/java.css +7 -0
  194. data/html/js/codepress/languages/java.js +24 -0
  195. data/html/js/codepress/languages/javascript.css +8 -0
  196. data/html/js/codepress/languages/javascript.js +30 -0
  197. data/html/js/codepress/languages/perl.css +11 -0
  198. data/html/js/codepress/languages/perl.js +27 -0
  199. data/html/js/codepress/languages/php.css +12 -0
  200. data/html/js/codepress/languages/php.js +61 -0
  201. data/html/js/codepress/languages/ruby.css +10 -0
  202. data/html/js/codepress/languages/ruby.js +26 -0
  203. data/html/js/codepress/languages/sql.css +10 -0
  204. data/html/js/codepress/languages/sql.js +30 -0
  205. data/html/js/codepress/languages/text.css +5 -0
  206. data/html/js/codepress/languages/text.js +9 -0
  207. data/html/js/codepress/languages/vbscript.css +71 -0
  208. data/html/js/codepress/languages/vbscript.js +117 -0
  209. data/html/js/codepress/languages/xsl.css +15 -0
  210. data/html/js/codepress/languages/xsl.js +103 -0
  211. data/html/js/codepress/license.txt +458 -0
  212. data/html/js/container-min.js +1 -0
  213. data/html/js/container-utils.js +78 -0
  214. data/html/js/dialog.js +270 -0
  215. data/html/js/edit_area/autocompletion.js +493 -0
  216. data/html/js/edit_area/edit_area.css +507 -0
  217. data/html/js/edit_area/edit_area.js +510 -0
  218. data/html/js/edit_area/edit_area_compressor.php +408 -0
  219. data/html/js/edit_area/edit_area_full.gz +0 -0
  220. data/html/js/edit_area/edit_area_full.js +38 -0
  221. data/html/js/edit_area/edit_area_full_with_plugins.gz +0 -0
  222. data/html/js/edit_area/edit_area_full_with_plugins.js +39 -0
  223. data/html/js/edit_area/edit_area_functions.js +1098 -0
  224. data/html/js/edit_area/edit_area_loader.js +1070 -0
  225. data/html/js/edit_area/elements_functions.js +337 -0
  226. data/html/js/edit_area/highlight.js +283 -0
  227. data/html/js/edit_area/images/Thumbs.db +0 -0
  228. data/html/js/edit_area/images/autocompletion.gif +0 -0
  229. data/html/js/edit_area/images/close.gif +0 -0
  230. data/html/js/edit_area/images/fullscreen.gif +0 -0
  231. data/html/js/edit_area/images/go_to_line.gif +0 -0
  232. data/html/js/edit_area/images/help.gif +0 -0
  233. data/html/js/edit_area/images/highlight.gif +0 -0
  234. data/html/js/edit_area/images/load.gif +0 -0
  235. data/html/js/edit_area/images/move.gif +0 -0
  236. data/html/js/edit_area/images/newdocument.gif +0 -0
  237. data/html/js/edit_area/images/opacity.png +0 -0
  238. data/html/js/edit_area/images/processing.gif +0 -0
  239. data/html/js/edit_area/images/redo.gif +0 -0
  240. data/html/js/edit_area/images/reset_highlight.gif +0 -0
  241. data/html/js/edit_area/images/save.gif +0 -0
  242. data/html/js/edit_area/images/search.gif +0 -0
  243. data/html/js/edit_area/images/smooth_selection.gif +0 -0
  244. data/html/js/edit_area/images/spacer.gif +0 -0
  245. data/html/js/edit_area/images/statusbar_resize.gif +0 -0
  246. data/html/js/edit_area/images/undo.gif +0 -0
  247. data/html/js/edit_area/keyboard.js +145 -0
  248. data/html/js/edit_area/langs/cs.js +65 -0
  249. data/html/js/edit_area/langs/de.js +65 -0
  250. data/html/js/edit_area/langs/dk.js +65 -0
  251. data/html/js/edit_area/langs/en.js +65 -0
  252. data/html/js/edit_area/langs/eo.js +65 -0
  253. data/html/js/edit_area/langs/es.js +62 -0
  254. data/html/js/edit_area/langs/fr.js +65 -0
  255. data/html/js/edit_area/langs/hr.js +65 -0
  256. data/html/js/edit_area/langs/it.js +65 -0
  257. data/html/js/edit_area/langs/ja.js +65 -0
  258. data/html/js/edit_area/langs/mk.js +65 -0
  259. data/html/js/edit_area/langs/nl.js +65 -0
  260. data/html/js/edit_area/langs/pl.js +65 -0
  261. data/html/js/edit_area/langs/pt.js +65 -0
  262. data/html/js/edit_area/langs/ru.js +65 -0
  263. data/html/js/edit_area/langs/sk.js +65 -0
  264. data/html/js/edit_area/license_apache.txt +7 -0
  265. data/html/js/edit_area/license_bsd.txt +10 -0
  266. data/html/js/edit_area/license_lgpl.txt +458 -0
  267. data/html/js/edit_area/manage_area.js +466 -0
  268. data/html/js/edit_area/plugins/charmap/charmap.js +90 -0
  269. data/html/js/edit_area/plugins/charmap/css/charmap.css +64 -0
  270. data/html/js/edit_area/plugins/charmap/images/charmap.gif +0 -0
  271. data/html/js/edit_area/plugins/charmap/jscripts/map.js +373 -0
  272. data/html/js/edit_area/plugins/charmap/langs/cs.js +6 -0
  273. data/html/js/edit_area/plugins/charmap/langs/de.js +6 -0
  274. data/html/js/edit_area/plugins/charmap/langs/dk.js +6 -0
  275. data/html/js/edit_area/plugins/charmap/langs/en.js +6 -0
  276. data/html/js/edit_area/plugins/charmap/langs/eo.js +6 -0
  277. data/html/js/edit_area/plugins/charmap/langs/es.js +6 -0
  278. data/html/js/edit_area/plugins/charmap/langs/fr.js +6 -0
  279. data/html/js/edit_area/plugins/charmap/langs/hr.js +6 -0
  280. data/html/js/edit_area/plugins/charmap/langs/it.js +6 -0
  281. data/html/js/edit_area/plugins/charmap/langs/ja.js +6 -0
  282. data/html/js/edit_area/plugins/charmap/langs/mk.js +6 -0
  283. data/html/js/edit_area/plugins/charmap/langs/nl.js +6 -0
  284. data/html/js/edit_area/plugins/charmap/langs/pl.js +6 -0
  285. data/html/js/edit_area/plugins/charmap/langs/pt.js +6 -0
  286. data/html/js/edit_area/plugins/charmap/langs/ru.js +6 -0
  287. data/html/js/edit_area/plugins/charmap/langs/sk.js +6 -0
  288. data/html/js/edit_area/plugins/charmap/popup.html +24 -0
  289. data/html/js/edit_area/plugins/test/css/test.css +3 -0
  290. data/html/js/edit_area/plugins/test/images/Thumbs.db +0 -0
  291. data/html/js/edit_area/plugins/test/images/test.gif +0 -0
  292. data/html/js/edit_area/plugins/test/langs/cs.js +4 -0
  293. data/html/js/edit_area/plugins/test/langs/de.js +4 -0
  294. data/html/js/edit_area/plugins/test/langs/dk.js +4 -0
  295. data/html/js/edit_area/plugins/test/langs/en.js +4 -0
  296. data/html/js/edit_area/plugins/test/langs/eo.js +4 -0
  297. data/html/js/edit_area/plugins/test/langs/es.js +4 -0
  298. data/html/js/edit_area/plugins/test/langs/fr.js +4 -0
  299. data/html/js/edit_area/plugins/test/langs/hr.js +4 -0
  300. data/html/js/edit_area/plugins/test/langs/it.js +4 -0
  301. data/html/js/edit_area/plugins/test/langs/ja.js +4 -0
  302. data/html/js/edit_area/plugins/test/langs/mk.js +4 -0
  303. data/html/js/edit_area/plugins/test/langs/nl.js +4 -0
  304. data/html/js/edit_area/plugins/test/langs/pl.js +4 -0
  305. data/html/js/edit_area/plugins/test/langs/pt.js +4 -0
  306. data/html/js/edit_area/plugins/test/langs/ru.js +4 -0
  307. data/html/js/edit_area/plugins/test/langs/sk.js +4 -0
  308. data/html/js/edit_area/plugins/test/test.js +110 -0
  309. data/html/js/edit_area/plugins/test/test2.js +1 -0
  310. data/html/js/edit_area/reg_syntax.js +164 -0
  311. data/html/js/edit_area/reg_syntax/basic.js +69 -0
  312. data/html/js/edit_area/reg_syntax/brainfuck.js +44 -0
  313. data/html/js/edit_area/reg_syntax/c.js +62 -0
  314. data/html/js/edit_area/reg_syntax/coldfusion.js +119 -0
  315. data/html/js/edit_area/reg_syntax/cpp.js +65 -0
  316. data/html/js/edit_area/reg_syntax/css.js +84 -0
  317. data/html/js/edit_area/reg_syntax/html.js +50 -0
  318. data/html/js/edit_area/reg_syntax/js.js +93 -0
  319. data/html/js/edit_area/reg_syntax/pas.js +82 -0
  320. data/html/js/edit_area/reg_syntax/perl.js +88 -0
  321. data/html/js/edit_area/reg_syntax/php.js +156 -0
  322. data/html/js/edit_area/reg_syntax/python.js +144 -0
  323. data/html/js/edit_area/reg_syntax/robotstxt.js +24 -0
  324. data/html/js/edit_area/reg_syntax/ruby.js +67 -0
  325. data/html/js/edit_area/reg_syntax/sql.js +55 -0
  326. data/html/js/edit_area/reg_syntax/tsql.js +87 -0
  327. data/html/js/edit_area/reg_syntax/vb.js +52 -0
  328. data/html/js/edit_area/reg_syntax/xml.js +56 -0
  329. data/html/js/edit_area/regexp.js +135 -0
  330. data/html/js/edit_area/resize_area.js +82 -0
  331. data/html/js/edit_area/search_replace.js +174 -0
  332. data/html/js/edit_area/template.html +99 -0
  333. data/html/js/json-broker-client.js +61 -0
  334. data/html/js/page-manager.js +93 -0
  335. data/html/js/prototype.js +4184 -0
  336. data/html/js/result-page.js +707 -0
  337. data/html/js/rt-setting-page.js +122 -0
  338. data/html/js/sidebar.js +246 -0
  339. data/html/js/templates.js +208 -0
  340. data/html/js/utils.js +716 -0
  341. data/html/js/uuid.js +103 -0
  342. data/html/swf/chart.swf +0 -0
  343. data/lib/jiji/agent/agent.rb +93 -0
  344. data/lib/jiji/agent/agent_manager.rb +133 -0
  345. data/lib/jiji/agent/agent_registry.rb +248 -0
  346. data/lib/jiji/agent/permitter.rb +128 -0
  347. data/lib/jiji/agent/util.rb +16 -0
  348. data/lib/jiji/collector.rb +219 -0
  349. data/lib/jiji/command.rb +129 -0
  350. data/lib/jiji/configuration.rb +80 -0
  351. data/lib/jiji/dao/rate_dao.rb +149 -0
  352. data/lib/jiji/dao/timed_data_dao.rb +334 -0
  353. data/lib/jiji/dao/trade_result_dao.rb +128 -0
  354. data/lib/jiji/error.rb +33 -0
  355. data/lib/jiji/models.rb +169 -0
  356. data/lib/jiji/observer.rb +105 -0
  357. data/lib/jiji/operator.rb +405 -0
  358. data/lib/jiji/output.rb +165 -0
  359. data/lib/jiji/process.rb +182 -0
  360. data/lib/jiji/process_manager.rb +189 -0
  361. data/lib/jiji/registry.rb +255 -0
  362. data/lib/jiji/server.rb +115 -0
  363. data/lib/jiji/service/agent_service.rb +131 -0
  364. data/lib/jiji/service/hello_service.rb +10 -0
  365. data/lib/jiji/service/output_service.rb +58 -0
  366. data/lib/jiji/service/process_service.rb +78 -0
  367. data/lib/jiji/service/rate_service.rb +33 -0
  368. data/lib/jiji/service/system_service.rb +14 -0
  369. data/lib/jiji/service/trade_result_service.rb +32 -0
  370. data/lib/jiji/single_click_client.rb +95 -0
  371. data/lib/jiji/util/block_to_session.rb +70 -0
  372. data/lib/jiji/util/cache.rb +79 -0
  373. data/lib/jiji/util/csv_append_support.rb +15 -0
  374. data/lib/jiji/util/file_lock.rb +86 -0
  375. data/lib/jiji/util/fix_yaml_bug.rb +11 -0
  376. data/lib/jiji/util/iterator.rb +70 -0
  377. data/lib/jiji/util/json_broker.rb +53 -0
  378. data/lib/jiji/util/json_rpc_requestor.rb +30 -0
  379. data/lib/jiji/util/synchronize_interceptor.rb +41 -0
  380. data/lib/jiji/util/thread_use_generator.rb +52 -0
  381. data/lib/jiji/util/util.rb +179 -0
  382. data/swf/build.xml +23 -0
  383. data/swf/chart/FxChart-config.xml +9 -0
  384. data/swf/chart/FxChart.mxml +17 -0
  385. data/swf/chart/fx/chart/Chart.as +155 -0
  386. data/swf/chart/fx/chart/ctrl/AutoUpdate.as +96 -0
  387. data/swf/chart/fx/chart/ctrl/Controller.as +258 -0
  388. data/swf/chart/fx/chart/ctrl/Event.as +75 -0
  389. data/swf/chart/fx/chart/model/Model.as +226 -0
  390. data/swf/chart/fx/chart/model/TimedData.as +40 -0
  391. data/swf/chart/fx/chart/ui/AbstractChartUI.as +59 -0
  392. data/swf/chart/fx/chart/ui/AbstractDrawChartUI.as +63 -0
  393. data/swf/chart/fx/chart/ui/Constants.as +233 -0
  394. data/swf/chart/fx/chart/ui/InformationWindow.as +224 -0
  395. data/swf/chart/fx/chart/ui/LayerManager.as +95 -0
  396. data/swf/chart/fx/chart/ui/Loading.as +32 -0
  397. data/swf/chart/fx/chart/ui/Pointer.as +59 -0
  398. data/swf/chart/fx/chart/ui/RangeInfoWindow.as +84 -0
  399. data/swf/chart/fx/chart/ui/RenderingContext.as +54 -0
  400. data/swf/chart/fx/chart/ui/ScaleSelector.as +95 -0
  401. data/swf/chart/fx/chart/ui/Scroll.as +240 -0
  402. data/swf/chart/fx/chart/ui/ScrollBar.as +378 -0
  403. data/swf/chart/fx/chart/ui/Stage.as +97 -0
  404. data/swf/chart/fx/chart/ui/TradeDetailWindow.as +146 -0
  405. data/swf/chart/fx/chart/ui/TradeResult.as +334 -0
  406. data/swf/chart/fx/chart/ui/Window.as +96 -0
  407. data/swf/chart/fx/chart/ui/candle/Axis.as +112 -0
  408. data/swf/chart/fx/chart/ui/candle/Candle.as +79 -0
  409. data/swf/chart/fx/chart/ui/candle/CandleChart.as +81 -0
  410. data/swf/chart/fx/chart/ui/graph/Graph.as +198 -0
  411. data/swf/chart/fx/chart/ui/graph/GraphManager.as +177 -0
  412. data/swf/chart/fx/chart/ui/resource/buy.gif +0 -0
  413. data/swf/chart/fx/chart/ui/resource/cursor_hand.gif +0 -0
  414. data/swf/chart/fx/chart/ui/resource/diff_label.gif +0 -0
  415. data/swf/chart/fx/chart/ui/resource/down.gif +0 -0
  416. data/swf/chart/fx/chart/ui/resource/down_buy.gif +0 -0
  417. data/swf/chart/fx/chart/ui/resource/down_buy_1.gif +0 -0
  418. data/swf/chart/fx/chart/ui/resource/down_buy_2.gif +0 -0
  419. data/swf/chart/fx/chart/ui/resource/down_buy_3.gif +0 -0
  420. data/swf/chart/fx/chart/ui/resource/down_sell.gif +0 -0
  421. data/swf/chart/fx/chart/ui/resource/down_sell_1.gif +0 -0
  422. data/swf/chart/fx/chart/ui/resource/down_sell_2.gif +0 -0
  423. data/swf/chart/fx/chart/ui/resource/down_sell_3.gif +0 -0
  424. data/swf/chart/fx/chart/ui/resource/draw_buy.gif +0 -0
  425. data/swf/chart/fx/chart/ui/resource/draw_sell.gif +0 -0
  426. data/swf/chart/fx/chart/ui/resource/end_label.gif +0 -0
  427. data/swf/chart/fx/chart/ui/resource/fixed.gif +0 -0
  428. data/swf/chart/fx/chart/ui/resource/loading.gif +0 -0
  429. data/swf/chart/fx/chart/ui/resource/max_label.gif +0 -0
  430. data/swf/chart/fx/chart/ui/resource/min_label.gif +0 -0
  431. data/swf/chart/fx/chart/ui/resource/scroll_bar.gif +0 -0
  432. data/swf/chart/fx/chart/ui/resource/scroll_bar_a.gif +0 -0
  433. data/swf/chart/fx/chart/ui/resource/scroll_bar_handle.gif +0 -0
  434. data/swf/chart/fx/chart/ui/resource/scroll_bar_handle_a.gif +0 -0
  435. data/swf/chart/fx/chart/ui/resource/scroll_bar_handle_o.gif +0 -0
  436. data/swf/chart/fx/chart/ui/resource/scroll_bar_left.gif +0 -0
  437. data/swf/chart/fx/chart/ui/resource/scroll_bar_left_a.gif +0 -0
  438. data/swf/chart/fx/chart/ui/resource/scroll_bar_left_o.gif +0 -0
  439. data/swf/chart/fx/chart/ui/resource/scroll_bar_o.gif +0 -0
  440. data/swf/chart/fx/chart/ui/resource/scroll_bar_right.gif +0 -0
  441. data/swf/chart/fx/chart/ui/resource/scroll_bar_right_a.gif +0 -0
  442. data/swf/chart/fx/chart/ui/resource/scroll_bar_right_o.gif +0 -0
  443. data/swf/chart/fx/chart/ui/resource/scroll_handle.gif +0 -0
  444. data/swf/chart/fx/chart/ui/resource/scroll_info_handle.gif +0 -0
  445. data/swf/chart/fx/chart/ui/resource/scroll_left_button.gif +0 -0
  446. data/swf/chart/fx/chart/ui/resource/scroll_left_button_d.gif +0 -0
  447. data/swf/chart/fx/chart/ui/resource/scroll_left_button_down.gif +0 -0
  448. data/swf/chart/fx/chart/ui/resource/scroll_left_button_g.gif +0 -0
  449. data/swf/chart/fx/chart/ui/resource/scroll_left_button_o.gif +0 -0
  450. data/swf/chart/fx/chart/ui/resource/scroll_left_button_up.gif +0 -0
  451. data/swf/chart/fx/chart/ui/resource/scroll_outer.gif +0 -0
  452. data/swf/chart/fx/chart/ui/resource/scroll_outer_left.gif +0 -0
  453. data/swf/chart/fx/chart/ui/resource/scroll_outer_right.gif +0 -0
  454. data/swf/chart/fx/chart/ui/resource/scroll_right_button.gif +0 -0
  455. data/swf/chart/fx/chart/ui/resource/scroll_right_button_d.gif +0 -0
  456. data/swf/chart/fx/chart/ui/resource/scroll_right_button_down.gif +0 -0
  457. data/swf/chart/fx/chart/ui/resource/scroll_right_button_g.gif +0 -0
  458. data/swf/chart/fx/chart/ui/resource/scroll_right_button_o.gif +0 -0
  459. data/swf/chart/fx/chart/ui/resource/scroll_right_button_up.gif +0 -0
  460. data/swf/chart/fx/chart/ui/resource/scroll_slider_left.gif +0 -0
  461. data/swf/chart/fx/chart/ui/resource/scroll_slider_right.gif +0 -0
  462. data/swf/chart/fx/chart/ui/resource/sell.gif +0 -0
  463. data/swf/chart/fx/chart/ui/resource/start_label.gif +0 -0
  464. data/swf/chart/fx/chart/ui/resource/stripe.gif +0 -0
  465. data/swf/chart/fx/chart/ui/resource/stripe_b.gif +0 -0
  466. data/swf/chart/fx/chart/ui/resource/stripe_r.gif +0 -0
  467. data/swf/chart/fx/chart/ui/resource/unfixed.gif +0 -0
  468. data/swf/chart/fx/chart/ui/resource/up.gif +0 -0
  469. data/swf/chart/fx/chart/ui/resource/up_buy.gif +0 -0
  470. data/swf/chart/fx/chart/ui/resource/up_buy_1.gif +0 -0
  471. data/swf/chart/fx/chart/ui/resource/up_buy_2.gif +0 -0
  472. data/swf/chart/fx/chart/ui/resource/up_buy_3.gif +0 -0
  473. data/swf/chart/fx/chart/ui/resource/up_sell.gif +0 -0
  474. data/swf/chart/fx/chart/ui/resource/up_sell_1.gif +0 -0
  475. data/swf/chart/fx/chart/ui/resource/up_sell_2.gif +0 -0
  476. data/swf/chart/fx/chart/ui/resource/up_sell_3.gif +0 -0
  477. data/swf/chart/fx/net/StubFactory.as +113 -0
  478. data/swf/chart/fx/util/ListenerSupport.as +55 -0
  479. data/swf/chart/fx/util/PositionManager.as +94 -0
  480. data/swf/chart/fx/util/ScaleFormatter.as +156 -0
  481. data/swf/chart/fx/util/Util.as +61 -0
  482. data/swf/chart/log.as +40 -0
  483. data/swf/lib/corelib.swc +0 -0
  484. data/test/BackCollectorTest/basic/2008-08-04/AUDJPY.csv +5 -0
  485. data/test/BackCollectorTest/basic/2008-08-04/USDJPY.csv +5 -0
  486. data/test/BackCollectorTest/basic/2008-08-04/ZARJPY.csv +5 -0
  487. data/test/BackCollectorTest/basic/2008-08-05/AUDJPY.csv +5 -0
  488. data/test/BackCollectorTest/basic/2008-08-05/USDJPY.csv +5 -0
  489. data/test/BackCollectorTest/basic/2008-08-05/ZARJPY.csv +5 -0
  490. data/test/BackCollectorTest/basic/2008-08-06/AUDJPY.csv +5 -0
  491. data/test/BackCollectorTest/basic/2008-08-06/USDJPY.csv +5 -0
  492. data/test/BackCollectorTest/basic/2008-08-06/ZARJPY.csv +5 -0
  493. data/test/BackCollectorTest/basic/2008-08-07/AUDJPY.csv +5 -0
  494. data/test/BackCollectorTest/basic/2008-08-07/USDJPY.csv +5 -0
  495. data/test/BackCollectorTest/basic/2008-08-07/ZARJPY.csv +5 -0
  496. data/test/BackCollectorTest/basic/AUDJPY/raw/2008-08-04.csv +5 -0
  497. data/test/BackCollectorTest/basic/AUDJPY/raw/2008-08-05.csv +5 -0
  498. data/test/BackCollectorTest/basic/AUDJPY/raw/2008-08-06.csv +5 -0
  499. data/test/BackCollectorTest/basic/AUDJPY/raw/2008-08-07.csv +5 -0
  500. data/test/BackCollectorTest/basic/USDJPY/raw/2008-08-04.csv +5 -0
  501. data/test/BackCollectorTest/basic/USDJPY/raw/2008-08-05.csv +5 -0
  502. data/test/BackCollectorTest/basic/USDJPY/raw/2008-08-06.csv +5 -0
  503. data/test/BackCollectorTest/basic/USDJPY/raw/2008-08-07.csv +5 -0
  504. data/test/BackCollectorTest/basic/ZARJPY/raw/2008-08-04.csv +5 -0
  505. data/test/BackCollectorTest/basic/ZARJPY/raw/2008-08-05.csv +5 -0
  506. data/test/BackCollectorTest/basic/ZARJPY/raw/2008-08-06.csv +5 -0
  507. data/test/BackCollectorTest/basic/ZARJPY/raw/2008-08-07.csv +5 -0
  508. data/test/BackCollectorTest/lack/2008-08-04/AUDJPY.csv +5 -0
  509. data/test/BackCollectorTest/lack/2008-08-04/USDJPY.csv +5 -0
  510. data/test/BackCollectorTest/lack/2008-08-04/ZARJPY.csv +5 -0
  511. data/test/BackCollectorTest/lack/2008-08-06/AUDJPY.csv +5 -0
  512. data/test/BackCollectorTest/lack/2008-08-06/USDJPY.csv +5 -0
  513. data/test/BackCollectorTest/lack/2008-08-06/ZARJPY.csv +5 -0
  514. data/test/BackCollectorTest/lack/2008-08-07/AUDJPY.csv +5 -0
  515. data/test/BackCollectorTest/lack/2008-08-07/USDJPY.csv +5 -0
  516. data/test/BackCollectorTest/lack/2008-08-07/ZARJPY.csv +5 -0
  517. data/test/BackCollectorTest/lack/AUDJPY/raw/2008-08-04.csv +5 -0
  518. data/test/BackCollectorTest/lack/AUDJPY/raw/2008-08-06.csv +5 -0
  519. data/test/BackCollectorTest/lack/AUDJPY/raw/2008-08-07.csv +5 -0
  520. data/test/BackCollectorTest/lack/USDJPY/raw/2008-08-04.csv +5 -0
  521. data/test/BackCollectorTest/lack/USDJPY/raw/2008-08-06.csv +5 -0
  522. data/test/BackCollectorTest/lack/USDJPY/raw/2008-08-07.csv +5 -0
  523. data/test/BackCollectorTest/lack/ZARJPY/raw/2008-08-04.csv +5 -0
  524. data/test/BackCollectorTest/lack/ZARJPY/raw/2008-08-06.csv +5 -0
  525. data/test/BackCollectorTest/lack/ZARJPY/raw/2008-08-07.csv +5 -0
  526. data/test/ProcessManagerTest/agents/moving_average.rb +95 -0
  527. data/test/ProcessManagerTest/conf/configuration.yaml +19 -0
  528. data/test/ProcessManagerTest/rate_datas/EURJPY/raw/2008-08-21.csv +5853 -0
  529. data/test/ProcessManagerTest/rate_datas/EURJPY/raw/2008-08-22.csv +5821 -0
  530. data/test/ProcessManagerTest/rate_datas/EURJPY/raw/2008-08-23.csv +5921 -0
  531. data/test/ProcessManagerTest/rate_datas/EURJPY/raw/2008-08-24.csv +5956 -0
  532. data/test/ProcessManagerTest/rate_datas/EURJPY/raw/2008-08-25.csv +5796 -0
  533. data/test/ProcessManagerTest/rate_datas/USDJPY/raw/2008-08-21.csv +5853 -0
  534. data/test/ProcessManagerTest/rate_datas/USDJPY/raw/2008-08-22.csv +5821 -0
  535. data/test/ProcessManagerTest/rate_datas/USDJPY/raw/2008-08-23.csv +5921 -0
  536. data/test/ProcessManagerTest/rate_datas/USDJPY/raw/2008-08-24.csv +5956 -0
  537. data/test/ProcessManagerTest/rate_datas/USDJPY/raw/2008-08-25.csv +5796 -0
  538. data/test/all_tests.rb +26 -0
  539. data/test/service/all_service_tests.rb +10 -0
  540. data/test/service/test_AgentService.rb +185 -0
  541. data/test/service/test_OutputService.rb +33 -0
  542. data/test/service/test_RateService.rb +56 -0
  543. data/test/test_AgentManager.rb +307 -0
  544. data/test/test_AgentRegistory.rb +566 -0
  545. data/test/test_BackTestCollector.rb +281 -0
  546. data/test/test_BlockToSession.rb +74 -0
  547. data/test/test_CSV.rb +85 -0
  548. data/test/test_Collector.rb +246 -0
  549. data/test/test_Configuration.rb +61 -0
  550. data/test/test_Configuration_a.yaml +6 -0
  551. data/test/test_Operator.rb +501 -0
  552. data/test/test_Output.rb +169 -0
  553. data/test/test_Output_registry.rb +49 -0
  554. data/test/test_PeriodicallyAgent.rb +180 -0
  555. data/test/test_Permitter.rb +217 -0
  556. data/test/test_Process.rb +186 -0
  557. data/test/test_ProcessManager.rb +312 -0
  558. data/test/test_RateDao.rb +697 -0
  559. data/test/test_SingleClickClient.rb +115 -0
  560. data/test/test_SynchronizeInterceptor.rb +75 -0
  561. data/test/test_TradeResultDao.rb +487 -0
  562. data/test/test_configuration.yaml +16 -0
  563. data/test/testutils.rb +37 -0
  564. metadata +750 -0
@@ -0,0 +1,128 @@
1
+
2
+ require 'thread'
3
+ require 'jiji/util/csv_append_support'
4
+ require 'jiji/util/thread_use_generator'
5
+ require 'jiji/util/util'
6
+ require 'jiji/models'
7
+ require 'jiji/dao/timed_data_dao'
8
+ require 'set'
9
+
10
+ module JIJI
11
+ module Dao
12
+
13
+ # 取引結果DAO
14
+ class TradeResultDao
15
+
16
+ def initialize( data_dir, scales=[] )
17
+ @data_dir = data_dir
18
+ @scales = scales
19
+
20
+ aggregators = @scales.map {|s| TradeAggregator.new(s) }
21
+ @trade_dao = dao( "trade", aggregators )
22
+
23
+ aggregators = @scales.map {|s| LastAggregator.new(s) }
24
+ @profit_or_loss_dao = dao( "profit_or_loss", aggregators )
25
+
26
+ @position_dir = "#{data_dir}/positions"
27
+ FileUtils.mkdir_p @position_dir unless File.exists? @position_dir
28
+ end
29
+
30
+ # ポジションデータを保存する
31
+ def save( position )
32
+ props = position.values
33
+ file = "#{@position_dir}/#{position.position_id}.yaml"
34
+ FileLock.new( file ).writelock {|f|
35
+ f.write( YAML.dump(props) )
36
+ }
37
+ end
38
+ # ポジションデータをロードする。
39
+ def load( id )
40
+ props = {}
41
+ file = "#{@position_dir}/#{id}.yaml"
42
+ if ( File.exist? file )
43
+ FileLock.new( file ).readlock {|f|
44
+ props = YAML.load f
45
+ }
46
+ end
47
+ props
48
+ end
49
+
50
+ # 指定期間のトレードデータを得る。
51
+ def list_positions( scale, start_date=nil, end_date=nil )
52
+ ids = Set.new
53
+ @trade_dao.each_data( scale, start_date, end_date ) {|r, t|
54
+ ids += r[0].split(" ")
55
+ }
56
+
57
+ # バッファ内に取得期間内のデータがある場合、それも追加する。
58
+ aggregator = @trade_dao.aggregator.find {|a| a.scale == scale }
59
+ if aggregator && aggregator.values
60
+ aggregator.values.each {|v| ids << v }
61
+ end
62
+ ids.inject({}) {|r,id|
63
+ v = load(id)
64
+ if ( !( start_date && v[:fix_date] != 0 && v[:fix_date] < start_date.to_i ) \
65
+ && !( end_date && v[:date] > end_date.to_i ))
66
+ r[id] = v
67
+ end
68
+ r
69
+ }
70
+ end
71
+
72
+ # 指定の期間の損益データを得る。
73
+ def each( scale=:raw, start_date=nil, end_date=nil, &block )
74
+ @profit_or_loss_dao.each_data( scale, start_date, end_date ) {|row, time|
75
+ yield row
76
+ }
77
+ end
78
+
79
+ # 取引結果を記録する。
80
+ def next( operator, time )
81
+ @profit_or_loss_dao << BasicTimedData.new(
82
+ [operator.profit_or_loss, operator.fixed_profit_or_loss, operator.win_rate], time)
83
+ ids = operator.positions.map {|p| p[1].position_id }
84
+ @trade_dao << BasicTimedData.new( [ids], time)
85
+ end
86
+
87
+ # 取引結果を強制的に記録する。
88
+ def flush( time )
89
+ # 取引結果のみ(損益データは出力しない)
90
+ @trade_dao.flush(time)
91
+ end
92
+
93
+ private
94
+
95
+ def dao( name, aggregators )
96
+ dir = "#{@data_dir}/#{name}"
97
+ FileUtils.mkdir_p dir unless File.exists? dir
98
+
99
+ TimedDataDao.new( dir, aggregators )
100
+ end
101
+
102
+ def lock(file)
103
+ FileLock.new( "#{file}.lock" ).writelock {
104
+ yield
105
+ }
106
+ end
107
+
108
+ class TradeAggregator < AbstractAggregator
109
+ def aggregate( timed_data )
110
+ @values = Set.new unless @values
111
+ @values += timed_data.values[0]
112
+ end
113
+ def aggregated
114
+ begin
115
+ str = @values.to_a.join(" ")
116
+ return BasicTimedData.new( [str] \
117
+ + [@start.to_i, @end.to_i], @end)
118
+ ensure
119
+ @values.clear
120
+ end
121
+ end
122
+ attr_reader :values
123
+ end
124
+
125
+ end
126
+ end
127
+
128
+ end
data/lib/jiji/error.rb ADDED
@@ -0,0 +1,33 @@
1
+
2
+ module JIJI
3
+ # 致命的エラー
4
+ class FatalError < StandardError
5
+ def initialize( code, message="" )
6
+ super( message )
7
+ @code = code
8
+ end
9
+ attr :code
10
+ end
11
+ # ユーザー操作により発生しうるエラー
12
+ class UserError < StandardError
13
+ def initialize( code, message="" )
14
+ super( message )
15
+ @code = code
16
+ end
17
+ attr :code
18
+ end
19
+
20
+ # エラーコード:存在しない
21
+ ERROR_NOT_FOUND = "not_found"
22
+ # エラーコード:すでに存在する
23
+ ERROR_ALREADY_EXIST = "already_exist"
24
+
25
+ # エラーコード:不正な名前
26
+ ERROR_ILLEGAL_NAME = "illegal_name"
27
+
28
+ # エラーコード:想定外エラー
29
+ ERROR_FATAL = "fatal"
30
+
31
+ # エラーコード:サーバーに接続されていない
32
+ ERROR_NOT_CONNECTED = "not_connected"
33
+ end
@@ -0,0 +1,169 @@
1
+
2
+ require 'jiji/util/util'
3
+ require "jiji/dao/timed_data_dao"
4
+
5
+ module JIJI
6
+
7
+ #==レートの集合
8
+ class Rates < Hash
9
+
10
+ include JIJI::Util::Model
11
+
12
+ def initialize( pair_infos, list, time=Time.now )
13
+ super()
14
+ @pair_infos = pair_infos.inject({}){ |r,pair|
15
+ code = JIJI::Util.convert_currency_pair_code(pair[0])
16
+ r[code] = pair[1]
17
+ r
18
+ }
19
+ @time = time
20
+ list.each_pair { |k,info|
21
+ self[k] = Rate.new( info.bid.to_f, info.ask.to_f,
22
+ info.sell_swap.to_f, info.buy_swap.to_f, time)
23
+ }
24
+ end
25
+ # 通貨ペアの情報(取引数量など)
26
+ attr_reader :pair_infos
27
+ # 現在時刻
28
+ attr_reader :time
29
+ end
30
+
31
+ #==レート
32
+ class Rate
33
+
34
+ include JIJI::Util::Model
35
+ include JIJI::Dao::TimedData
36
+
37
+ def initialize( bid=nil, ask=nil, sell_swap=nil, buy_swap=nil, time=nil )
38
+ @bid = bid
39
+ @ask = ask
40
+ @sell_swap = sell_swap
41
+ @buy_swap = buy_swap
42
+ @time = time
43
+ end
44
+ # 値を配列で取得する
45
+ def values
46
+ [bid,ask,sell_swap,buy_swap,time.to_i]
47
+ end
48
+ # 値を配列で設定する
49
+ def values=(values)
50
+ @bid = values[0].to_f
51
+ @ask = values[1].to_f
52
+ @sell_swap = values[2].to_f
53
+ @buy_swap = values[3].to_f
54
+ end
55
+ attr_reader :bid, :ask, :sell_swap, :buy_swap
56
+ end
57
+
58
+ #==一定期間のレートの集合
59
+ class PeriodicallyRates < Hash
60
+
61
+ include JIJI::Util::Model
62
+
63
+ def initialize( pair_infos, list=[] )
64
+ super()
65
+ @pair_infos = pair_infos
66
+ list.each {|rates|
67
+ self << rates
68
+ }
69
+ end
70
+ def <<(rates)
71
+ now = rates.time
72
+ @start_time = now unless @start_time
73
+ @end_time = now
74
+ rates.each_pair { |code,rate|
75
+ self[code] = PeriodicallyRate.new unless key? code
76
+ self[code] << rate
77
+ }
78
+ end
79
+ def time
80
+ @start_time
81
+ end
82
+ attr_reader :pair_infos
83
+ attr :start_time, true
84
+ attr :end_time, true
85
+ end
86
+
87
+ #==一定期間のレート
88
+ #bid,ask,sell_swap,buy_swapは四本値(JIJI::PeriodicallyValue)で保持される。
89
+ class PeriodicallyRate
90
+
91
+ include JIJI::Util::Model
92
+ include JIJI::Dao::TimedData
93
+
94
+ def initialize( list=[] )
95
+ @bid = PeriodicallyValue.new
96
+ @ask = PeriodicallyValue.new
97
+ @sell_swap = PeriodicallyValue.new
98
+ @buy_swap = PeriodicallyValue.new
99
+ list.each { |item|
100
+ self << item
101
+ }
102
+ end
103
+ def <<( rate )
104
+ @bid << rate.bid
105
+ @ask << rate.ask
106
+ @sell_swap << rate.sell_swap
107
+ @buy_swap << rate.buy_swap
108
+ @start_time = rate.time unless @start_time
109
+ @end_time = rate.time
110
+ end
111
+ # 値を配列で取得する
112
+ def values
113
+ bid.values + ask.values + sell_swap.values + buy_swap.values \
114
+ + [@start_time.to_i, @end_time.to_i]
115
+ end
116
+ # 値を配列で設定する
117
+ def values=(values)
118
+ @bid.values = values[0..3]
119
+ @ask.values = values[4..7]
120
+ @sell_swap.values = values[8..11]
121
+ @buy_swap.values = values[12..15]
122
+ @start_time = Time.at(values[16].to_i)
123
+ @end_time = Time.at(values[17].to_i)
124
+ end
125
+ def time
126
+ @end_time
127
+ end
128
+ def time=(t)
129
+ @end_time = t
130
+ end
131
+ attr_reader :bid, :ask, :sell_swap, :buy_swap
132
+ attr :start_time, true
133
+ attr :end_time, true
134
+ end
135
+
136
+ #==一定期間の値
137
+ #始値、終値、高値、安値の四本値
138
+ class PeriodicallyValue
139
+
140
+ include JIJI::Util::Model
141
+
142
+ def initialize( list=[] )
143
+ list.each { |item|
144
+ self << item
145
+ }
146
+ end
147
+ def <<( value )
148
+ @start = value if @start == nil
149
+ @end = value
150
+ @max = value if @max == nil || value > @max
151
+ @min = value if @min == nil || value < @min
152
+ end
153
+ # 値を配列で取得する
154
+ def values
155
+ [@start, @end, @max, @min]
156
+ end
157
+ # 値を配列で設定する
158
+ def values=(values)
159
+ @start = values[0].to_f
160
+ @end = values[1].to_f
161
+ @max = values[2].to_f
162
+ @min = values[3].to_f
163
+ end
164
+ attr :start
165
+ attr :end
166
+ attr :max
167
+ attr :min
168
+ end
169
+ end
@@ -0,0 +1,105 @@
1
+
2
+ require 'thread'
3
+
4
+ module JIJI
5
+
6
+ #==コレクターからのレートの通知を受け取るクラス。
7
+ class ObserverManager
8
+ #コンストラクタ
9
+ #observers:: オブサーバー
10
+ #logger:: ロガー
11
+ def initialize( observers, logger )
12
+ @logger = logger
13
+ @observers = observers
14
+ end
15
+ #レートの通知を受ける
16
+ #rates:: レート
17
+ def next_rates( rates )
18
+ @observers.each {|w|
19
+ w.next_rates( rates )
20
+ }
21
+ end
22
+ #オブザーバーを追加する
23
+ #observer:: オブザーバー
24
+ def <<(observer)
25
+ @observers << observer
26
+ end
27
+ #通知を停止する
28
+ def stop
29
+ end
30
+ #ロガー
31
+ attr :logger, true
32
+ end
33
+
34
+
35
+ #==コレクターからのレートの通知を受け取り、別スレッドで処理するクラス。
36
+ #- 登録されたオブザーバーごとに専用のスレッドを起こして情報を通知する。
37
+ #- スレッドを破棄する必要があるため、必ずstopで停止すること。
38
+ class WorkerThreadObserverManager
39
+ #コンストラクタ
40
+ #observers:: オブサーバー
41
+ #logger:: ロガー
42
+ def initialize( observers, logger )
43
+ @logger = logger
44
+ @workers = observers.map {|o|
45
+ Worker.new( o, @logger )
46
+ }
47
+ end
48
+ #レートの通知を受ける
49
+ #rates:: レート
50
+ def next_rates( rates )
51
+ @workers.each {|w|
52
+ w.next_rates( rates )
53
+ }
54
+ end
55
+ #オブザーバーを追加する
56
+ #observer:: オブザーバー
57
+ def <<(observer)
58
+ @workers << Worker.new( observer, @logger )
59
+ end
60
+ #通知を停止する
61
+ def stop
62
+ @logger.info( "observer manager stop" )
63
+ @workers.each {|w| w.alive = false }
64
+ @workers.each {|w| w.thread.join }
65
+ @workers.clear
66
+ end
67
+ #ロガー
68
+ attr :logger, true
69
+ end
70
+
71
+ # ワーカースレッド
72
+ class Worker
73
+ def initialize( observer, logger )
74
+ @logger = logger
75
+ @alive = true
76
+ @alive_mutex = Mutex.new
77
+ @q = Queue.new
78
+ @thread = Thread.start {
79
+ while( !@q.empty? || alive? )
80
+ JIJI::Util.log_if_error( @logger ) {
81
+ rates = @q.pop
82
+ observer.next_rates( rates ) if rates != nil
83
+ }
84
+ end
85
+ }
86
+ end
87
+ def next_rates( rates )
88
+ @q.push rates
89
+ end
90
+ def alive?
91
+ @alive_mutex.synchronize {
92
+ @alive
93
+ }
94
+ end
95
+ def alive=(value)
96
+ @alive_mutex.synchronize {
97
+ @alive = value
98
+ @q.push nil # 眠れるスレッドをたたき起こす。
99
+ }
100
+ end
101
+
102
+ attr_reader :thread
103
+ end
104
+
105
+ end
@@ -0,0 +1,405 @@
1
+
2
+ require 'fileutils'
3
+ require 'delegate'
4
+ require 'jiji/util/util'
5
+ require 'jiji/single_click_client'
6
+ require 'jiji/util/util'
7
+ require 'jiji/dao/timed_data_dao'
8
+ require 'uuidtools'
9
+
10
+ module JIJI
11
+
12
+ #==オペレーター
13
+ class Operator
14
+
15
+ #===コンストラクタ
16
+ #*money*:: 保証金
17
+ def initialize( trade_result_dao=nil, money=nil )
18
+ @rate = nil
19
+ @money = money
20
+ @profit_or_loss = 0
21
+ @fixed_profit_or_loss = 0
22
+ @positions = {}
23
+ @draw = 0
24
+ @lose = 0
25
+ @win = 0.0
26
+ @trade_result_dao = trade_result_dao
27
+ end
28
+
29
+ #===レートを更新する。
30
+ def next_rates( rate )
31
+ @rate = rate
32
+ result = @positions.inject({:total=>0.0,:profit=>0}) {|r,e|
33
+ p = e[1]
34
+ p.next(rate)
35
+ r[:total] += p.price if p.state == Position::STATE_START
36
+ r[:profit] += p.profit_or_loss
37
+ r
38
+ }
39
+ @profit_or_loss = result[:profit] + @fixed_profit_or_loss
40
+ if @money && (( @money + result[:profit] ) / result[:total]) <= 0.007
41
+ raise "loss cut"
42
+ end
43
+ @trade_result_dao.next( self, rate.time ) if @trade_result_dao
44
+ end
45
+
46
+ #===購入する
47
+ #count:: 購入する数量
48
+ #pair:: 通貨ペア(:EURJPYなど)
49
+ #trader:: 取引実行者識別用の名前
50
+ #return:: Position
51
+ def buy(count, pair=:EURJPY, trader="")
52
+ rate = @rate[pair]
53
+ unit = @rate.pair_infos[pair].trade_unit
54
+ p = Position.new( UUID.random_create().to_s, Position::BUY, count,
55
+ unit, @rate.time, rate.ask, pair, trader, self )
56
+ p.next( @rate )
57
+ @profit_or_loss += p.profit_or_loss
58
+ @positions[p.position_id] = p
59
+ @trade_result_dao.save( p ) if @trade_result_dao
60
+ return p
61
+ end
62
+
63
+ #===売却する
64
+ #count:: 売却する数量
65
+ #pair:: 通貨ペア(:EURJPYなど)
66
+ #trader:: 取引実行者識別用の名前
67
+ #return:: Position
68
+ def sell(count, pair=:EURJPY, trader="")
69
+ rate = @rate[pair]
70
+ unit = @rate.pair_infos[pair].trade_unit
71
+ p = Position.new( UUID.random_create().to_s, Position::SELL, count,
72
+ unit, @rate.time, rate.bid, pair, trader, self )
73
+ p.next( @rate )
74
+ @profit_or_loss += p.profit_or_loss
75
+ @positions[p.position_id] = p
76
+ @trade_result_dao.save( p ) if @trade_result_dao
77
+ return p
78
+ end
79
+
80
+ # 取引を確定する
81
+ def commit(position)
82
+ position._commit
83
+ @trade_result_dao.save( position ) if @trade_result_dao
84
+ @positions.delete position.position_id
85
+
86
+ @fixed_profit_or_loss += position.profit_or_loss
87
+ if position.profit_or_loss == 0
88
+ @draw+=1
89
+ elsif position.profit_or_loss < 0
90
+ @lose+=1
91
+ else
92
+ @win+=1
93
+ end
94
+ end
95
+
96
+ # 勝率
97
+ def win_rate
98
+ win > 0 ? win / (win+lose+draw) : 0.0
99
+ end
100
+
101
+ # 未約定のポジションデータを"ロスト"としてマークする。
102
+ def stop
103
+ @positions.each_pair {|k, v|
104
+ v.lost
105
+ @trade_result_dao.save( v ) if @trade_result_dao
106
+ }
107
+ end
108
+
109
+ # すべてのポジションデータを保存する。
110
+ def flush
111
+ @positions.each_pair {|k, v|
112
+ @trade_result_dao.save( v ) if @trade_result_dao
113
+ }
114
+ end
115
+
116
+ #現在の損益
117
+ attr_reader :profit_or_loss
118
+ #現在の確定済み損益
119
+ attr_reader :fixed_profit_or_loss
120
+ #建て玉
121
+ attr :positions
122
+
123
+ # 勝ち数
124
+ attr_reader :win
125
+ # 負け数
126
+ attr_reader :lose
127
+ # 引き分け
128
+ attr_reader :draw
129
+
130
+ attr :conf, true
131
+ end
132
+
133
+
134
+
135
+ #==ポジション
136
+ class Position
137
+
138
+ #売り/買い区分
139
+ SELL = 0
140
+ BUY = 1
141
+
142
+ #状態:注文中
143
+ STATE_WAITING = 0
144
+ #状態:新規
145
+ STATE_START = 1
146
+ #状態:決済注文中
147
+ STATE_FIX_WAITING = 2
148
+ #状態:決済済み
149
+ STATE_FIXED = 3
150
+ #状態:約定前にシステムが再起動された
151
+ STATE_LOST = 4
152
+
153
+ #===コンストラクタ
154
+ #
155
+ #*sell_or_buy*:: 売りor買い
156
+ #*count*:: 数量
157
+ #*unit*:: 取引単位
158
+ #*date*:: 取引日時
159
+ #*rate*:: レート
160
+ #*pair*:: 通貨ペア
161
+ #*trader*:: 取引実行者
162
+ #*operator*:: operator
163
+ #*open_interest_no*:: 建玉番号
164
+ #*order_no*:: 注文番号
165
+ def initialize( position_id, sell_or_buy, count, unit, date, rate, pair,
166
+ trader, operator, open_interest_no="", order_no="" )
167
+ @position_id = position_id
168
+ @sell_or_buy = sell_or_buy
169
+ @count = count
170
+ @unit = unit
171
+ @price = (count*unit*rate).to_i
172
+ @date = date
173
+ @profit_or_loss = 0
174
+ @state =STATE_START
175
+ @rate = rate
176
+ @pair = pair
177
+ @trader = trader
178
+
179
+ @open_interest_no = open_interest_no
180
+ @order_no = order_no
181
+
182
+ @operator = operator
183
+ @info = {}
184
+ @swap = 0
185
+ @swap_time = Time.local( date.year, \
186
+ date.month, date.day, operator.conf.get([:swap_time], 5 ))
187
+ @swap_time += 60*60*24 if date > @swap_time
188
+ end
189
+
190
+ def _commit
191
+ raise "illegal state" if @state != STATE_START
192
+ @state = STATE_FIXED
193
+ @fix_date = @current_date
194
+ @fix_rate = @current_rate
195
+ end
196
+
197
+ def lost
198
+ @state = STATE_LOST
199
+ end
200
+
201
+ #===現在価格を更新
202
+ def next(rates)
203
+ return if @state == STATE_FIXED
204
+ rate = rates[@pair]
205
+ @current_rate = @sell_or_buy == BUY ? rate.bid : rate.ask
206
+ @current_price = (@count * @unit * @current_rate).to_i
207
+
208
+ # swap
209
+ if @swap_time <= rates.time
210
+ @swap += @sell_or_buy == BUY ? rate.buy_swap : rate.sell_swap
211
+ @swap_time += 60*60*24
212
+ end
213
+
214
+ @profit_or_loss = @sell_or_buy == BUY \
215
+ ? @current_price - @price + @swap\
216
+ : @price - @current_price + @swap
217
+
218
+ @current_date = rates.time
219
+ end
220
+
221
+ def [](key)
222
+ @info[key]
223
+ end
224
+ def []=(key, value)
225
+ @info[key] = value
226
+ end
227
+
228
+ def values
229
+ {
230
+ :position_id => position_id,
231
+ :open_interest_no=> open_interest_no,
232
+ :sell_or_buy => sell_or_buy == JIJI::Position::SELL ? :sell : :buy,
233
+ :state => state,
234
+ :date => date.to_i,
235
+ :fix_date => fix_date.to_i,
236
+ :count => count ,
237
+ :price => price,
238
+ :profit_or_loss => profit_or_loss.to_i,
239
+ :rate => rate,
240
+ :fix_rate => fix_rate,
241
+ :swap=> swap,
242
+ :pair => pair,
243
+ :trader => trader
244
+ }
245
+ end
246
+
247
+ # クライアント
248
+ attr :operator
249
+ # 建玉番号
250
+ attr :open_interest_no, true
251
+ # 注文番号
252
+ attr :order_no, true
253
+
254
+ # 一意な識別子
255
+ attr_reader :position_id
256
+ # 売りか買いか?
257
+ attr_reader :sell_or_buy
258
+ # 状態
259
+ attr_reader :state
260
+
261
+ # 購入日時
262
+ attr_reader :date
263
+ # 決済日時
264
+ attr_reader :fix_date
265
+ # 取引数量
266
+ attr_reader :count
267
+ # 取得金額
268
+ attr_reader :price
269
+ # 現在価値
270
+ attr_reader :current_price
271
+ # 現在の損益
272
+ attr_reader :profit_or_loss
273
+ # 購入時のレート
274
+ attr_reader :rate
275
+ # 決済時のレート
276
+ attr_reader :fix_rate
277
+ # 決済時のレート
278
+ attr_reader :swap
279
+ # 通貨ペア
280
+ attr_reader :pair
281
+ # 取引実行者
282
+ attr_reader :trader
283
+ end
284
+
285
+ #==リアル取引用オペレーター
286
+ class RmtOperator < Operator
287
+
288
+ #===コンストラクタ
289
+ #*client*:: クライアント
290
+ #*logger*:: ロガー
291
+ #*money*:: 保証金
292
+ def initialize( client, logger, trade_result_dao, trade_enable=true, money=nil )
293
+ super(trade_result_dao,money)
294
+ @client = client
295
+ @logger = logger
296
+ @trade_enable = trade_enable
297
+ end
298
+
299
+ #===購入する
300
+ #*count*:: 購入する数量
301
+ #*return*:: Position
302
+ def buy(count, pair=:EURJPY, trader="")
303
+ open_interest_no = nil
304
+ order_no = nil
305
+ if @trade_enable
306
+ JIJI::Util.log_if_error_and_throw( @logger ) {
307
+ rate = @rate[pair]
308
+ # 成り行きで買い
309
+ result = @client.request{ |fx|
310
+ fx.order( JIJI::Util.convert_currency_pair_code_r(pair),
311
+ ClickClient::FX::BUY, count, options={:slippage_base_rate=>rate.bid} )
312
+ }
313
+ open_interest_no = result.open_interest_no
314
+ order_no = result.order_no
315
+ }
316
+ end
317
+ p = super(count, pair, trader)
318
+ p.open_interest_no = open_interest_no
319
+ p.order_no = order_no
320
+ p
321
+ end
322
+
323
+ #===売却する
324
+ #*count*:: 売却する数量
325
+ #*return*:: Position
326
+ def sell(count, pair=:EURJPY, trader="")
327
+ open_interest_no = nil
328
+ order_no = nil
329
+ if @trade_enable
330
+ JIJI::Util.log_if_error_and_throw( @logger ) {
331
+ rate = @rate[pair]
332
+ # 成り行きで売り
333
+ result = @client.request {|fx|
334
+ fx.order( JIJI::Util.convert_currency_pair_code_r(pair),
335
+ ClickClient::FX::SELL, count, options={:slippage_base_rate=>rate.ask} )
336
+ }
337
+ open_interest_no = result.open_interest_no
338
+ order_no = result.order_no
339
+ }
340
+ end
341
+ p = super(count, pair, trader)
342
+ p.open_interest_no = open_interest_no
343
+ p.order_no = order_no
344
+ p
345
+ end
346
+
347
+ # 取引を確定する
348
+ def commit(position)
349
+ if @trade_enable
350
+ JIJI::Util.log_if_error_and_throw( @logger ) {
351
+ @client.request {|fx|
352
+ fx.settle( position.open_interest_no, position.count )
353
+ }
354
+ }
355
+ end
356
+ super(position)
357
+ end
358
+
359
+ attr :trade_enable, true
360
+ end
361
+
362
+ # 各エージェントに設定されるオペレータ。
363
+ # 取引者としてエージェント名を指定して売り買いを行なう。
364
+ # また、建玉を独自に保持する。(エージェント間で共有されない)
365
+ # 売/買ロジック自体ははオペレータに委譲する。
366
+ class AgentOperator
367
+ def initialize( operator, agent_name )
368
+ @operator = operator
369
+ @name = agent_name
370
+ @positions = {}.taint
371
+ end
372
+
373
+ #===購入する
374
+ #count:: 購入する数量
375
+ #pair:: 通貨ペア
376
+ #return:: ポジション
377
+ def buy(count, pair=:EURJPY)
378
+ p = @operator.buy( count, pair, @name )
379
+ @positions[p.position_id] = p
380
+ return p
381
+ end
382
+
383
+ #===売却する
384
+ #count:: 売却する数量
385
+ #pair:: 通貨ペア
386
+ #return:: ポジション
387
+ def sell(count, pair=:EURJPY)
388
+ p = @operator.sell( count, pair, @name )
389
+ @positions[p.position_id] = p
390
+ return p
391
+ end
392
+
393
+ # 取引を確定する
394
+ def commit(position)
395
+ @operator.commit(position)
396
+ @positions.delete position.position_id
397
+ end
398
+
399
+ #建て玉
400
+ attr_reader :positions
401
+
402
+ end
403
+
404
+ end
405
+