From 100da74e3d7b8c1b2430f064bdeb3ec8c7378f12 Mon Sep 17 00:00:00 2001 From: dpyro Date: Tue, 4 Sep 2018 03:23:20 -0500 Subject: [PATCH] Disable all mutable tests by default and doc nits. --- BinanceApiTests/BinanceApiObjCTests.m | 104 +++++++++--------- BinanceApiTests/BinanceApiTests.swift | 145 +++++++++++++------------- README.md | 2 +- TODO.md | 1 + 4 files changed, 126 insertions(+), 126 deletions(-) diff --git a/BinanceApiTests/BinanceApiObjCTests.m b/BinanceApiTests/BinanceApiObjCTests.m index 18969e3..def2995 100644 --- a/BinanceApiTests/BinanceApiObjCTests.m +++ b/BinanceApiTests/BinanceApiObjCTests.m @@ -176,61 +176,61 @@ - (void)testAllBookTickers { [self waitForExpectations:@[expectation] timeout:self.timeout]; } -- (void)testTestNewOrder { - NSString *symbol = @"ETHBTC"; - NSDecimalNumber *quantity = [NSDecimalNumber decimalNumberWithString:@"1.0"]; - - XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"all book tickers"]; - - BinanceApi *api = [[BinanceApi alloc] initWithApiKey:self.apiKey secretKey:self.secretKey]; - [api testNewOrderWithSymbol:symbol side:BinanceOrderSide.Buy type:BinanceOrderType.Market timeInForce:nil quantity:quantity price:nil newClientOrderId:nil stopPrice:nil icebergQuantity:nil responseHandler:^(NSError * _Nullable error) { - XCTAssertNil(error); - - [expectation fulfill]; - }]; - - [self waitForExpectations:@[expectation] timeout:self.timeout]; -} - -- (void)testQueryOrder { - XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"query order"]; - - BinanceApi *api = [[BinanceApi alloc] initWithApiKey:self.apiKey secretKey:self.secretKey]; - [api queryOrderWithSymbol:self.querySymbol orderId:self.queryOrderId originalClientOrderId:nil responseHandler:^(NSDictionary * _Nullable result, NSError * _Nullable error) { - XCTAssertNil(error); - XCTAssert(result); - - XCTAssert([(NSString *)[result valueForKey:@"symbol"] isEqualToString:self.querySymbol]); - XCTAssertEqual([(NSNumber *)[result valueForKey:@"orderId"] unsignedLongLongValue], self.queryOrderId); - - NSLog(@"%@: %@", [result valueForKey:@"symbol"], [result valueForKey:@"status"]); - - [expectation fulfill]; - }]; - - [self waitForExpectations:@[expectation] timeout:self.timeout]; -} - - -- (void)testCancelOrder { - NSString *symbol = @"BNBETH"; - UInt64 orderId = 10000; - - XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"cancel order"]; - - BinanceApi *api = [[BinanceApi alloc] initWithApiKey:self.apiKey secretKey:self.secretKey]; - [api cancelOrderWithSymbol:symbol orderId:orderId originalClientOrderId:nil newClientOrderId:nil responseHandler:^(NSDictionary * _Nullable result, NSError * _Nullable error) { - XCTAssertNil(error); - XCTAssert(result); +//- (void)testTestNewOrder { +// NSString *symbol = @"ETHBTC"; +// NSDecimalNumber *quantity = [NSDecimalNumber decimalNumberWithString:@"1.0"]; +// +// XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"all book tickers"]; +// +// BinanceApi *api = [[BinanceApi alloc] initWithApiKey:self.apiKey secretKey:self.secretKey]; +// [api testNewOrderWithSymbol:symbol side:BinanceOrderSide.Buy type:BinanceOrderType.Market timeInForce:nil quantity:quantity price:nil newClientOrderId:nil stopPrice:nil icebergQuantity:nil responseHandler:^(NSError * _Nullable error) { +// XCTAssertNil(error); +// +// [expectation fulfill]; +// }]; +// +// [self waitForExpectations:@[expectation] timeout:self.timeout]; +//} - UInt64 orderId = [[result valueForKey:@"orderId"] unsignedLongLongValue]; - NSLog(@"Cancelled order %llu", orderId); +//- (void)testQueryOrder { +// XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"query order"]; +// +// BinanceApi *api = [[BinanceApi alloc] initWithApiKey:self.apiKey secretKey:self.secretKey]; +// [api queryOrderWithSymbol:self.querySymbol orderId:self.queryOrderId originalClientOrderId:nil responseHandler:^(NSDictionary * _Nullable result, NSError * _Nullable error) { +// XCTAssertNil(error); +// XCTAssert(result); +// +// XCTAssert([(NSString *)[result valueForKey:@"symbol"] isEqualToString:self.querySymbol]); +// XCTAssertEqual([(NSNumber *)[result valueForKey:@"orderId"] unsignedLongLongValue], self.queryOrderId); +// +// NSLog(@"%@: %@", [result valueForKey:@"symbol"], [result valueForKey:@"status"]); +// +// [expectation fulfill]; +// }]; +// +// [self waitForExpectations:@[expectation] timeout:self.timeout]; +//} - [expectation fulfill]; - }]; - [self waitForExpectations:@[expectation] timeout:self.timeout]; -} +//- (void)testCancelOrder { +// NSString *symbol = @"BNBETH"; +// UInt64 orderId = 10000; +// +// XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"cancel order"]; +// +// BinanceApi *api = [[BinanceApi alloc] initWithApiKey:self.apiKey secretKey:self.secretKey]; +// [api cancelOrderWithSymbol:symbol orderId:orderId originalClientOrderId:nil newClientOrderId:nil responseHandler:^(NSDictionary * _Nullable result, NSError * _Nullable error) { +// XCTAssertNil(error); +// XCTAssert(result); +// +// UInt64 orderId = [[result valueForKey:@"orderId"] unsignedLongLongValue]; +// NSLog(@"Cancelled order %llu", orderId); +// +// [expectation fulfill]; +// }]; +// +// [self waitForExpectations:@[expectation] timeout:self.timeout]; +//} - (void)testOpenOrders { diff --git a/BinanceApiTests/BinanceApiTests.swift b/BinanceApiTests/BinanceApiTests.swift index 7e850b1..7ad553a 100644 --- a/BinanceApiTests/BinanceApiTests.swift +++ b/BinanceApiTests/BinanceApiTests.swift @@ -36,7 +36,6 @@ class BinanceApiTests: XCTestCase { } func testSignature() { - // let apiKey = "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A" let secretKey = "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j" let message = "symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000×tamp=1499827319559" @@ -197,80 +196,80 @@ class BinanceApiTests: XCTestCase { } } - /*func testNewOrder() { - let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey) - let symbol = "ETHBTC" - let request = BinanceNewOrderRequest( - symbol: symbol, - side: .sell, - type: .limit, - quantity: Decimal(string: "0.001")!, - price: Decimal(string: "1.1")!, timeInForce: .goodTilCancelled) - - asyncTest("new order") { (expectation) in - api.send(request) { response in - XCTAssertTrue(response.result.isSuccess) - XCTAssertNotNil(response.result.value) - let value = response.result.value! - XCTAssertEqual(value.symbol, symbol) - print("Created new order #\(value.orderId)") - expectation.fulfill() - } - } - }*/ - - func testTestNewOrder() { - let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey) - let symbol = "ETHBTC" - let request = BinanceTestNewOrderRequest( - symbol: symbol, - side: .buy, - type: .market, - quantity: Decimal(string: "1.1")!) - - asyncTest("test new order") { (expectation) in - api.send(request) { response in - XCTAssertTrue(response.result.isSuccess) - XCTAssertNotNil(response.result.value) - let _ = response.result.value! - expectation.fulfill() - } - } - } - - func testQueryOrder() { - let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey) - let request = BinanceQueryOrderRequest(symbol: self.querySymbol, orderId: self.queryOrderId) - - asyncTest("query order") { (expectation) in - api.send(request) { response in - XCTAssertTrue(response.result.isSuccess) - XCTAssertNotNil(response.result.value) - let order = response.result.value! - print(order) - expectation.fulfill() - } - } - } +// func testNewOrder() { +// let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey) +// let symbol = "ETHBTC" +// let request = BinanceNewOrderRequest( +// symbol: symbol, +// side: .sell, +// type: .limit, +// quantity: Decimal(string: "0.001")!, +// price: Decimal(string: "1.1")!, timeInForce: .goodTilCancelled) +// +// asyncTest("new order") { (expectation) in +// api.send(request) { response in +// XCTAssertTrue(response.result.isSuccess) +// XCTAssertNotNil(response.result.value) +// let value = response.result.value! +// XCTAssertEqual(value.symbol, symbol) +// print("Created new order #\(value.orderId)") +// expectation.fulfill() +// } +// } +// } - /*func testCancelOrder() { - let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey) - let symbol = "ETHBTC" - let orderId = UInt64(11691907) - let request = BinanceCancelOrderRequest(symbol: symbol, orderId: orderId) +// func testTestNewOrder() { +// let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey) +// let symbol = "ETHBTC" +// let request = BinanceTestNewOrderRequest( +// symbol: symbol, +// side: .buy, +// type: .market, +// quantity: Decimal(string: "1.1")!) +// +// asyncTest("test new order") { (expectation) in +// api.send(request) { response in +// XCTAssertTrue(response.result.isSuccess) +// XCTAssertNotNil(response.result.value) +// let _ = response.result.value! +// expectation.fulfill() +// } +// } +// } - asyncTest("cancel order") { (expectation) in - api.send(request) { response in - XCTAssertTrue(response.result.isSuccess) - XCTAssertNotNil(response.result.value) - let value = response.result.value! - XCTAssertEqual(value.symbol, symbol) - XCTAssertEqual(value.orderId, orderId) - print("Cancelled order #\(value.orderId)") - expectation.fulfill() - } - } - }*/ +// func testQueryOrder() { +// let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey) +// let request = BinanceQueryOrderRequest(symbol: self.querySymbol, orderId: self.queryOrderId) +// +// asyncTest("query order") { (expectation) in +// api.send(request) { response in +// XCTAssertTrue(response.result.isSuccess) +// XCTAssertNotNil(response.result.value) +// let order = response.result.value! +// print(order) +// expectation.fulfill() +// } +// } +// } +// +// func testCancelOrder() { +// let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey) +// let symbol = "ETHBTC" +// let orderId = UInt64(11691907) +// let request = BinanceCancelOrderRequest(symbol: symbol, orderId: orderId) +// +// asyncTest("cancel order") { (expectation) in +// api.send(request) { response in +// XCTAssertTrue(response.result.isSuccess) +// XCTAssertNotNil(response.result.value) +// let value = response.result.value! +// XCTAssertEqual(value.symbol, symbol) +// XCTAssertEqual(value.orderId, orderId) +// print("Cancelled order #\(value.orderId)") +// expectation.fulfill() +// } +// } +// } func testOpenOrders() { let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey) diff --git a/README.md b/README.md index 15e3de4..9052511 100644 --- a/README.md +++ b/README.md @@ -279,4 +279,4 @@ api.send(request) { response in ## Testing & Examples -Both an Objective-C and Swift test suite are included. You can use the test code as an example for integration this library. You will need to insert your own apikey, secretkey, and order to query to test the signed endpoints. The new order (not the test version) and cancel order endpoints in the test suite *will* execute on the market but are disabled by default. +Both an Objective-C and Swift test suite are included. You can use the test code as an example for integration this library. You will need to insert your own `apiKey`, `secretKey`, and `orderId` to query to test the signed endpoints. Mutable tests are commented (disabled) by default. You should disable withdrawal and optionally trading access for the API key before using it. You should also revoke the API key when you are done testing. diff --git a/TODO.md b/TODO.md index c588d74..b3188e3 100644 --- a/TODO.md +++ b/TODO.md @@ -6,3 +6,4 @@ * Remove the need for an `elements` ivar in array responses that are transformed into dicts. * Add dSYM files for debugging * Add CI support +* Injectable API credential secrets for testing