spacepaste

  1.  
  2. # Takes two inputs.
  3. # Two small floats.
  4. # Example, price = 0.03403234, vol= 0.0025
  5. # for given price and volume. calulate the next valid price for same volume by incrementing price
  6. # smallet increment is in price can only be 0.00000001
  7. def calc(price, vol):
  8. inc = 0.000000010
  9. exp = 8
  10. p = price
  11. v = vol
  12. i = 0
  13. while True:
  14. i+=1
  15. p += inc
  16. # If the sum have any fractions|desimals larger than 0 then its not valid.
  17. sum = format(float(v) * (float(p) * 10 ** exp),'.8f')
  18. x = int(sum.split(".")[1])
  19. if x == 0:
  20. return [int(float(sum)), p]
  21. # Takes to long i guess, just return zero
  22. if i > 10000:
  23. return [0,0]
  24. vol = 0.0025
  25. old_price = 0.03403234
  26. res = calc(old_price, vol)
  27. print("vol :", format(vol, '.8f'))
  28. print("old price:", format(old_price, '.8f'))
  29. print("new price:", format(r[1], '.8f'))
  30.