private async Task RunPositionsTest() { if (!_marketHalted) { // Make sure there's a position to test await PlaceMarketOrder(); // get list of open positions var positions = await Rest.GetPositionsAsync(_accountId); _results.Verify(positions.Count > 0, "Positions retrieved"); foreach (var position in positions) { VerifyPosition(position); } // get position for a given instrument var onePosition = await Rest.GetPositionAsync(_accountId, TestInstrument); VerifyPosition(onePosition); // close a whole position var closePositionResponse = await Rest.DeletePositionAsync(_accountId, TestInstrument); _results.Verify(closePositionResponse.ids.Count > 0 && closePositionResponse.instrument == TestInstrument, "Position closed"); _results.Verify(closePositionResponse.totalUnits > 0 && closePositionResponse.price > 0, "Position close response seems valid"); } else { _results.Add("Skipping: Position test because market is halted"); } }
public override async Task MakeRequest() { await InternalMakeRequest(() => Rest.DeletePositionAsync(AccountDataSource.DefaultDataSource.Id, requestParams["instrument"])); }
static void Main(string[] args) { List <Instrument> instruments = null; var task = Task.Run(async() => instruments = await Rest.GetInstrumentsAsync(AccountId, null, new List <string>(_majors))); task.Wait(); var selectedMajors = instruments.Where(s => Array.Exists <string>(_majors, y => y == s.instrument)); RatesSession session = new RatesSession(AccountId, new List <Instrument>(selectedMajors)); _tickReceived = new Semaphore(0, 100); session.DataReceived += SessionOnDataReceived; session.StartSession(); Console.WriteLine("Starting rate stream test"); bool success = _tickReceived.WaitOne(10000); session.StopSession(); EventsSession eventSession = new EventsSession(AccountId); _eventReceived = new Semaphore(0, 100); eventSession.DataReceived += OnEventReceived; eventSession.StartSession(); Console.WriteLine("Starting event stream test"); Task.Run(() => { success = _eventReceived.WaitOne(10000); eventSession.StopSession(); } ); List <Price> prices; var task2 = Task.Run(async() => prices = await Rest.GetRatesAsync(instruments)); task2.Wait(); List <Position> positions = null; var task3 = Task.Run(async() => positions = await Rest.GetPositionsAsync(AccountId)); task3.Wait(); var request = new Dictionary <string, string> { { "instrument", TestInstrument }, { "units", "10000" }, { "side", "sell" }, { "type", "market" }, { "price", "1.0" } }; if (positions.Count == 0) { //Open a position PostOrderResponse response = null; var task4 = Task.Run(async() => response = await Rest.PostOrderAsync(AccountId, request)); task4.Wait(); if (response.tradeOpened != null && response.tradeOpened.id > 0) { Console.WriteLine("Post order success"); } } else { //Close all positions foreach (var position in positions) { DeletePositionResponse closePositionResponse = null; var task5 = Task.Run(async() => closePositionResponse = await Rest.DeletePositionAsync(AccountId, TestInstrument)); task5.Wait(); if (closePositionResponse.ids.Count > 0 && closePositionResponse.instrument == TestInstrument) { Console.WriteLine("Position closed"); } if (closePositionResponse.totalUnits > 0 && closePositionResponse.price > 0) { Console.WriteLine("Position close response seems valid"); } foreach (var id in closePositionResponse.ids) { Transaction transaction = null; var task6 = Task.Run(async() => transaction = await Rest.GetTransactionDetailsAsync(AccountId, id)); task6.Wait(); } } } Console.ReadLine(); }