-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdata_source.lua
More file actions
150 lines (120 loc) · 3.7 KB
/
data_source.lua
File metadata and controls
150 lines (120 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
CreateDataSourceOrig = CreateDataSource
local DS_ID_NOT_FOUND = -1
-- Создаем data source, в случае успеха возвращаем id data source
function CreateDataSource(class_code, sec_code, interval, param)
local ds, error
if (param) then
ds, error = CreateDataSourceOrig(class_code, sec_code, getInterval(interval), param)
else
ds, error = CreateDataSourceOrig(class_code, sec_code, getInterval(interval))
end
if (error) then
return error
end
table.insert(ds_tables, ds)
return #ds_tables
end
-- Open
function O(id, index)
if (ds_tables[id] == nil) then
return DS_ID_NOT_FOUND
end
return ds_tables[id]:O(index)
end
-- High
function H(id, index)
if (ds_tables[id] == nil) then
return DS_ID_NOT_FOUND
end
return ds_tables[id]:H(index)
end
-- Low
function L(id, index)
if (ds_tables[id] == nil) then
return DS_ID_NOT_FOUND
end
return ds_tables[id]:L(index)
end
-- Close
function C(id, index)
if (ds_tables[id] == nil) then
return DS_ID_NOT_FOUND
end
return ds_tables[id]:C(index)
end
-- Volume
function V(id, index)
if (ds_tables[id] == nil) then
return DS_ID_NOT_FOUND
end
return ds_tables[id]:V(index)
end
-- Time
function T(id, index)
if (ds_tables[id] == nil) then
return DS_ID_NOT_FOUND
end
return ds_tables[id]:T(index)
end
-- Size
function Size(id)
if (ds_tables[id] == nil) then
return DS_ID_NOT_FOUND
end
return ds_tables[id]:Size()
end
-- Close
function Close(id)
if (ds_tables[id] == nil) then
return DS_ID_NOT_FOUND
end
local result = ds_tables[id]:Close()
if (result) then
table.remove(ds_tables, id)
end
return result
end
-- SetUpdateCallback
function SetUpdateCallback(id)
if (ds_tables[id] == nil) then
return DS_ID_NOT_FOUND
end
return ds_tables[id]:SetUpdateCallback(function (index)
if c == nil then return end
c:send(config.send_delimitter .. json_encode({
id = "callback",
callback_name = "UpdateCallback",
ds_id = id,
result = index,
}))
PrintDbgStr("UpdateCallback")
end)
end
-- SetEmptyCallback
function SetEmptyCallback(id)
if (ds_tables[id] == nil) then
return DS_ID_NOT_FOUND
end
return ds_tables[id]:SetEmptyCallback()
end
-- Возвращает значение интервала по строке
function getInterval(interval_string)
if (interval_string == "INTERVAL_TICK") then return INTERVAL_TICK
elseif (interval_string == "INTERVAL_M1") then return INTERVAL_M1
elseif (interval_string == "INTERVAL_M2") then return INTERVAL_M2
elseif (interval_string == "INTERVAL_M3") then return INTERVAL_M3
elseif (interval_string == "INTERVAL_M4") then return INTERVAL_M4
elseif (interval_string == "INTERVAL_M5") then return INTERVAL_M5
elseif (interval_string == "INTERVAL_M6") then return INTERVAL_M6
elseif (interval_string == "INTERVAL_M10") then return INTERVAL_M10
elseif (interval_string == "INTERVAL_M15") then return INTERVAL_M15
elseif (interval_string == "INTERVAL_M20") then return INTERVAL_M20
elseif (interval_string == "INTERVAL_M30") then return INTERVAL_M30
elseif (interval_string == "INTERVAL_H1") then return INTERVAL_H1
elseif (interval_string == "INTERVAL_H2") then return INTERVAL_H2
elseif (interval_string == "INTERVAL_H4") then return INTERVAL_H4
elseif (interval_string == "INTERVAL_D1") then return INTERVAL_D1
elseif (interval_string == "INTERVAL_W1") then return INTERVAL_W1
elseif (interval_string == "INTERVAL_MN1") then return INTERVAL_MN1
end
end