- Add backtest and market socket handlers for API and Worker - Add proto definitions for backtest and market services - Update client socket integration and tests - Generate protobuf code for Go and Dart - Archive completed agent tasks under agent-task/archive/2026/05/
71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package socket
|
|
|
|
import (
|
|
altv1 "git.toki-labs.com/toki/alt/packages/contracts/gen/go/alt/v1"
|
|
"git.toki-labs.com/toki/alt/packages/domain/market"
|
|
)
|
|
|
|
func instrumentToProto(inst market.Instrument) *altv1.Instrument {
|
|
return &altv1.Instrument{
|
|
Id: string(inst.ID),
|
|
Market: marketToProto(inst.Market),
|
|
Venue: venueToProto(inst.Venue),
|
|
Symbol: inst.Symbol,
|
|
Name: inst.Name,
|
|
Currency: currencyToProto(inst.Currency),
|
|
ProviderSymbols: cloneProviderSymbols(inst.ProviderSymbols),
|
|
}
|
|
}
|
|
|
|
func instrumentsToProto(insts []market.Instrument) []*altv1.Instrument {
|
|
out := make([]*altv1.Instrument, len(insts))
|
|
for i, inst := range insts {
|
|
out[i] = instrumentToProto(inst)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func barToProto(bar market.Bar) *altv1.Bar {
|
|
return &altv1.Bar{
|
|
InstrumentId: string(bar.InstrumentID),
|
|
Timeframe: timeframeToProto(bar.Timeframe),
|
|
TimestampUnixMs: timeToUnixMs(bar.Timestamp),
|
|
Open: priceToProto(bar.Open),
|
|
High: priceToProto(bar.High),
|
|
Low: priceToProto(bar.Low),
|
|
Close: priceToProto(bar.Close),
|
|
Volume: quantityToProto(bar.Volume),
|
|
}
|
|
}
|
|
|
|
func barsToProto(bars []market.Bar) []*altv1.Bar {
|
|
out := make([]*altv1.Bar, len(bars))
|
|
for i, bar := range bars {
|
|
out[i] = barToProto(bar)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func venueToProto(v market.Venue) altv1.Venue {
|
|
switch v {
|
|
case market.VenueKRX:
|
|
return altv1.Venue_VENUE_KRX
|
|
case market.VenueNASDAQ:
|
|
return altv1.Venue_VENUE_NASDAQ
|
|
case market.VenueNYSE:
|
|
return altv1.Venue_VENUE_NYSE
|
|
default:
|
|
return altv1.Venue_VENUE_UNSPECIFIED
|
|
}
|
|
}
|
|
|
|
func cloneProviderSymbols(symbols map[string]string) map[string]string {
|
|
if len(symbols) == 0 {
|
|
return nil
|
|
}
|
|
out := make(map[string]string, len(symbols))
|
|
for k, v := range symbols {
|
|
out[k] = v
|
|
}
|
|
return out
|
|
}
|