2.2 Lower price lists

Author: The Little Dream, Created: 2016-11-07 16:41:10, Updated: 2019-08-01 09:26:27

Lower price lists


  • Buy (Price, Amount) function

Small preparations

In the transaction function Buy (())/Sell () There are several APIs that you must be familiar with.

  • 1, GetOrder ((orderId) Returns an Order structure to retrieve order details based on order number.
  • 2, GetOrders retrieves all unfinished orders and returns an Order array structure.
  • CancelOrder (orderId) Cancel an order based on the order number, returning true or false.
  • 4, Order status The status value in the order structure
[
        ORDER_STATE_PENDING     :未完成
        ORDER_STATE_CLOSED      :已关闭
        ORDER_STATE_CANCELED	:已取消
]
  • 5, Order Order structure, returned by GetOrder
{
        Id          :交易单唯一标识
        Price       :下单价格
        Amount      :下单数量
        DealAmount  :成交数量
        Status      :订单状态, 参考常量里的订单状态
        Type        :订单类型, 参考常量里的订单类型
}

The API documentation

Buy(Price, Amount)	下买单, Price为买单价格,Amount为数量, 返回一个订单ID
可以跟多余的参数做为附加消息显示到日志, 如exchange.Buy(1000,0.1, "OK", 123)
支持现货(火币/BitVC/OKCoin/OKCoin国际/OKCoin期货/BTCChina/BitYes)市价单, 市价单价格指定为-1
exchange.Buy(1000), 指买市价1000元的币, BTCChina例外exchange.Buy(0.3)指市价买0.3个币
  • List of prices

Let's see how easy it is to use a price list, but there are a lot of details that need to be worked out.Section 3.1There will be a very detailed processing process for everyone to learn.

function main() {    
        //  方便用户看这些  宏的值 我们事先打印出来
        //  ORDER_STATE_PENDING     :未完成
        //  ORDER_STATE_CLOSED      :已关闭
        //  ORDER_STATE_CANCELED    :已取消

        Log("ORDER_STATE_PENDING:", ORDER_STATE_PENDING, ", ORDER_STATE_CLOSED:", 
            ORDER_STATE_CLOSED, ", ORDER_STATE_CANCELED:", ORDER_STATE_CANCELED); // 这些都是订单状态的宏,打印这些值认识下,在本段代码不起任何作用,仅仅观察下这些 “状态” 的值。
    
        var ticker = exchange.GetTicker();               // 上一章 已经讲述了怎么获取行情信息。
        Log("初始账户信息:", exchange.GetAccount());      //  用于对比交易前后账户信息
    
        var ID = exchange.Buy(ticker.Sell + 0.1, 0.1);   // ticker.Sell 即 上一章中的  depth.Asks[0].Price 。
                                                         //  返回值是一个订单 ID ,参考上面 小准备。
        // 限价单下单后 返回一个ID 可以用来查询这个订单的完成情况。我们暂停1秒 即:  Sleep(1000)   。
        Sleep(1000);
        var order = exchange.GetOrder(ID);               // 根据ID 获取 对应的 订单信息。
        Log("order:", order);
        Log("当前账户信息:", exchange.GetAccount());       //  对比初始账户信息
}

The results are as follows:imgYou can see that the status of the order printed is 1, i.e.: ORDER_STATE_CLOSED. The current order status is completed, see dealAmount is 0.1, which also confirms that the order has completed the transaction. The transaction amount is dealAmount.

  • Sell (Price, Amount) function

The API documentation

    Sell(Price, Amount)	跟Buy函数一样的调用方法和场景
  • List of prices

The above Buy () function was tested by the backtesting system we used, and here we test it with the analog disk to see if there are any outstanding () or partial () orders.

function main() {    
        //  方便用户看这些  宏的值 我们事先打印出来
        //  ORDER_STATE_PENDING	:未完成
        //  ORDER_STATE_CLOSED	:已关闭
        //  ORDER_STATE_CANCELED	:已取消

        Log("ORDER_STATE_PENDING:", ORDER_STATE_PENDING, "
            , ORDER_STATE_CLOSED:", ORDER_STATE_CLOSED, ", ORDER_STATE_CANCELED:", ORDER_STATE_CANCELED);
    
        var ticker = exchange.GetTicker();   // 上一章 已经讲述了怎么获取行情信息。
        Log("初始账户信息:", exchange.GetAccount());   //  用于对比交易前后账户信息
        var ID = exchange.Sell(ticker.Sell + 0.3, 2); // 这里故意把卖出价格加了 0.3 ,并且使用的ticker.Sell,增加了未成交的几率。
                                                      //  返回值是一个订单 ID ,参考上面 小准备。
        // 限价单下单后 返回一个ID 可以用来查询这个订单的完成情况。我们暂停1秒 即:  Sleep(1000)   。
        Sleep(1000);
        var order = exchange.GetOrder(ID);            // 根据ID 获取 对应的 订单信息。
        Log("order:", order);
        Log("当前账户信息:", exchange.GetAccount());   //  对比初始账户信息
}

The inventor quantified the results of running the analogue disc as follows:imgYou can see that the status value of the order printed is 0, i.e. not completed. The value of the DealAmount is 0, and the 2 coins sold are also frozen because the order is Pending.

What about the pending submission? Here we use the CancelOrder (ID) function, which we use to cancel the order with the specified ID.

function main() {    
        //  方便用户看这些  宏的值 我们事先打印出来
        //  ORDER_STATE_PENDING	:未完成
        //  ORDER_STATE_CLOSED	:已关闭
        //  ORDER_STATE_CANCELED	:已取消

        Log("ORDER_STATE_PENDING:", ORDER_STATE_PENDING, ", ORDER_STATE_CLOSED:", ORDER_STATE_CLOSED,
            ", ORDER_STATE_CANCELED:", ORDER_STATE_CANCELED);
    
        var ticker = exchange.GetTicker();   // 上一章 已经讲述了怎么获取行情信息。
        Log("初始账户信息:", exchange.GetAccount());   //  用于对比交易前后账户信息
        var ID = exchange.Sell(ticker.Sell + 50, 2);  // ticker.Sell 即 上一章中的  depth.Asks[0].Price 。
                                                      //  返回值是一个订单 ID ,参考上面 小准备。
        // 限价单下单后 返回一个ID 可以用来查询这个订单的完成情况。我们暂停1秒 即:  Sleep(1000)   。
        Sleep(1000);
        var order = exchange.GetOrder(ID);  // 根据ID 获取 对应的 订单信息。
        Log("order:", order);
        Log("当前账户信息:", exchange.GetAccount());   //  对比初始账户信息
        Sleep(60 * 1000);
        exchange.CancelOrder(ID);         //  取消 这个ID 的订单
        order = exchange.GetOrder(ID);    //  读取这个ID的订单信息。
        Log("order:", order);
}

Run results: Showing the order ID 634795459 Last printed message Status is 2: ORDER_STATE_CANCELED: Cancelledimg

The GetOrder ((ID) and GetOrders ((() functions look very similar, the difference being that the former retrieves the order information of the specified ID, while the latter retrieves all the order information of the specified ID.未完成The order (GetOrders) returns the data structure as an array of objects, i.e. an array of order structures for each element.


More

bijiasuoWhat if I don't buy Bitcoin, I buy other coins, I clean up?

bijiasuoMark, please.

penglihengI'm not sure if I can answer that question. exchange.Buy ((ticker, 0.1) to buy one and exchange.Buy ((depth, 0.1) to buy one What's the difference? The real market price of the coin is how to get the nickel.

FangBeiPython version This is a list of all the different ways Dn-filebox.qbox.me/a2802f5f41f416374d79c48aca05030ce2b2e8a8.png is credited in the database. This is a list of all the different ways Dn-filebox.qbox.me/d6d7d1af28993a2225ec33b092b4cf2e8c479edc.png is credited in the database.

The Little DreamSee the fourth question in this post: https://www.botvs.com/bbs-topic/1427 In real-time, you can use custom control settings.

The Little DreamGetTicker gets real-time traffic data, GetDepth gets deep information, buy and sell is the same.

The Little DreamThank you for sharing!