forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
orders.go
63 lines (55 loc) · 1.07 KB
/
orders.go
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
63
package main
const (
LIMIT_ORDER = iota
MARKET_ORDER
)
var Orders []*Order
type Order struct {
OrderID int
Exchange string
Type int
Amount float64
Price float64
}
func NewOrder(Exchange string, amount, price float64) int {
order := &Order{}
if len(Orders) == 0 {
order.OrderID = 0
} else {
order.OrderID = len(Orders)
}
order.Exchange = Exchange
order.Amount = amount
order.Price = price
Orders = append(Orders, order)
return order.OrderID
}
func DeleteOrder(orderID int) bool {
for i := range Orders {
if Orders[i].OrderID == orderID {
Orders = append(Orders[:i], Orders[i+1:]...)
return true
}
}
return false
}
func GetOrdersByExchange(exchange string) ([]*Order, bool) {
orders := []*Order{}
for i := range Orders {
if Orders[i].Exchange == exchange {
orders = append(orders, Orders[i])
}
}
if len(orders) > 0 {
return orders, true
}
return nil, false
}
func GetOrderByOrderID(orderID int) (*Order, bool) {
for i := range Orders {
if Orders[i].OrderID == orderID {
return Orders[i], true
}
}
return nil, false
}