这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged

ok #1

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
113 changes: 113 additions & 0 deletions Python版多品种追涨杀跌策略(教学).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

> 策略名称

Python版多品种追涨杀跌策略(教学)

> 策略作者

小小梦

> 策略描述

https://www.fmz.com/bbs-topic/4959



> 源码 (python)

``` python
'''backtest
start: 2019-02-20 00:00:00
end: 2020-01-10 00:00:00
period: 1m
exchanges: [{"eid":"OKEX","currency":"BTC_USDT"},{"eid":"OKEX","currency":"ETH_USDT","stocks":30},{"eid":"OKEX","currency":"LTC_USDT","stocks":100}]
'''

import time
import json

params = {
"arrBasePrice": [-1, -1, -1], # -1
"arrRatio": [0.05, 0.05, 0.05], # 0.05
"arrAcc": [], # _C(exchange.GetAccount)
"arrLastCancelAll": [0, 0, 0], # 0
"arrMinStocks": [0.01, 0.01, 0.01], # 0.01
"arrPricePrecision": [2, 2, 2], # 2
"arrAmountPrecision": [3, 2, 2], # 2
"arrTick":[]
}

def CancelAll(e):
while True :
orders = _C(e.GetOrders)
for i in range(len(orders)) :
e.CancelOrder(orders[i]["Id"], orders[i])
if len(orders) == 0 :
break
Sleep(1000)

def process(e, index):
global params
ticker = _C(e.GetTicker)
params["arrTick"][index] = ticker
if params["arrBasePrice"][index] == -1 :
params["arrBasePrice"][index] = ticker.Last
if ticker.Last - params["arrBasePrice"][index] > 0 and (ticker.Last - params["arrBasePrice"][index]) / params["arrBasePrice"][index] > params["arrRatio"][index]:
params["arrAcc"][index] = _C(e.GetAccount)
if params["arrAcc"][index].Balance * params["arrRatio"][index] / ticker.Last > params["arrMinStocks"][index]:
e.Buy(ticker.Last, params["arrAcc"][index].Balance * params["arrRatio"][index] / ticker.Last)
params["arrBasePrice"][index] = ticker.Last
if ticker.Last - params["arrBasePrice"][index] < 0 and (params["arrBasePrice"][index] - ticker.Last) / params["arrBasePrice"][index] > params["arrRatio"][index]:
params["arrAcc"][index] = _C(e.GetAccount)
if params["arrAcc"][index].Stocks * params["arrRatio"][index] > params["arrMinStocks"][index]:
e.Sell(ticker.Last, params["arrAcc"][index].Stocks * params["arrRatio"][index])
params["arrBasePrice"][index] = ticker.Last
ts = time.time()
if ts - params["arrLastCancelAll"][index] > 60 * 5 :
CancelAll(e)
params["arrLastCancelAll"][index] = ts

def main():
global params

for i in range(len(exchanges)) :
params["arrAcc"].append(_C(exchanges[i].GetAccount))
params["arrTick"].append(_C(exchanges[i].GetTicker))
exchanges[i].SetPrecision(params["arrPricePrecision"][i], params["arrAmountPrecision"][i])

for key in params :
if len(params[key]) < len(exchanges):
raise "params error!"

while True:
tblAcc = {
"type" : "table",
"title": "account",
"cols": ["账户信息"],
"rows": []
}

tblTick = {
"type" : "table",
"title": "ticker",
"cols": ["行情信息"],
"rows": []
}
for i in range(len(exchanges)):
process(exchanges[i], i)

for i in range(len(exchanges)):
tblAcc["rows"].append([json.dumps(params["arrAcc"][i])])
tblTick["rows"].append([json.dumps(params["arrTick"][i])])

LogStatus(_D(), "\n`" + json.dumps([tblAcc, tblTick]) + "`")
Sleep(500)
```

> 策略出处

https://www.fmz.com/strategy/182268

> 更新时间

2020-01-20 17:44:33
74 changes: 74 additions & 0 deletions Python版追涨杀跌策略(教学).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

> 策略名称

Python版追涨杀跌策略(教学)

> 策略作者

小小梦

> 策略描述

https://www.fmz.com/bbs-topic/4908



> 源码 (python)

``` python
'''backtest
start: 2019-02-20 00:00:00
end: 2020-01-10 00:00:00
period: 1m
exchanges: [{"eid":"OKEX","currency":"BTC_USDT"}]
'''

import time

basePrice = -1
ratio = 0.05
acc = _C(exchange.GetAccount)
lastCancelAll = 0
minStocks = 0.01

def CancelAll():
while True :
orders = _C(exchange.GetOrders)
for i in range(len(orders)) :
exchange.CancelOrder(orders[i]["Id"], orders[i])
if len(orders) == 0 :
break
Sleep(1000)

def main():
global basePrice, acc, lastCancelAll
exchange.SetPrecision(2, 3)
while True:
ticker = _C(exchange.GetTicker)
if basePrice == -1 :
basePrice = ticker.Last
if ticker.Last - basePrice > 0 and (ticker.Last - basePrice) / basePrice > ratio :
acc = _C(exchange.GetAccount)
if acc.Balance * ratio / ticker.Last > minStocks :
exchange.Buy(ticker.Last, acc.Balance * ratio / ticker.Last)
basePrice = ticker.Last
if ticker.Last - basePrice < 0 and (basePrice - ticker.Last) / basePrice > ratio :
acc = _C(exchange.GetAccount)
if acc.Stocks * ratio > minStocks :
exchange.Sell(ticker.Last, acc.Stocks * ratio)
basePrice = ticker.Last
ts = time.time()
if ts - lastCancelAll > 60 * 5 :
CancelAll()
lastCancelAll = ts
LogStatus(_D(), "\n", "行情信息:", ticker, "\n", "账户信息:", acc)
Sleep(500)
```

> 策略出处

https://www.fmz.com/strategy/181185

> 更新时间

2020-01-11 15:15:01
25 changes: 0 additions & 25 deletions 10行人品策略.js

This file was deleted.

Loading