Algo Trading:简单的等间距网格下单

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%

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值