Type/to search
8
Follow
1375
Followers
3.2 Modèle : Bibliothèque de trading de devises numériques (prise en charge intégrée des contrats à terme et au comptant OKCoin futures/BitVC)
Tutorials
Created 2017-01-04 19:00:10  Updated 2017-10-11 10:27:01
 19
 5723

3.2 Modèle : Bibliothèque de trading de devises numériques (prise en charge intégrée des contrats à terme et au comptant OKCoin futures/BitVC)


La section 3.1 présente un modèle de transaction en temps réel, ce qui simplifie considérablement la tâche de la stratégie de transaction en temps réel. Cependant, le traitement des transactions à terme est très différent de celui des transactions en temps réel, de sorte que les fonctions de transaction à terme sont intégrées sur la base du modèle en temps réel et sont maintenant publiques.

img

Le blogueur a publié un billet sur la place Stratégie:

img

  • En espèces:

    La monnaie en espèces est identique à celle de la monnaie numérique en espèces précédente.

  • Les échanges à terme:

    paramètre:
    img

    img

    Le code de test fourni par la stratégie:

    function main() { if (exchange.GetName() === 'Futures_OKCoin') { var info = exchange.SetContractType("this_week"); Log("info 返回值:", info); Log("当前持仓信息", exchange.GetPosition(), _C(exchange.GetTicker)); var depth = exchange.GetDepth(); var p = $.NewPositionManager(); p.OpenShort("this_week", 10, depth.Bids[0].Price - 2); Log(exchange.GetPosition()); Sleep(500 * 1000); depth = exchange.GetDepth(); var ret = p.Cover("this_week", depth.Bids[0].Price + 2, 5); Log("cover ret:", ret); //LogProfit(p.Profit()); Log(exchange.GetPosition()); Log("-----------------------------测试分割线----------------------------------------"); var depth = exchange.GetDepth(); p.OpenLong("this_week", 20, depth.Bids[0].Price + 2); Log(exchange.GetPosition()); Sleep(500 * 1000); depth = exchange.GetDepth(); var ret = p.Cover("this_week", depth.Bids[0].Price - 2, 10, PD_LONG); Log("cover ret:", ret); Log(exchange.GetPosition()); Log("-----------------------------测试分割线----------------------------------------"); var ret = p.Cover("this_week", depth.Bids[0].Price - 3, 10, PD_LONG); Log("cover ret:", ret); var ret = p.Cover("this_week", depth.Bids[0].Price + 3, 5, PD_SHORT); Log("cover ret:", ret); Log(exchange.GetPosition()); } else if (exchange.GetName() === 'Futures_BitVC') { var info = exchange.SetContractType("week"); Log("info 返回值:", info); Log("当前持仓信息", exchange.GetPosition(), _C(exchange.GetTicker)); var depth = exchange.GetDepth(); var p = $.NewPositionManager(); p.OpenLong("week", 500, depth.Bids[0].Price + 2); Log(exchange.GetPosition()); Sleep(500 * 1000); depth = exchange.GetDepth(); var ret = p.Cover("week", depth.Bids[0].Price - 2, 500); Log("cover ret:", ret); Log(exchange.GetPosition()); Log("-----------------------------测试分割线----------------------------------------"); var info = exchange.SetContractType("week"); Log("info 返回值:", info); Log("当前持仓信息", exchange.GetPosition(), _C(exchange.GetTicker)); var depth = exchange.GetDepth(); p.OpenShort("week", 600, depth.Bids[0].Price - 2); Log(exchange.GetPosition()); Sleep(500 * 1000); depth = exchange.GetDepth(); var ret = p.Cover("week", depth.Bids[0].Price - 2, 500, PD_SHORT); Log("cover ret:", ret); Log(exchange.GetPosition()); Log("-----------------------------测试分割线----------------------------------------"); var ret = p.Cover("week", depth.Bids[0].Price + 3, 100, PD_SHORT); Log("cover ret:", ret); //p.Cover("week", depth.Asks[0].Price - 3, 300, PD_LONG); Log(exchange.GetPosition()); } else if(exchange.GetName() === 'huobi' || exchange.GetName() === 'OKCoin'){ Log($.GetAccount()); Log($.Buy(0.5)); Log($.Sell(0.5)); exchange.Buy(1000, 3); $.CancelPendingOrders(exchanges[0]); Log($.Cross(30, 7)); Log($.Cross([1,2,3,2.8,3.5], [3,1.9,2,5,0.6])); } }

    Utilisation:
    img

Le code de test dans la stratégie ((Sélection du modèle de référence))

img

Stratégie de test:

function main(){ var p = $.NewPositionManager(); var i = 0; exchanges[0].SetContractType("this_week"); var isFirst = true; var ret = null; while(true){ var depth = _C(exchanges[0].GetDepth); var positions = _C(exchanges[0].GetPosition); var len = positions.length; if(isFirst === true && i % 3 === 0 && len === 0){ ret = p.OpenLong("this_week", 1 + (i % 3) + (i % 2), depth.Asks[0].Price); isFirst = false; }else if(isFirst === false){ ret = p.OpenShort("this_week", 1 + (i % 3) + (i % 2), depth.Bids[0].Price); isFirst = true; }else{ for(var j = 0 ; j < len; j++){ if(positions[j].Type === PD_LONG){ ret = p.Cover("this_week", depth.Bids[0].Price - 2, positions[j].Amount, PD_LONG); }else if(positions[j].Type === PD_SHORT){ ret = p.Cover("this_week", depth.Asks[0].Price + 2, positions[j].Amount, PD_SHORT); } Log("ret:", ret); } } Log("ret", ret, "---------------------#FF0000"); i++; Sleep(1000 * 60 * 15); } }

Si vous avez des questions, BUG, n'hésitez pas à contacter l'auteur, merci beaucoup !

Related Recommendations
Comment
All comments (17)

    为啥我没有找到JS的 数字货币交易类库,策略里面没有看到

    7 years ago

    img
    在这个位置

    7 years ago

    你好,这个是现货和商品期货的,我在群里面问了,JS数字货币期货类库因为有bug,已经没了

    7 years ago

    数字货币期货的交易类库 是非官方的,因为交易所 持仓接口经常延迟,可能导致重复下单,所以取消公开了。

    7 years ago

    $.Buy(0.5)用的价格是多少的

    7 years ago

    当时的对手价,加一点滑价。

    7 years ago

    python版本的也支持okex期货吗?

    9 years ago

    python 的 没有 期货功能
    没移植 >_<

    9 years ago

    不太会用js,有关于okex期货的python模板参考下吗?

    9 years ago

    这个暂时 没写,不过 有 商品期货的 期货 pyhton 模版, 我的JS 其实 也是 照着 商品期货 的结构写的,可以参考。

    9 years ago

    请问ret 代表什么呀?是什么英文词组的简写呀? RECOVER T?

    9 years ago

    return 返回值的意思 ,一般用来 临时储存 一个 函数 返回值 。

    9 years ago

    请问PY版的在哪呀?

    9 years ago

    https://www.botvs.com/strategy/21104 , 可能和JS 的版本有点 不一样,这个是 照着 JS 的移植的。

    9 years ago

    感谢感谢

    9 years ago

    习惯用python,有python版本吗

    9 years ago

    有python 版本的 ,不过 用的比较少 使用的时候最好 做下测试 。

    9 years ago
  • 1
Forums
PINE Language
Get the app
iPhone Download
© 2015 - ∞ INVENTOR PTE LTD (SG)