Browse Source

Proto

- Action: add FLAT
Alexey Kim 6 hours ago
parent
commit
b011d649b7
5 changed files with 33 additions and 19 deletions
  1. 14 10
      probability.pb.go
  2. 3 2
      proto/probability.proto
  3. 2 2
      proto/probability_pb2.py
  4. 10 2
      strategy/alpaca/ppo/strategy.go
  5. 4 3
      util/order.go

+ 14 - 10
probability.pb.go

@@ -25,19 +25,22 @@ const (
 type Action int32
 
 const (
-	Action_SELL Action = 0
-	Action_BUY  Action = 1
+	Action_FLAT Action = 0
+	Action_SELL Action = 1
+	Action_BUY  Action = 2
 )
 
 // Enum value maps for Action.
 var (
 	Action_name = map[int32]string{
-		0: "SELL",
-		1: "BUY",
+		0: "FLAT",
+		1: "SELL",
+		2: "BUY",
 	}
 	Action_value = map[string]int32{
-		"SELL": 0,
-		"BUY":  1,
+		"FLAT": 0,
+		"SELL": 1,
+		"BUY":  2,
 	}
 )
 
@@ -161,7 +164,7 @@ func (x *Turn) GetAction() Action {
 	if x != nil {
 		return x.Action
 	}
-	return Action_SELL
+	return Action_FLAT
 }
 
 type Probability_Stamp struct {
@@ -229,10 +232,11 @@ const file_proto_probability_proto_rawDesc = "" +
 	"\x05value\x18\x02 \x01(\x02R\x05value\"^\n" +
 	"\x04Turn\x12.\n" +
 	"\x04time\x18\x01 \x01(\v2\x1a.google.protobuf.TimestampR\x04time\x12&\n" +
-	"\x06action\x18\x02 \x01(\x0e2\x0e.sentio.ActionR\x06action*\x1b\n" +
+	"\x06action\x18\x02 \x01(\x0e2\x0e.sentio.ActionR\x06action*%\n" +
 	"\x06Action\x12\b\n" +
-	"\x04SELL\x10\x00\x12\a\n" +
-	"\x03BUY\x10\x01B\n" +
+	"\x04FLAT\x10\x00\x12\b\n" +
+	"\x04SELL\x10\x01\x12\a\n" +
+	"\x03BUY\x10\x02B\n" +
 	"Z\b./sentiob\x06proto3"
 
 var (

+ 3 - 2
proto/probability.proto

@@ -14,8 +14,9 @@ message Probability {
 }
 
 enum Action {
-  SELL = 0;
-  BUY = 1;
+  FLAT = 0;
+  SELL = 1;
+  BUY = 2;
 }
 
 message Turn {

+ 2 - 2
proto/probability_pb2.py

@@ -25,7 +25,7 @@ _sym_db = _symbol_database.Default()
 from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2
 
 
-DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x17proto/probability.proto\x12\x06sentio\x1a\x1fgoogle/protobuf/timestamp.proto\"\x8f\x01\n\x0bProbability\x12\x31\n\x06stamps\x18\n \x03(\x0b\x32\x19.sentio.Probability.StampR\x06stamps\x1aM\n\x05Stamp\x12.\n\x04time\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.TimestampR\x04time\x12\x14\n\x05value\x18\x02 \x01(\x02R\x05value\"^\n\x04Turn\x12.\n\x04time\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.TimestampR\x04time\x12&\n\x06\x61\x63tion\x18\x02 \x01(\x0e\x32\x0e.sentio.ActionR\x06\x61\x63tion*\x1b\n\x06\x41\x63tion\x12\x08\n\x04SELL\x10\x00\x12\x07\n\x03\x42UY\x10\x01\x42\nZ\x08./sentiob\x06proto3')
+DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x17proto/probability.proto\x12\x06sentio\x1a\x1fgoogle/protobuf/timestamp.proto\"\x8f\x01\n\x0bProbability\x12\x31\n\x06stamps\x18\n \x03(\x0b\x32\x19.sentio.Probability.StampR\x06stamps\x1aM\n\x05Stamp\x12.\n\x04time\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.TimestampR\x04time\x12\x14\n\x05value\x18\x02 \x01(\x02R\x05value\"^\n\x04Turn\x12.\n\x04time\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.TimestampR\x04time\x12&\n\x06\x61\x63tion\x18\x02 \x01(\x0e\x32\x0e.sentio.ActionR\x06\x61\x63tion*%\n\x06\x41\x63tion\x12\x08\n\x04\x46LAT\x10\x00\x12\x08\n\x04SELL\x10\x01\x12\x07\n\x03\x42UY\x10\x02\x42\nZ\x08./sentiob\x06proto3')
 
 _globals = globals()
 _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
@@ -34,7 +34,7 @@ if not _descriptor._USE_C_DESCRIPTORS:
   _globals['DESCRIPTOR']._loaded_options = None
   _globals['DESCRIPTOR']._serialized_options = b'Z\010./sentio'
   _globals['_ACTION']._serialized_start=310
-  _globals['_ACTION']._serialized_end=337
+  _globals['_ACTION']._serialized_end=347
   _globals['_PROBABILITY']._serialized_start=69
   _globals['_PROBABILITY']._serialized_end=212
   _globals['_PROBABILITY_STAMP']._serialized_start=135

+ 10 - 2
strategy/alpaca/ppo/strategy.go

@@ -1,9 +1,10 @@
 package main
 
 import (
+	"time"
+
 	"git.beejay.kim/Gshopper/sentio"
 	"git.beejay.kim/Gshopper/sentio/util"
-	"time"
 )
 
 var Strategy = qqq{}
@@ -81,7 +82,9 @@ func (strategy qqq) Handle(turn *sentio.Turn, market sentio.Market, rs sentio.Ri
 		side := util.SideOf(orders[i].GetIntent())
 
 		if sentio.LONG == side && sentio.Action_SELL == turn.Action ||
-			sentio.SHORT == side && sentio.Action_BUY == turn.Action {
+			sentio.LONG == side && sentio.Action_FLAT == turn.Action ||
+			sentio.SHORT == side && sentio.Action_BUY == turn.Action ||
+			sentio.SHORT == side && sentio.Action_FLAT == turn.Action {
 			shouldClose = true
 		}
 
@@ -109,6 +112,11 @@ func (strategy qqq) Handle(turn *sentio.Turn, market sentio.Market, rs sentio.Ri
 		}
 	}
 
+	// While Action_FLAT we could wait for better position
+	if sentio.Action_FLAT == turn.Action {
+		return nil
+	}
+
 	// Prevent new orders if we just closed one
 	if hasClosedOrders || len(orders) > 0 {
 		return nil

+ 4 - 3
util/order.go

@@ -3,8 +3,9 @@ package util
 import (
 	"errors"
 	"fmt"
-	"git.beejay.kim/Gshopper/sentio"
 	"math"
+
+	"git.beejay.kim/Gshopper/sentio"
 )
 
 const TradingRange = .02
@@ -60,8 +61,8 @@ func NewOrder(
 
 	bid = sentio.ToFixed(quotes[opts.Symbol].BidPrice, 2)
 	opts.Action = sentio.Action_BUY
-	opts.TakeProfit = ToPtr(sentio.ToFixed(rm.TakeProfit(opts.Symbol, bid), 2))
-	opts.StopLoss = ToPtr(sentio.ToFixed(rm.StopLoss(opts.Symbol, bid), 2))
+	opts.TakeProfit = ToPtr(rm.TakeProfit(opts.Symbol, bid))
+	opts.StopLoss = ToPtr(rm.StopLoss(opts.Symbol, bid))
 
 	// Invert OrderOptions if we will do SHORT for BASE symbol
 	if sentio.SHORT == side && !canLeverage {