Skip to content

Instantly share code, notes, and snippets.

@mingyu-kwak
Created November 20, 2017 08:01
Show Gist options
  • Select an option

  • Save mingyu-kwak/abcfeaae1cece1814336166b9c793f59 to your computer and use it in GitHub Desktop.

Select an option

Save mingyu-kwak/abcfeaae1cece1814336166b9c793f59 to your computer and use it in GitHub Desktop.
주식 자동거래 p.160~163 개선 (단위 테스트 필요)
public int get_hoga_unit_price(int i_price, string i_jongmok_cd, int i_hoga_unit_jump)
{
int l_market_type = 0;
try
{
l_market_type = int.Parse(axKHOpenAPI1.GetMarketType(i_jongmok_cd).ToString());
}
catch (Exception e)
{
write_err_log("get_hogk_unit_price() e.Message : " + e.Message, 0);
}
int l_rest;
int range_flag = -1;
int[][] hoga =
new[]
{
new[] { 1, 5, 10, 50, 100, 500, 1000 }, // 코스피 호가
new[] { 1, 5, 10, 50, 100, 100, 100 } // 코스닥 호가
};
int[] range = {0, 1000, 5000, 10000, 50000, 100000, 500000, int.MaxValue};
for (var i = 0; i < range.Length - 1; i++)
{
if (i_price >= range[i] && i_price < range[i + 1])
{
range_flag = i;
break;
}
}
if (range_flag == -1)
{
return -1;
}
if (l_market_type == 10) // 코스닥이면
{
l_market_type = 1;
}
l_rest = i_price % hoga[l_market_type][range_flag];
if (l_rest == 0)
{
return i_price + (i_hoga_unit_jump * hoga[l_market_type][range_flag]);
}
if (l_rest < (hoga[l_market_type][range_flag] / 2))
{
return (i_price - l_rest) + (i_hoga_unit_jump * hoga[l_market_type][range_flag]);
}
return (i_price + (hoga[l_market_type][range_flag] - l_rest))
+ (i_hoga_unit_jump * hoga[l_market_type][range_flag]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment