Skip to content

Instantly share code, notes, and snippets.

@baont
Created April 19, 2021 07:16
Show Gist options
  • Select an option

  • Save baont/b08478b4b63bf7d127c295b7b5bb7fd6 to your computer and use it in GitHub Desktop.

Select an option

Save baont/b08478b4b63bf7d127c295b7b5bb7fd6 to your computer and use it in GitHub Desktop.
decimal = min decimal # vd 1 2 3 4 thì lấy 1
sum_buy = 0
sum_sell = 0
# tìm depth mà sum_buy > 1.5*sum_sell
depth_i = -1
for depth = 0 to 100:
sum_buy += usdt sum buy at depth, decimal
sum_sell += usdt sum sell at depth, decimal
if sum_buy > 1.5 sum_sell:
depth_i = depth
break;
if depth_i = -1 # tìm ko thấy depth nào thoả sum_buy > 1.5*sum_sell
exit
if usdt sum buy at 0, decimal > usdt sum sell at 0, decimal
# giá sum ở depth 0 bên mua cao hơn bên bán -> giá tăng
buy_price_range = (price_buy [decimal , depth_i], price [decimal , depth_i]+ 1 đơn vị nhỏ hơn]
decimal_2 = decimal + 1 # drill 1 level
sum_amount_buy = 0
sum_amount_sell = 0
sum_usdt_buy = 0
sum_usdt_sell = 0
for i = 0 to 100
sum_amount_buy += amount_buy[decimal_2, i]
sum_amount_sell += amount_sell[decimal_2, i]
sum_usdt_buy += usdt sum buy at i, decimal_2
sum_usdt_sell += usdt sum sell at i, decimal_2
break tại i đầu tiên thoả (price_buy[decimal_2, i] nằm trong buy_price_range) and (sum_amount_buy < sum_amount_sell)
and (sum_usdt_buy[i+1] > sum_usdt_sell[i+1])
return price_buy = price_buy[decimal_2, i]
if usdt sum buy at 0, decimal < usdt sum sell at 0, decimal
# giá sum ở depth 0 bên mua thấp hơn bên bán -> giá
buy_price_range = (price_buy [decimal , depth_i] - 1 đơn vị nhỏ hơn , price [decimal , depth_i]]
decimal_2 = decimal + 1 # drill 1 level
sum_amount_buy = 0
sum_amount_sell = 0
sum_usdt_buy = 0
sum_usdt_sell = 0
for i = 0 to 100
sum_amount_buy += amount_buy[decimal_2, i]
sum_amount_sell += amount_sell[decimal_2, i]
sum_usdt_buy += usdt sum buy at i, decimal_2
sum_usdt_sell += usdt sum sell at i, decimal_2
break tại i đầu tiên thoả (price_buy[decimal_2, i] nằm trong buy_price_range) and (sum_usdt_buy[i+1] < sum_usdt_sell[i+1])
(sum_amount_buy > sum_amount_sell)
return price_buy = price_buy[decimal_2, i]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment