Skip to content

Commit

Permalink
Add immediate or cancel limit orders
Browse files Browse the repository at this point in the history
  • Loading branch information
rupurt committed Jun 6, 2018
1 parent 02e1c02 commit 763b8f7
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[
{
"request": {
"body": "price=0.01&quantity=0.1&recvWindow=1000&side=BUY&symbol=LTCBTC&timeInForce=IOC&timestamp=1527291300666&type=LIMIT&signature=***",
"headers": {
"X-MBX-APIKEY": "***"
},
"method": "post",
"options": [],
"request_body": "",
"url": "https://api.binance.com/api/v3/order"
},
"response": {
"binary": false,
"body": "{\"symbol\":\"LTCBTC\",\"orderId\":47528830,\"clientOrderId\":\"zyMyhtRENlvFHrl4CitDe0\",\"transactTime\":1527291300912,\"price\":\"0.01000000\",\"origQty\":\"0.10000000\",\"executedQty\":\"0.00000000\",\"status\":\"EXPIRED\",\"timeInForce\":\"IOC\",\"type\":\"LIMIT\",\"side\":\"BUY\"}",
"headers": {
"Content-Type": "application/json",
"Transfer-Encoding": "chunked",
"Connection": "keep-alive",
"Date": "Fri, 25 May 2018 23:35:00 GMT",
"Server": "nginx",
"Vary": "Accept-Encoding",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains",
"X-Frame-Options": "SAMEORIGIN",
"X-Xss-Protection": "1; mode=block",
"X-Content-Type-Options": "nosniff",
"Content-Security-Policy": "default-src 'self'",
"X-Content-Security-Policy": "default-src 'self'",
"X-WebKit-CSP": "default-src 'self'",
"Cache-Control": "no-cache, no-store, must-revalidate",
"Pragma": "no-cache",
"Expires": "0",
"X-Cache": "Miss from cloudfront",
"Via": "1.1 fb1574d5a6ba2d77d2a656aba08aa3c3.cloudfront.net (CloudFront)",
"X-Amz-Cf-Id": "7FpRejCpXjYssWLkFBBSqvrIlcQQUmXaFGh4q1eFUpiWvRc91Ipo2g=="
},
"status_code": 200,
"type": "ok"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[
{
"request": {
"body": "price=50000&quantity=0.001&recvWindow=1000&side=SELL&symbol=BTCUSDT&timeInForce=IOC&timestamp=1527291410866&type=LIMIT&signature=***",
"headers": {
"X-MBX-APIKEY": "***"
},
"method": "post",
"options": [],
"request_body": "",
"url": "https://api.binance.com/api/v3/order"
},
"response": {
"binary": false,
"body": "{\"symbol\":\"BTCUSDT\",\"orderId\":108279070,\"clientOrderId\":\"roSkLhwX9KCgYqr4yFPx1V\",\"transactTime\":1527291411088,\"price\":\"50000.00000000\",\"origQty\":\"0.00100000\",\"executedQty\":\"0.00000000\",\"status\":\"EXPIRED\",\"timeInForce\":\"IOC\",\"type\":\"LIMIT\",\"side\":\"SELL\"}",
"headers": {
"Content-Type": "application/json",
"Transfer-Encoding": "chunked",
"Connection": "keep-alive",
"Date": "Fri, 25 May 2018 23:36:51 GMT",
"Server": "nginx",
"Vary": "Accept-Encoding",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains",
"X-Frame-Options": "SAMEORIGIN",
"X-Xss-Protection": "1; mode=block",
"X-Content-Type-Options": "nosniff",
"Content-Security-Policy": "default-src 'self'",
"X-Content-Security-Policy": "default-src 'self'",
"X-WebKit-CSP": "default-src 'self'",
"Cache-Control": "no-cache, no-store, must-revalidate",
"Pragma": "no-cache",
"Expires": "0",
"X-Cache": "Miss from cloudfront",
"Via": "1.1 51f2e50a0d2a5ee1d9c830bf417b2713.cloudfront.net (CloudFront)",
"X-Amz-Cf-Id": "BX8-X-VXYRrjfwPJ8H-Gx4sgVhcoBDZ7WlOiWn-u0SWuW2h0e5Rhpw=="
},
"status_code": 200,
"type": "ok"
}
}
]
38 changes: 38 additions & 0 deletions test/binance_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ defmodule BinanceTest do
assert response.type == "LIMIT"
end
end

test "can create an order with am immediate or cancel duration" do
use_cassette "order_limit_buy_immediate_or_cancel_success" do
assert {:ok, %Binance.OrderResponse{} = response} =
Binance.order_limit_buy("LTCBTC", 0.1, 0.01, "IOC")

assert response.client_order_id == "zyMyhtRENlvFHrl4CitDe0"
assert response.executed_qty == "0.00000000"
assert response.order_id == 47_528_830
assert response.orig_qty == "0.10000000"
assert response.price == "0.01000000"
assert response.side == "BUY"
assert response.status == "EXPIRED"
assert response.symbol == "LTCBTC"
assert response.time_in_force == "IOC"
assert response.transact_time == 1_527_291_300_912
assert response.type == "LIMIT"
end
end
end

describe ".order_limit_sell" do
Expand Down Expand Up @@ -166,5 +185,24 @@ defmodule BinanceTest do
assert response.type == "LIMIT"
end
end

test "can create an order with am immediate or cancel duration" do
use_cassette "order_limit_sell_immediate_or_cancel_success" do
assert {:ok, %Binance.OrderResponse{} = response} =
Binance.order_limit_sell("BTCUSDT", 0.001, 50_000, "IOC")

assert response.client_order_id == "roSkLhwX9KCgYqr4yFPx1V"
assert response.executed_qty == "0.00000000"
assert response.order_id == 108_279_070
assert response.orig_qty == "0.00100000"
assert response.price == "50000.00000000"
assert response.side == "SELL"
assert response.status == "EXPIRED"
assert response.symbol == "BTCUSDT"
assert response.time_in_force == "IOC"
assert response.transact_time == 1_527_291_411_088
assert response.type == "LIMIT"
end
end
end
end

0 comments on commit 763b8f7

Please sign in to comment.