Skip to content

Commit

Permalink
Prune dead code (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleyvega committed Jul 19, 2021
1 parent e3efa43 commit 602007c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 41 deletions.
8 changes: 4 additions & 4 deletions bot/normal/datarequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (b *Bot) lookupInitialValues() error {
func (b *Bot) getAccountGeneral() error {
response, err := b.node.PartyAccounts(&api.PartyAccountsRequest{
// MarketId: general account is not per market
PartyId: b.walletPubKeyHex,
PartyId: b.walletPubKey,
Asset: b.settlementAssetID,
Type: proto.AccountType_ACCOUNT_TYPE_GENERAL,
})
Expand All @@ -73,7 +73,7 @@ func (b *Bot) getAccountGeneral() error {
// getAccountMargin get this bot's margin account balance.
func (b *Bot) getAccountMargin() error {
response, err := b.node.PartyAccounts(&api.PartyAccountsRequest{
PartyId: b.walletPubKeyHex,
PartyId: b.walletPubKey,
MarketId: b.market.Id,
Asset: b.settlementAssetID,
Type: proto.AccountType_ACCOUNT_TYPE_MARGIN,
Expand All @@ -95,7 +95,7 @@ func (b *Bot) getAccountMargin() error {
func (b *Bot) getAccountBond() error {
b.balanceBond = 0
response, err := b.node.PartyAccounts(&api.PartyAccountsRequest{
PartyId: b.walletPubKeyHex,
PartyId: b.walletPubKey,
MarketId: b.market.Id,
Asset: b.settlementAssetID,
Type: proto.AccountType_ACCOUNT_TYPE_BOND,
Expand All @@ -116,7 +116,7 @@ func (b *Bot) getAccountBond() error {
// getPositions get this bot's positions.
func (b *Bot) getPositions() ([]*proto.Position, error) {
response, err := b.node.PositionsByParty(&api.PositionsByPartyRequest{
PartyId: b.walletPubKeyHex,
PartyId: b.walletPubKey,
MarketId: b.market.Id,
})
if err != nil {
Expand Down
57 changes: 22 additions & 35 deletions bot/normal/normal.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package normal

import (
// "encoding/base64"
"fmt"
"math"
"math/rand"
Expand Down Expand Up @@ -73,9 +72,7 @@ type Bot struct {

walletServer *wallet.Handler
walletPassphrase string
walletPubKeyRaw []byte // "XYZ" ...
walletPubKeyHex string // "58595a" ...
walletToken string
walletPubKey string // "58595a" ...

buyShape []*proto.LiquidityOrder
sellShape []*proto.LiquidityOrder
Expand Down Expand Up @@ -227,7 +224,7 @@ func (b *Bot) Stop() {
// GetTraderDetails returns information relating to the trader
func (b *Bot) GetTraderDetails() string {
name := b.config.Name
pubKey := b.walletPubKeyHex
pubKey := b.walletPubKey
settlementVegaAssetID := b.settlementAssetID
settlementEthereumContractAddress := b.settlementAssetAddress

Expand All @@ -254,7 +251,7 @@ func (b *Bot) sendLiquidityProvision(buys, sells []*proto.LiquidityOrder) error
},
}
submitTxReq := &walletpb.SubmitTransactionRequest{
PubKey: b.walletPubKeyHex,
PubKey: b.walletPubKey,
Command: cmd,
}
err := b.signSubmitTxV2(submitTxReq, 0)
Expand Down Expand Up @@ -403,7 +400,7 @@ func (b *Bot) submitOrder(
}

submitTxReq := &walletpb.SubmitTransactionRequest{
PubKey: b.walletPubKeyHex,
PubKey: b.walletPubKey,
Command: cmd,
}
err := b.signSubmitTxV2(submitTxReq, 0)
Expand All @@ -416,8 +413,8 @@ func (b *Bot) submitOrder(
func (b *Bot) checkInitialMargin() error {
// Turn the shapes into a set of orders scaled by commitment
obligation := b.strategy.CommitmentFraction * float64(b.balanceMargin+b.balanceBond+b.balanceGeneral)
buyOrders := b.calculateOrderSizes(b.market.Id, b.walletPubKeyHex, obligation, b.buyShape, b.marketData.MidPrice)
sellOrders := b.calculateOrderSizes(b.market.Id, b.walletPubKeyHex, obligation, b.sellShape, b.marketData.MidPrice)
buyOrders := b.calculateOrderSizes(b.market.Id, b.walletPubKey, obligation, b.buyShape, b.marketData.MidPrice)
sellOrders := b.calculateOrderSizes(b.market.Id, b.walletPubKey, obligation, b.sellShape, b.marketData.MidPrice)

buyRisk := float64(0.01)
sellRisk := float64(0.01)
Expand Down Expand Up @@ -785,27 +782,24 @@ func (b *Bot) GetRealisticOrderDetails(externalPrice uint64) (price, size uint64
}

func (b *Bot) setupWallet() (err error) {
// b.walletPassphrase = "DCBAabcd1357!#&*" + b.config.Name
b.walletPassphrase = "123"

if b.walletToken == "" {
err = b.walletServer.LoginWallet(b.config.Name, b.walletPassphrase)
if err != nil {
if err == wallet.ErrWalletDoesNotExists {
err = b.walletServer.CreateWallet(b.config.Name, b.walletPassphrase)
if err != nil {
return errors.Wrap(err, "failed to create wallet")
}
b.log.Debug("Created and logged into wallet")
} else {
return errors.Wrap(err, "failed to log in to wallet")
err = b.walletServer.LoginWallet(b.config.Name, b.walletPassphrase)
if err != nil {
if err == wallet.ErrWalletDoesNotExists {
err = b.walletServer.CreateWallet(b.config.Name, b.walletPassphrase)
if err != nil {
return errors.Wrap(err, "failed to create wallet")
}
b.log.Debug("Created and logged into wallet")
} else {
b.log.Debug("Logged into wallet")
return errors.Wrap(err, "failed to log in to wallet")
}
} else {
b.log.Debug("Logged into wallet")
}

if b.walletPubKeyHex == "" || b.walletPubKeyRaw == nil {
if b.walletPubKey == "" {
var keys []wallet.PublicKey
keys, err = b.walletServer.ListPublicKeys(b.config.Name)
if err != nil {
Expand All @@ -817,20 +811,13 @@ func (b *Bot) setupWallet() (err error) {
if err != nil {
return fmt.Errorf("failed to generate keypair: %w", err)
}
b.walletPubKeyHex = key.Pub
b.log.WithFields(log.Fields{"pubKey": b.walletPubKeyHex}).Debug("Created keypair")
b.walletPubKey = key.Pub
b.log.WithFields(log.Fields{"pubKey": b.walletPubKey}).Debug("Created keypair")
} else {
b.walletPubKeyHex = keys[0].Key
b.log.WithFields(log.Fields{"pubKey": b.walletPubKeyHex}).Debug("Using existing keypair")
}

b.walletPubKeyRaw, err = hexToRaw([]byte(b.walletPubKeyHex))
if err != nil {
b.walletPubKeyHex = ""
b.walletPubKeyRaw = nil
return errors.Wrap(err, "failed to decode hex pubkey")
b.walletPubKey = keys[0].Key
b.log.WithFields(log.Fields{"pubKey": b.walletPubKey}).Debug("Using existing keypair")
}
}
b.log = b.log.WithFields(log.Fields{"pubkey": b.walletPubKeyHex})
b.log = b.log.WithFields(log.Fields{"pubkey": b.walletPubKey})
return
}
4 changes: 2 additions & 2 deletions bot/normal/streamingdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (b *Bot) subscribeToEvents() error {
Type: []eventspb.BusEventType{
eventspb.BusEventType_BUS_EVENT_TYPE_ACCOUNT,
},
PartyId: b.walletPubKeyHex,
PartyId: b.walletPubKey,
}
// First we have to create the stream
stream, err := b.node.ObserveEventBus()
Expand Down Expand Up @@ -98,7 +98,7 @@ func (b *Bot) processEventBusData(stream api.TradingDataService_ObserveEventBusC
func (b *Bot) subscribePositions() error {
req := &api.PositionsSubscribeRequest{
MarketId: b.market.Id,
PartyId: b.walletPubKeyHex,
PartyId: b.walletPubKey,
}
stream, err := b.node.PositionsSubscribe(req)
if err != nil {
Expand Down

0 comments on commit 602007c

Please sign in to comment.