Digital currency market making technology - random price

First, taking the random number

ticker follows

{'bid': 0.0131, 'ask': 0.0139, 'last': 0.0134}

Use Python3 own random number,

random.uniform (x, y) The method of generating a random real number, it is within [x, y] range.
price_quant = round(random.uniform(ticker['bid'], ticker['ask']))

The following values

0.013129986458554987
0.013560374857658363
0.01369777925459942
0.013783165049587678
0.013895282774288966
0.013270566637852447
0.01349905426904132
0.013599971576874823
0.013235747582137573
0.013416767768451226

Coupled with a precision setting

price_quant = round(random.uniform(ticker['bid'], ticker['ask']), precision[symbol]["price"])

Returns the following

0.0139
0.0131
0.0139
0.0136
0.0139
0.0135
0.0136
0.0138
0.0138
0.0134
0.0137
0.0136
0.0137
0.0132
0.0136
0.0132
0.0139
0.0136
0.0132
0.0138

 

Second, the problem of rounding

Because of problems of rounding, will hit the part of the digital values ​​Handicap, then we need to further offset

price_quant = round(random.uniform(ticker['bid'] + pow(10, -1*precision[symbol]["price"]), ticker['ask'] - pow(10, -1*precision[symbol]["price"])), precision[symbol]["price"]) # 比特量化

Returns the following

0.0136
0.0133
0.0138
0.0135
0.0133
0.0133
0.0133
0.0134
0.0137
0.0136
0.0133
0.0135
0.0133
0.0134
0.0134
0.0134
0.0134
0.0137
0.0133
0.0132

Get the desired data.

 

Guess you like

Origin www.cnblogs.com/fangbei/p/random-price.html