class SplitPricer(Pricer):
def __init__(self, pdesc, bid, ask):
super().__init__(pdesc)
self.bid = bid
self.ask = ask
def price(self)->list:
lb = self.ask if self.pdesc['LB']=='ASK' else Decimal(self.pdesc['LB'])
ub = self.bid if self.pdesc['UB']=='BID' else Decimal(self.pdesc['UB'])
assert( not (self.pdesc['LB'] in ['BID','ASK'] and self.pdesc['UB'] in ['BID','ASK']) )
n = int(self.pdesc['NT'] ) # Number of Trades
n -= 1 # To facilitate arange below (arange exludes right bound)
assert( lb < ub )
assert( (lb >= self.ask and ub > self.ask)
or
(lb < self.bid and ub <= self.bid ))
d = (ub-lb)/n
prices = np.arange(lb, ub+d, d).tolist()
amount_ratio = np.ones(len(prices))/len(prices) # By default, equal amount at each prices
return list( zip(prices,amount_ratio) )
其中“pdesc”类似以下格式(yml):
...
- NAME: split-main-order
ACTION: split-buy
EXCHANGE: BINANCE
SYMBOL: BTC-USDT
PRICE:
T: SPLIT
LB: 15000
UB: 17798
NT: 3
AMOUNT: 0.03
TYPE: limit
TIF: 20201122 03:50:00
结果如下:
ex symbol price qty type tif_now from_md
...
9 BINANCE BTC-USDT 15000.00 0.0100 split-buy 0 days 16:48:58.884529 -15.7%
10 BINANCE BTC-USDT 16399.00 0.0100 split-buy 0 days 16:48:58.884529 -7.9%
11 BINANCE BTC-USDT 17798.00 0.0100 split-buy 0 days 16:48:58.884529 -0.0%