現貨期權期貨/合約量化/量化合約/秒合約/永續合約/交易所繫統開發成熟技術及原始碼

xiaofufu發表於2023-02-23

  The contract trading system is a derivative product of digital assets.Users can gain gains from the rise/fall of the price of digital assets by judging the rise and fall and choosing to buy long or sell short contracts.The contract trading system uses the differential delivery mode.When the contract expires,all open positions will be closed according to the arithmetic average price of the last period of the index price,rather than physical delivery


  def in_longhu(ts_code,date):


  date=str(date)


  y=date[0:4]


  m=date[4:6]


  d=date[6:8]


  global market


  #date=y+'-'+m+'-'+d


  path='./longhudata/'


  faceDir=Path(path)


  if faceDir.exists():


  file_dir=path+market+date+'.csv'


  else:


  os.mkdir(faceDir)


  file_dir=path+market+date+'.csv'


  #判斷檔案是否存在,不存在則透過網路介面獲得


  if os.path.exists(file_dir):


  df=pd.read_csv(file_dir)


  codes=df['ts_code'].values


  else:


  #初始化pro介面


  pro=ts.pro_api('ee5c0e991e17949cdafbcf8ec42321ef4bac94e9ca3474e4d62313a3')


  df=pro.top_list(trade_date=date)


  df.to_csv(file_dir,index=False,encoding="utf_8_sig")


  codes=df['ts_code'].values


  #print(codes)


  for c in codes:


  if c==ts_code:


  print(c,ts_code,date,True)


  return True


  #print(date,ts_code,False)


  return False


  def get_gainian():


  pro=ts.pro_api('ee5c0e991e17949cdafbcf8ec42321ef4bac94e9ca3474e4d62313a3')


  path='./概念/'


  dir=Path(path)


  if not dir.exists():


  os.mkdir(dir)


  file=path+'A概念.csv'


  if os.path.exists(file):


  df=pd.read_csv(file)


  else:


  df=pro.concept()


  df.to_csv(file,encoding='utf_8_sig')


  names=df['name'].values


  codes=df['code'].values


  for name,code in zip(names,codes):


  name=str.replace(name,'/','')


  namefile=path+name+'.csv'


  if not os.path.exists(namefile):


  df=pro.concept_detail(id=code)


  df.to_csv(namefile,encoding='utf_8_sig')


  #獲取程式碼對應的名字


  def get_code_name(ts_code):


  code_list=pd.read_csv('all_codes.csv')


  codes=code_list['ts_code'].values


  names=code_list['name'].values


  i=0


  for code in codes:


  if code==ts_code:


  return names<i>


  else:


  i=i+1


  print('NOName**************************NoName')


  return'noName'


  #獲取名字對應程式碼


  def get_name_code(name):


  code_list=pd.read_csv('all_codes.csv')


  codes=code_list['ts_code'].values


  names=code_list['name'].values


  i=0


  for find in names:


  if name==find:


  return codes<i>


  else:


  i=i+1


  print('NOCode**************************NOCode')


  return'NoCode'


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69956839/viewspace-2936755/,如需轉載,請註明出處,否則將追究法律責任。

相關文章