The resource loading... loading...

We did a grid transaction retrieval feature online with FMZ.

Author: I won't quantify it., Created: 2020-10-18 23:56:01, Updated:

Back to basics

I've been looking for a real-time feedback tool for a while, and the vnpy feels like it's too much trouble to switch to an interface. Finally, I turned to the documentation in FMZ's new guide. We've been working on it for six months, and we've been working on it for six months, and we've been working on it for six months. By the way, there are very few articles on fmz, which is useful in the beginner's guide.

The first is that users can choose their own start and end times.img

This thing needs to be parameterized:

imgIt feels like a stupid way to do it, I don't know if there are any functions that can be initialized.

self.grid_setting = {
          "min_price": min_price,
          "max_price": max_price,
          "grid_diff": grid_diff,
          "re_diff": grid_diff,
          "total_amount_B": total_amount_B
      }

Grid configuration parameters: minimum, maximum price, distribution interval of the grid and interval of re-attachment.

The above are parameters submitted by the user.

The main bus function is

    def bus(self):
      params = gen_params(self.begin, self.end, self.currency, self.balance, self.stocks)
      task = VCtx(params)
      done = self.train()
      ret = task.Join(True)
      benefit_cal = self.cal_benefit(ret,done)
      result = {}
      result['done'] = done
      result['ret'] = benefit_cal
      return result
  • Retrieve the retrieval configuration of fmz with the gen_params function that was just created
  • Running training functions
  • Calculates the yield and displays the transaction records according to the data structure returned by fmz

Calling the task.Join () will terminate the retrieval task and return the net value data. The join parameter does not pass True, returns the original unanalyzed retrieval result, and cannot call the transaction or market-related function after the end.

Through the documentation, I'm guessing what the tactical results are going to mean.

The code is calculated by adding fmz returns to the gain data

  def cal_benefit(self,ret,done):
      #计算相隔多少天
      day_begin =  datetime.datetime.strptime(self.begin, '%Y-%m-%d %H:%M:%S')
      day_end =  datetime.datetime.strptime(self.end, '%Y-%m-%d %H:%M:%S')
      days = (day_end - day_begin).days
      begin = ret.iloc[0].net
      end = ret.iloc[-1].net
      fee = ret.iloc[-1].fee
      #计算一共多少次套利
      df = pd.DataFrame(done)
      #如果没有成交记录
      if len(done) == 0:
          benefit_cal = {}
          benefit_cal['benefit'] = 0
          benefit_cal['count'] = 0
          benefit_cal['fee'] = 0
          benefit_cal['benefit_p'] = 0
          return benefit_cal

      buy_count = len(df[df['type'] == 'buy'])
      sell_count = len(df[df['type'] == 'sell'])
      count = min(buy_count , sell_count)
      benefit = count * self.grid_diff * float(done[0]['amount'])
      benefit_cal = {}
      benefit_cal['benefit']= benefit
      benefit_cal['count']= count
      benefit_cal['fee']= fee
      print(benefit_cal)
      per = benefit / self.total_amount_B * 360 / days
      print(per)
      benefit_cal['benefit_p']= round( per , 4)
      return benefit_cal

I'm sure it's a bit confusing, but first let me tell you about the idea of our grid:

The idea behind the hanging checklist

  • First, initialize the grid based on the user's parameters.
  • The first listing
  • Check the transaction status of the order on time and re-order according to the order
          while True:
              Sleep(1000 * 60 * 5)
              if 'refreash_data_finish!' != mid.refreash_data():
                  continue
              # 初始化网格
              if not init_flag:
                  cur_price = mid.ticker['Last']
                  grid_list = grid.cal_grid_list(cur_price)
                  init_flag = True

              # 开始挂单
              if not place_flag:
                  grid.place_orders()
                  place_flag = True

              # 开始检查订单状态及时挂单
              grid.check_order_update()
              done = grid.done

I think that's what it is, and it may seem strange at first glance.

This time I want to share mainly to express the speed of FMZ echoes in 14 days basically meets the user's waiting time at the front end, longer is a bit slower, is a good tool to quantify echoes as an interface, congratulations!

Yes, this time we are back to promote a wave of trading competition, our team of everwin quantification has organized a trading competition, free to participate. As long as everyone provides the API of the inquiry, you can register successfully, as a two-week competition, our bonus is also good. Leave a contact form fengye607.


More

The grassYou need to get the real-time transaction and then simulate the results of the retrieval. This can be a bit of a hassle, but if it's just a single transaction pair you can try writing your own retrieval engine, which is not complicated.