Using Python as a quantitative investment---handicap high frequency strategy

Source: Internet
Author: User
Tags diff eval sleep

How to use: Put the previous configuration foundation, write to a python file, file name saved as Okcoinspotapi, and then put the following code, write to a new file, save it, you can directly run the

Principle: According to the handicap sale volume, the depth market pending orders quantity, carries on the sale decision-making. belong to high-frequency strategy.

Note: This strategy has been made firm and has been withdrawn. If used, it is recommended to further optimize.

One more step, qq:1733505732.

Please specify: python, bitcoin quantization

#-*-Coding:utf-8-*-"" "Created on Mon with 17:40:55 2017 @author: Yunjinqi e-mail:yunjinqi@qq.com
yourself in the world from anyone else. "" "####################################################### #盘口模型 from okcoinspotapi import * Import pandas as PD import n Umpy as NP import datetime import time ##################################################### #初始数据 #引入初始信息 apikey = ' 9b93e 53a-e803-4883-b8fc-64af2f3ccc57 ' Secretkey = ' 14284b3c0b9cf0f932e83888388855c9 ' okcoinresturl = ' www.okcoin.cn ' # Note: The domestic account needs to be modified to www.okcoin.cn Okcoinspot = Okcoinspot (okcoinresturl,apikey,secretkey) okcoinfuture = Okcoinfuture ( Okcoinresturl,apikey,secretkey) #info =eval (Okcoinspot.userinfo ()) #账户信息 #info #################################### #获取并整理数据 def cut (deep): deep[' bid_price ']= ' deep[' bid_volume ', ']= ', ' deep[' ask_price ', ']= ', ' deep[', ' Ask_price ' ' For I in Range (len (deep)): Deep.ix[i, ' Bid_price ']=deep.ix[i, ' bids '][0] deep.ix[i, ' Bid_volume ']=deep . Ix[i, ' BIDs '][1] deep.ix[i, ' Ask_price ']=deep.ix[i, ' asks '][0] deep.ix[i, ' Ask_volume ']=deep.ix[i, ' asks '][1] Del deep[' asks '] del deep[' bids '] deep[' bid_price ']=deep[' Bid_price ' to ('].astype ' float64 ') deep[' bid_volume ']=deep[' b Id_volume '].astype (' float64 ') deep[' ask_price ']=deep[' Ask_price '].astype (' float64 ') deep[' ask_price ']=deep[' Price '].astype (' float64 ') return deep def Bid_ask_vol_diff (deep): bidvol10=deep[' Bid_volume ' "][:10" askvol10=de ep[' Ask_volume '][-10:] Diff=bidvol10.sum ()-askvol10.sum () return diff #diff >0 is the admission condition 1 def bid_ask_price_diff (de EP): bidprice10=deep[' Bid_price '][:10] askprice10=deep[' Ask_price '][-10:] Bid_diff=bidprice10.max ()-bidprice10 . Min () Ask_diff=askprice10.max ()-askprice10.min () Diff=bid_diff-ask_diff #小于0是入场条件 return diff def Bid_ask_big Vol. (Deep): bidvol10=deep[' Bid_volume '][:10] askvol10=deep[' Ask_volume '][-10:] Diff=bidvol10.max () >askvol10. Max () #大于0是入场条件 returnDiff i=0 while True:deep=pd. Dataframe (okcoinspot.depth (' Btc_cny ')) deep=cut (deep) deep if Bid_ask_vol_diff (deep) >0 and Bid_ask_price_di FF (deep) <0 and Bid_ask_bigvol (deep) >0:price_buy=str (deep[' Bid_price '][1]+0.01) buy=okcoinspot.trade (' Btc_cny ', ' buy ', price_buy, ' 0.01 ') time.sleep (0.2) price_sell=str (deep[' Bid_price "][1]+0.50) sell=okcoin 
        Spot.trade (' Btc_cny ', ' sell ', Price_sell, ' 0.01 ') print (Sell) i=i+1 Try:buyid=str (eval (Buy) [' order_id ']) Sellid=str (eval (Sell) [' order_id ']) except Nameerror:pass except time. Sleep (5) try:cancel_buy=okcoinspot.cancelorder (' Btc_cny ', Buyid) cance1_sell=okcoinspot.cancelorder (' BTC _cny ', sellid) except Nameerror:pass except Keyerror:pass Info_btc_free=eval (eval (okcoinspot. UserInfo ()) [' Info '] [' funds '] [' free '] [' BTC ']] info_net=eval (eval (Okcoinspot.userinfo ()) [' Info '] [' funds '] [' Asset ' [' net ']] print (i,info_btc_free,info_net) 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.