0
Follow
0
Followers
'''backtest
start: 2018-09-30 00:00:00
end: 2018-10-11 19:00:00
period: 15m
exchanges: [{"eid":"OKCoin_EN","currency":"ETC_USD"}]
'''
def main():
first()
while True:
get_information = _C(exchange.GetTicker)
#get_order = exchange.GetOrder()
btc_price_last = get_information.Last
#account = exchange.GetAccount()
for j in range(0,len(Grid_price_list)):
if(Grid_price_list[j-1] < btc_price_last < Grid_price_list[j]): # 判断价格所在的网格区间
if(btc_price_last < exchange.GetOrder(buy_id).AvgPrice and btc_price_last <= Grid_price_list[j-1]): # !!!需要进一步完善针对卖单情况的逻辑!!!,现价小于买入价,且现价小于等于网格下值,继续买入。
buy()
else:
main()
if(btc_price_last > exchange.GetOrder(buy_id).AvgPrice and btc_price_last >= Grid_price_list[j]): # !!!需要进一步完善针对卖单情况的逻辑!!!,现价大于买入价,且现价大于等于网格上值,继续卖出。
sell()
else:
main()
order_stock_rate = 0.05 * j # 仓位比例
Sleep(300 * 1000)
def buy():
buy_price = Grid_price_list[j-1]
buy_id = exchange.Buy(buy_price, 500 * (j - 1) / buy_price)
def sell():
sell_price = Grid_price_list[j]
sell_id = exchange.Sell(sell_price, 500 * j / sell_price)
def first():
get_information = _C(exchange.GetTicker)
#get_order = exchange.GetOrder()
btc_price_last = get_information.Last
global account
account = _C(exchange.GetAccount)
global Grid_price_list
Grid_price_list = [] # 给最低网格价格赋值,算出每个价格
btc_price_bottom = 7
for i in range(1,20):
btc_price_bottom = btc_price_bottom * 1.05
Grid_price_list.append(btc_price_bottom)
Log(Grid_price_list)
global j
for j in range(0,len(Grid_price_list)):
if(Grid_price_list[j-1] < btc_price_last < Grid_price_list[j]): # 判断价格所在的网格区间
buy()
Log("初始买入",exchange.GetOrder(buy_id)
#order_stock_rate = 0.05 * j # 仓位比例
Related Recommendations
Adding exchanges on our setting listIntroducing Visual Programming on FMZ QuantLooking For PartnershipGreat news! Check out our platforms’ NEW features, the “Demands & Offers” page on our website.Our platform’s New design PC/MacOS local software client is released now!Flash collapse robot (teaching)Index equilibrium strategy (teaching)can anyone please explain how to start with this platformC++ API call exampleHow to break through the Tick receiving limit of commodity futures
Comment
All comments (8)
回测报错, Traceback (most recent call last): File "<string>", line 1292, in Run File "<string>", line 63 if 'init' in locals() and callable(init): ^ SyntaxError: invalid syntax
8 years ago
8 years ago
您看下面的代码和日志,exchange.GetOrder(buy_id)的信息里面amount是368.3512,Stocks的信息还是跟我回测设置的值一样是20。
Log("初始买入",exchange.GetOrder(buy_id),account.Stocks)
2018-09-30 00:00:00 信息 初始买入 {'Status': 0L, 'Price': 10.8592, 'AvgPrice': 0.0, 'Amount': 368.3512, 'DealAmount': 0.0, 'ContractType': 'ETC_USDT_Huobi', 'Type': 0L, 'Id': 1L} 20.0
2018-09-30 00:00:00 信息 1 20.0
2018-09-30 00:00:00 Huobi 买入 10.8592 368.351259761308
8 years ago
- 1
