-
Notifications
You must be signed in to change notification settings - Fork 0
/
Venue.cs
62 lines (55 loc) · 2.07 KB
/
Venue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace StockFighter
{
public class Venue
{
string Symbol;
HttpClient Client;
public Venue(string venueSymbol, HttpClient client)
{
this.Symbol = venueSymbol;
this.Client = client;
}
public string GetStocks()
{
var path = Paths.ExpandPath(Paths.StockRoot, new Dictionary<string, string> { { Paths.PathParts.VenueName, this.Symbol } });
var response = this.Client.GetAsync(path).Result;
string result = response.Content.ReadAsStringAsync().Result;
return result;
}
public Stock GetStock(Stock stock)
{
var path = Paths.ExpandPath(
Paths.StockQuote,
new Dictionary<string, string> {
{ Paths.PathParts.VenueName, this.Symbol },
{ Paths.PathParts.StockName, stock.Symbol }
});
var response = this.Client.GetAsync(path).Result;
string result = response.Content.ReadAsStringAsync().Result;
var returnStock = JsonConvert.DeserializeObject<Stock>(result);
return returnStock;
}
public OrderStatus OrderStock(Stock stock, Order order)
{
var path = Paths.ExpandPath(
Paths.StockOrder,
new Dictionary<string, string> {
{ Paths.PathParts.VenueName, this.Symbol },
{ Paths.PathParts.StockName, stock.Symbol }
});
var purchaseOrderJson = JsonConvert.SerializeObject(order);
var content = new StringContent(purchaseOrderJson);
var response = this.Client.PostAsync(path, content).Result;
string result = response.Content.ReadAsStringAsync().Result;
var returnOrder = JsonConvert.DeserializeObject<OrderStatus>(result);
return returnOrder;
}
}
}